adding blinker01 example, blinks the OK led.
This commit is contained in:
37
README
37
README
@@ -0,0 +1,37 @@
|
||||
|
||||
Right, I know...Got my raspberry pi today.
|
||||
|
||||
This repo serves as a collection of low level examples. No operating
|
||||
system, embedded or low level embedded or deeply embedded, whatever
|
||||
your term is for this.
|
||||
|
||||
From what we know so far there is a gpu on chip that boots off of I
|
||||
assume an on chip rom. This goes to the sd card and does things. it
|
||||
appears that the entry point for us as programmers is the kernel.img
|
||||
file, which appears to be the memory image copied into the ARM memory
|
||||
before releasing reset on the ARM processor. The name of course because
|
||||
this is intended to be a Linux based educational computer, but it is
|
||||
just a file name, just a memory image.
|
||||
|
||||
You will want to go here
|
||||
http://elinux.org/RPi_Hardware
|
||||
And get the datasheet for the part
|
||||
http://www.raspberrypi.org/wp-content/uploads/2012/02/BCM2835-ARM-Peripherals.pdf
|
||||
(might be an old link, find the one on the wiki page)
|
||||
And the schematic for the board
|
||||
http://www.raspberrypi.org/wp-content/uploads/2012/04/Raspberry-Pi-Schematics-R1.0.pdf
|
||||
(might be an old link, find the one on the wiki page)
|
||||
|
||||
Ultimately I will make a uart based bootloader. For now start with
|
||||
blinker01
|
||||
|
||||
I dont normally use .data nor gcc libraries nor C libraries so you can
|
||||
build most if not all of my examples using a gcc cross compilerl. Basically
|
||||
it doesnt matter if you use arm-none-linux-gnueabi or arm-none-eabi.
|
||||
what was formerly codesourcery.com still has a LITE version of their
|
||||
toolchain which is easy to come by, easy to install and well maybe not
|
||||
easy to use but you can use it. Building your own toolchain from gnu
|
||||
sources (binutils and gcc) is fairly straight forward and at some point
|
||||
will create a script to do that for you.
|
||||
|
||||
|
||||
|
||||
30
blinker01/Makefile
Normal file
30
blinker01/Makefile
Normal file
@@ -0,0 +1,30 @@
|
||||
|
||||
ARMGNU ?= arm-none-eabi
|
||||
|
||||
COPS = -Wall -O2 -nostdlib -nostartfiles -ffreestanding
|
||||
|
||||
all : kernel.img
|
||||
|
||||
clean :
|
||||
rm -f *.o
|
||||
rm -f *.bin
|
||||
rm -f *.elf
|
||||
rm -f *.list
|
||||
rm -f *.img
|
||||
|
||||
novectors.o : novectors.s
|
||||
$(ARMGNU)-as novectors.s -o novectors.o
|
||||
|
||||
blinker01.o : blinker01.c
|
||||
$(ARMGNU)-gcc $(COPS) -c blinker01.c -o blinker01.o
|
||||
|
||||
kernel.img : memmap novectors.o blinker01.o
|
||||
$(ARMGNU)-ld novectors.o blinker01.o -T memmap -o blinker01.elf
|
||||
$(ARMGNU)-objdump -D blinker01.elf > blinker01.list
|
||||
$(ARMGNU)-objcopy blinker01.elf -O binary kernel.img
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
45
blinker01/README
Normal file
45
blinker01/README
Normal file
@@ -0,0 +1,45 @@
|
||||
|
||||
See the top level README for information on where to find the
|
||||
schematic and programmers reference manual for the ARM processor
|
||||
on the raspberry pi.
|
||||
|
||||
Based on some web searches the gpio is based at address 0x20200000 not
|
||||
0x7E200000 as shown in the documentation. I have to go figure that out.
|
||||
|
||||
Apparently what they have done is have the thing boot using the gpu
|
||||
in the part, dont bother, leave it be, they are not going to let us
|
||||
program it, not for a while at least. There is I assume a gpu bootloader
|
||||
programmed in the chip, an OTP ROM based on something I read. This
|
||||
searches for the sd card, and I assume loads another gpu bootloader
|
||||
from that, at some point, the arm memory is loaded from kernel.img
|
||||
on the sd card, then the ARM is released from reset.
|
||||
|
||||
This simple example, sets up a small stack, not much to this program, and
|
||||
I have not read up on how much memory is actually in this space. It
|
||||
then enables gpio16 as an output. Then goes into a loop that sets
|
||||
the gpio, waits, resets it, waits, repeat. gpio16 is shown on the
|
||||
schematic to connect to the OK led. One of the bank of leds on the
|
||||
corner near the audio out and host usb ports. The blink rate
|
||||
for me is a few blinks a second perhaps. Future examples will get
|
||||
use a timer if there is one and narrow in on the clock setup, etc.
|
||||
|
||||
Copy the kernel.img file to the sd card, overwriting whatever you had
|
||||
there. You may wish to backup the one you had there before you started
|
||||
playing at this level.
|
||||
|
||||
The beauty of this boot design is that it is not (easily) brickable,
|
||||
so far as we know. With ignorance being bliss I will say it is not
|
||||
brickable. Second we have no flash on the card we always run out of
|
||||
ram as far as we are concerned. Making the board cheaper among other
|
||||
things. The negative side to this is the development process is very
|
||||
painful. It goes back to the GBA or NDS days, actually it was more
|
||||
painful then. Here you unplug the rpi, pull the sd card out, put
|
||||
the sd card in an sd card reader, plug the sd card reader into the
|
||||
computer, wait or mount, copy kernel.img to the sd card, wait or sync,
|
||||
unmount the sd card, remove the sd card reader, remove the sd card
|
||||
place in rpi, plug in rpi. And repeat with each new build. I hope
|
||||
to get the uart figured out and a bootloader so that I/we only have
|
||||
to do that once, and from there on power off, power on, load the
|
||||
program over serial. Not to dissimilar to the arduino experience.
|
||||
|
||||
|
||||
33
blinker01/blinker01.c
Normal file
33
blinker01/blinker01.c
Normal file
@@ -0,0 +1,33 @@
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
extern void PUT32 ( unsigned int, unsigned int );
|
||||
extern unsigned int GET32 ( unsigned int );
|
||||
extern void dummy ( unsigned int );
|
||||
|
||||
#define GPFSEL1 0x20200004
|
||||
#define GPSET0 0x2020001C
|
||||
#define GPCLR0 0x20200028
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
int notmain ( void )
|
||||
{
|
||||
unsigned int ra;
|
||||
|
||||
ra=GET32(GPFSEL1);
|
||||
ra&=~(7<<18);
|
||||
ra|=1<<18;
|
||||
PUT32(GPFSEL1,ra);
|
||||
|
||||
while(1)
|
||||
{
|
||||
PUT32(GPSET0,1<<16);
|
||||
for(ra=0;ra<0x100000;ra++) dummy(ra);
|
||||
PUT32(GPCLR0,1<<16);
|
||||
for(ra=0;ra<0x100000;ra++) dummy(ra);
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
//-------------------------------------------------------------------------
|
||||
//-------------------------------------------------------------------------
|
||||
12
blinker01/memmap
Normal file
12
blinker01/memmap
Normal file
@@ -0,0 +1,12 @@
|
||||
|
||||
MEMORY
|
||||
{
|
||||
ram : ORIGIN = 0x00000000, LENGTH = 0x1000
|
||||
}
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
.text : { *(.text*) } > ram
|
||||
.bss : { *(.bss*) } > ram
|
||||
}
|
||||
|
||||
23
blinker01/novectors.s
Normal file
23
blinker01/novectors.s
Normal file
@@ -0,0 +1,23 @@
|
||||
|
||||
.globl _start
|
||||
_start:
|
||||
b reset
|
||||
|
||||
reset:
|
||||
mov sp,#0x1000
|
||||
bl notmain
|
||||
hang: b hang
|
||||
|
||||
.globl PUT32
|
||||
PUT32:
|
||||
str r1,[r0]
|
||||
bx lr
|
||||
|
||||
.globl GET32
|
||||
GET32:
|
||||
ldr r0,[r0]
|
||||
bx lr
|
||||
|
||||
.globl dummy
|
||||
dummy:
|
||||
bx lr
|
||||
Reference in New Issue
Block a user