updating blinker01 for the raspberry pi 2, need to do B+ still

This commit is contained in:
dwelch67
2015-12-23 01:47:54 -05:00
parent d77a2c7cf5
commit aa32e651ed
12 changed files with 444 additions and 0 deletions

View File

@@ -4,6 +4,11 @@ schematic and programmers reference manual for the ARM processor
on the raspberry pi. Also find information on how to load and run
these programs.
The code in this directory is for the old/original-ish raspberry pi
which you can still get raspberry pi 1 if you will. The pi2 directory
is for the raspberry pi 2 the one with the quad core arm. You have to
match the right program to the right raspberry pi.
This simple example sets up a small stack, not much to this program
so the stack doesnt need much room. It then enables gpio16 as
an output. Then goes into a loop that sets the gpio, waits, resets it,

70
blinker01/pi2/Makefile Normal file
View File

@@ -0,0 +1,70 @@
ARMGNU ?= arm-none-eabi
AOPS = --warn --fatal-warnings
COPS = -Wall -Werror -O2 -nostdlib -nostartfiles -ffreestanding
gcc : blinker01.hex blinker01.bin
all : gcc clang
clean :
rm -f *.o
rm -f *.bin
rm -f *.hex
rm -f *.elf
rm -f *.list
rm -f *.img
rm -f *.bc
rm -f *.clang.opt.s
vectors.o : vectors.s
$(ARMGNU)-as vectors.s -o vectors.o
blinker01.o : blinker01.c
$(ARMGNU)-gcc $(COPS) -c blinker01.c -o blinker01.o
blinker01.elf : memmap vectors.o blinker01.o
$(ARMGNU)-ld vectors.o blinker01.o -T memmap -o blinker01.elf
$(ARMGNU)-objdump -D blinker01.elf > blinker01.list
blinker01.bin : blinker01.elf
$(ARMGNU)-objcopy blinker01.elf -O binary blinker01.bin
blinker01.hex : blinker01.elf
$(ARMGNU)-objcopy blinker01.elf -O ihex blinker01.hex
LOPS = -Wall -m32 -emit-llvm
LLCOPS = -march=arm -mcpu=arm1176jzf-s
LLCOPS0 = -march=arm
LLCOPS1 = -march=arm -mcpu=arm1176jzf-s
COPS = -Wall -O2 -nostdlib -nostartfiles -ffreestanding
OOPS = -std-compile-opts
clang : blinker01.clang.hex blinker01.clang.bin
blinker01.clang.bc : blinker01.c
clang $(LOPS) -c blinker01.c -o blinker01.clang.bc
blinker01.clang.opt.elf : memmap vectors.o blinker01.clang.bc
opt $(OOPS) blinker01.clang.bc -o blinker01.clang.opt.bc
llc $(LLCOPS) blinker01.clang.opt.bc -o blinker01.clang.opt.s
$(ARMGNU)-as blinker01.clang.opt.s -o blinker01.clang.opt.o
$(ARMGNU)-ld -o blinker01.clang.opt.elf -T memmap vectors.o blinker01.clang.opt.o
$(ARMGNU)-objdump -D blinker01.clang.opt.elf > blinker01.clang.opt.list
blinker01.clang.hex : blinker01.clang.opt.elf
$(ARMGNU)-objcopy blinker01.clang.opt.elf blinker01.clang.hex -O ihex
blinker01.clang.bin : blinker01.clang.opt.elf
$(ARMGNU)-objcopy blinker01.clang.opt.elf blinker01.clang.bin -O binary

16
blinker01/pi2/README Normal file
View File

@@ -0,0 +1,16 @@
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. Also find information on how to load and run
these programs.
Same as blinker01 in the directory above, except the raspberry pi 2
has two leds one on gpio47 the other gpio35
Also note to make more room for ram the raspberry pi 2 uses a base
address for peripherals of 0x3F000000 where the raspberry pi used
0x20000000.
also note that for the raspberry pi 2 the arm file copied from the
sd card to ram is kernel7.img the older raspberry pis still use
kernel.img.

View File

@@ -0,0 +1,70 @@
ARMGNU ?= arm-none-eabi
AOPS = --warn --fatal-warnings
COPS = -Wall -Werror -O2 -nostdlib -nostartfiles -ffreestanding
gcc : blinker01.hex blinker01.bin blinker.list
all : gcc clang
clean :
rm -f *.o
rm -f *.bin
rm -f *.hex
rm -f *.elf
rm -f *.list
rm -f *.img
rm -f *.bc
rm -f *.clang.opt.s
vectors.o : vectors.s
$(ARMGNU)-as vectors.s -o vectors.o
blinker01.o : blinker01.c
$(ARMGNU)-gcc $(COPS) -c blinker01.c -o blinker01.o
blinker01.elf : memmap vectors.o blinker01.o
$(ARMGNU)-ld vectors.o blinker01.o -T memmap -o blinker01.elf
$(ARMGNU)-objdump -D blinker01.elf > blinker01.list
blinker01.bin : blinker01.elf
$(ARMGNU)-objcopy blinker01.elf -O binary blinker01.bin
blinker01.hex : blinker01.elf
$(ARMGNU)-objcopy blinker01.elf -O ihex blinker01.hex
blinker.list : blinker.s
arm-none-eabi-as blinker.s -o blinker.o
arm-none-eabi-objdump -D blinker.o > blinker.list
LOPS = -Wall -m32 -emit-llvm
LLCOPS = -march=arm -mcpu=arm1176jzf-s
LLCOPS0 = -march=arm
LLCOPS1 = -march=arm -mcpu=arm1176jzf-s
COPS = -Wall -O2 -nostdlib -nostartfiles -ffreestanding
OOPS = -std-compile-opts
clang : blinker01.clang.hex blinker01.clang.bin
blinker01.clang.bc : blinker01.c
clang $(LOPS) -c blinker01.c -o blinker01.clang.bc
blinker01.clang.opt.elf : memmap vectors.o blinker01.clang.bc
opt $(OOPS) blinker01.clang.bc -o blinker01.clang.opt.bc
llc $(LLCOPS) blinker01.clang.opt.bc -o blinker01.clang.opt.s
$(ARMGNU)-as blinker01.clang.opt.s -o blinker01.clang.opt.o
$(ARMGNU)-ld -o blinker01.clang.opt.elf -T memmap vectors.o blinker01.clang.opt.o
$(ARMGNU)-objdump -D blinker01.clang.opt.elf > blinker01.clang.opt.list
blinker01.clang.hex : blinker01.clang.opt.elf
$(ARMGNU)-objcopy blinker01.clang.opt.elf blinker01.clang.hex -O ihex
blinker01.clang.bin : blinker01.clang.opt.elf
$(ARMGNU)-objcopy blinker01.clang.opt.elf blinker01.clang.bin -O binary

17
blinker01/pi2/asm/README Normal file
View File

@@ -0,0 +1,17 @@
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. Also find information on how to load and run
these programs.
specifically for a forum question, self modifying code if you will,
writes instructions to ram then branches to that code. in this case
essentially the same blinker01 example just some asm that is loaded
by the running program then branched to.
blinker.s is the ASM program that does the blinking and blinker01.c
just writes those instrucions to ram and executes them. blinker.list
once assembled and dumped shows the list of instructions. naturally
you have to start at an address that is aligned on a 32 bit boundary,
any address that has ram behind it not being used by the program
loading nor the gpu, should work.

View File

@@ -0,0 +1,49 @@
;@ ------------------------------------------------------------------
;@ ------------------------------------------------------------------
.globl _start
_start:
mov r0,#0x3F000000
orr r0,r0,#0x00200000
ldr r1,[r0,#0x10]
bic r1,r1,#0x00E00000
orr r1,r1,#0x00200000
str r1,[r0,#0x10]
ldr r1,[r0,#0x0C]
bic r1,r1,#0x00038000
orr r1,r1,#0x00008000
str r1,[r0,#0x0C]
mov r2,#0x00008000
mov r3,#0x00000008
mainloop:
str r2,[r0,#0x20]
str r3,[r0,#0x2C]
mov r4,#0x100000
one:
subs r4,r4,#1
bne one
str r2,[r0,#0x2C]
str r3,[r0,#0x20]
mov r4,#0x100000
two:
subs r4,r4,#1
bne two
b mainloop
;@-------------------------------------------------------------------------
;@-------------------------------------------------------------------------
;@-------------------------------------------------------------------------
;@
;@ Copyright (c) 2012 David Welch dwelch@dwelch.com
;@
;@ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
;@
;@ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
;@
;@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
;@
;@-------------------------------------------------------------------------

View File

@@ -0,0 +1,58 @@
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
extern void PUT32 ( unsigned int, unsigned int );
extern unsigned int GET32 ( unsigned int );
extern void dummy ( unsigned int );
extern void HOP ( unsigned int );
//-------------------------------------------------------------------------
int notmain ( void )
{
unsigned int ra;
ra=0x10000;
PUT32(ra,0xe3a0043f); ra+=4;
PUT32(ra,0xe3800602); ra+=4;
PUT32(ra,0xe5901010); ra+=4;
PUT32(ra,0xe3c1160e); ra+=4;
PUT32(ra,0xe3811602); ra+=4;
PUT32(ra,0xe5801010); ra+=4;
PUT32(ra,0xe590100c); ra+=4;
PUT32(ra,0xe3c1190e); ra+=4;
PUT32(ra,0xe3811902); ra+=4;
PUT32(ra,0xe580100c); ra+=4;
PUT32(ra,0xe3a02902); ra+=4;
PUT32(ra,0xe3a03008); ra+=4;
PUT32(ra,0xe5802020); ra+=4;
PUT32(ra,0xe580302c); ra+=4;
PUT32(ra,0xe3a04601); ra+=4;
PUT32(ra,0xe2544001); ra+=4;
PUT32(ra,0x1afffffd); ra+=4;
PUT32(ra,0xe580202c); ra+=4;
PUT32(ra,0xe5803020); ra+=4;
PUT32(ra,0xe3a04601); ra+=4;
PUT32(ra,0xe2544001); ra+=4;
PUT32(ra,0x1afffffd); ra+=4;
PUT32(ra,0xeafffff4); ra+=4;
HOP(0x10000);
return(0);
}
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
//
// Copyright (c) 2012 David Welch dwelch@dwelch.com
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-------------------------------------------------------------------------

11
blinker01/pi2/asm/memmap Normal file
View File

@@ -0,0 +1,11 @@
MEMORY
{
ram : ORIGIN = 0x8000, LENGTH = 0x10000
}
SECTIONS
{
.text : { *(.text*) } > ram
.bss : { *(.bss*) } > ram
}

View File

@@ -0,0 +1,43 @@
;@ ------------------------------------------------------------------
;@ ------------------------------------------------------------------
.globl _start
_start:
mov sp,#0x8000
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
.globl HOP
HOP:
bx r0
;@-------------------------------------------------------------------------
;@-------------------------------------------------------------------------
;@-------------------------------------------------------------------------
;@
;@ Copyright (c) 2012 David Welch dwelch@dwelch.com
;@
;@ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
;@
;@ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
;@
;@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
;@
;@-------------------------------------------------------------------------

55
blinker01/pi2/blinker01.c Normal file
View File

@@ -0,0 +1,55 @@
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
extern void PUT32 ( unsigned int, unsigned int );
extern unsigned int GET32 ( unsigned int );
extern void dummy ( unsigned int );
#define GPFSEL3 0x3F20000C
#define GPFSEL4 0x3F200010
#define GPSET1 0x3F200020
#define GPCLR1 0x3F20002C
//-------------------------------------------------------------------------
int notmain ( void )
{
unsigned int ra;
ra=GET32(GPFSEL4);
ra&=~(7<<21);
ra|=1<<21;
PUT32(GPFSEL4,ra);
ra=GET32(GPFSEL3);
ra&=~(7<<15);
ra|=1<<15;
PUT32(GPFSEL3,ra);
while(1)
{
PUT32(GPSET1,1<<(47-32));
PUT32(GPCLR1,1<<(35-32));
for(ra=0;ra<0x100000;ra++) dummy(ra);
PUT32(GPCLR1,1<<(47-32));
PUT32(GPSET1,1<<(35-32));
for(ra=0;ra<0x100000;ra++) dummy(ra);
}
return(0);
}
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
//
// Copyright (c) 2015 David Welch dwelch@dwelch.com
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-------------------------------------------------------------------------

11
blinker01/pi2/memmap Normal file
View File

@@ -0,0 +1,11 @@
MEMORY
{
ram : ORIGIN = 0x8000, LENGTH = 0x10000
}
SECTIONS
{
.text : { *(.text*) } > ram
.bss : { *(.bss*) } > ram
}

39
blinker01/pi2/vectors.s Normal file
View File

@@ -0,0 +1,39 @@
;@ ------------------------------------------------------------------
;@ ------------------------------------------------------------------
.globl _start
_start:
mov sp,#0x8000
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
;@-------------------------------------------------------------------------
;@-------------------------------------------------------------------------
;@-------------------------------------------------------------------------
;@
;@ Copyright (c) 2012 David Welch dwelch@dwelch.com
;@
;@ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
;@
;@ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
;@
;@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
;@
;@-------------------------------------------------------------------------