Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Just got a B+ board, led is on a different pin, starting to port exam…
…ples
- Loading branch information
Showing
12 changed files
with
339 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
This directory is specific to the Raspberry Pi B+ board, which has | ||
changed a little from the A and B boards, first thing is the led has | ||
changed from GPIO16 to GPIO47. | ||
|
||
As of this writing the schematics are not available so will have to | ||
figure things out along the way... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
|
||
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. | ||
|
||
This simple example sets up a small stack, not much to this program | ||
so the stack doesnt need much room. It then enables gpio47 as | ||
an output. Then goes into a loop that sets the gpio, waits, resets it, | ||
waits, repeat. gpio47 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. | ||
|
||
I normally set my stack pointer to be at the top of some bank of ram | ||
if only one ram bank in the system then the top of that ram bank. See | ||
the top level README, they force us to start somewhere other than zero | ||
so for such simple programs like these I am setting the program to start | ||
at 0x8000 and the stack to start at 0x7FFC. Note that on an ARM the | ||
stack pointer (r13) points at the first address after the top of the | ||
stack so setting r13 to 0x8000 means the stack starts at 0x7FFC and | ||
works down away from our program. | ||
|
||
vectors.s is the entry point for this program, even an application on | ||
an operating system like linux has some assembly up front before | ||
calling the main function. For this processor the minimum is to to | ||
set up the stack pointer and call the main function. Because some | ||
compilers add extra stuff if they see a main() funtion I use some | ||
function name other than main() typically for embedded systems like this. | ||
If you dont have any pre-initialized variables, and dont assume that | ||
un-initialized variables are zero, then you dont have or need a .data | ||
and wont need to zero .bss. Typically the asm that preceeds the call | ||
to the main function would prepare the .data segment if needed and zero | ||
the .bss segment. Also the linker script is usually more complicated | ||
to initialize global variables with the addresses and sizes of the | ||
segments. I dont do these things so my startup code only needs to | ||
set the stack pointer and branch to the main function. | ||
|
||
The example includes a Makefile that is capable of building using | ||
gnu/gcc tools or a hybrid clang(llvm)/gnu binutils to experience an | ||
alternate C compiler. | ||
|
||
The reason for the dummy function is that when a compiler optimizes | ||
code like this: | ||
|
||
for(ra=0;ra<0x1000;ra++) continue; | ||
|
||
It replaces it with this equivalent: | ||
|
||
ra = 0x1000; | ||
|
||
Which we dont want, we want the program to actually burn some time so | ||
we can see the led with our slow eyes. | ||
|
||
The compiler doesnt know what dummy does because the asm for it is not | ||
something the C compiler can inspect. So | ||
|
||
for(ra=0;ra<0x1000;ra++) dummy(ra); | ||
|
||
To properly implement your program the C compiler must in order call | ||
dummy(0), dummy(1), dummy(2), etc. For smaller loops it may choose | ||
to unroll the loop. that is fine. | ||
|
||
Another solution is to declare ra volatile and that will cause first | ||
the loop to not get optimized, and ra to be read from and saved to memory | ||
each time through the loop. I like one approach you may like another. | ||
|
||
The program is simple refer to the broadcom arm document for information | ||
on these registers. Remember that in the broadcom document the addresses | ||
will be 0x7Exxxxxx not 0x20xxxxxx. | ||
|
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
|
||
//------------------------------------------------------------------------- | ||
//------------------------------------------------------------------------- | ||
|
||
extern void PUT32 ( unsigned int, unsigned int ); | ||
extern unsigned int GET32 ( unsigned int ); | ||
extern void dummy ( unsigned int ); | ||
|
||
#define GPFSEL1 0x20200004 | ||
#define GPFSEL2 0x20200008 | ||
#define GPFSEL3 0x2020000C | ||
#define GPFSEL4 0x20200010 | ||
#define GPSET0 0x2020001C | ||
#define GPSET1 0x20200020 | ||
#define GPCLR0 0x20200028 | ||
#define GPCLR1 0x2020002C | ||
|
||
//------------------------------------------------------------------------- | ||
int notmain ( void ) | ||
{ | ||
unsigned int ra; | ||
|
||
ra=GET32(GPFSEL4); | ||
ra&=~(7<<21); | ||
ra|=1<<21; | ||
PUT32(GPFSEL4,ra); | ||
|
||
while(1) | ||
{ | ||
PUT32(GPSET1,1<<(47-32)); | ||
for(ra=0;ra<0x100000;ra++) dummy(ra); | ||
PUT32(GPCLR1,1<<(47-32)); | ||
for(ra=0;ra<0x100000;ra++) dummy(ra); | ||
} | ||
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. | ||
// | ||
//------------------------------------------------------------------------- |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
:1080000002D9A0E3050000EBFEFFFFEA001080E5C7 | ||
:108010001EFF2FE1000090E51EFF2FE11EFF2FE164 | ||
:1080200010402DE95C009FE5F9FFFFEB0E16C0E361 | ||
:10803000021681E34C009FE5F3FFFFEB48009FE54C | ||
:108040000219A0E3F0FFFFEB0040A0E30400A0E171 | ||
:10805000014084E2F0FFFFEB010654E3FAFFFF1A50 | ||
:1080600028009FE50219A0E3E7FFFFEB0040A0E333 | ||
:108070000400A0E1014084E2E7FFFFEB010654E3C6 | ||
:10808000FAFFFF1AECFFFFEA10002020200020205A | ||
:048090002C00202080 | ||
:040000030000800079 | ||
:00000001FF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
|
||
blinker01.elf: file format elf32-littlearm | ||
|
||
|
||
Disassembly of section .text: | ||
|
||
00008000 <_start>: | ||
8000: e3a0d902 mov sp, #32768 ; 0x8000 | ||
8004: eb000005 bl 8020 <notmain> | ||
|
||
00008008 <hang>: | ||
8008: eafffffe b 8008 <hang> | ||
|
||
0000800c <PUT32>: | ||
800c: e5801000 str r1, [r0] | ||
8010: e12fff1e bx lr | ||
|
||
00008014 <GET32>: | ||
8014: e5900000 ldr r0, [r0] | ||
8018: e12fff1e bx lr | ||
|
||
0000801c <dummy>: | ||
801c: e12fff1e bx lr | ||
|
||
00008020 <notmain>: | ||
8020: e92d4010 push {r4, lr} | ||
8024: e59f005c ldr r0, [pc, #92] ; 8088 <notmain+0x68> | ||
8028: ebfffff9 bl 8014 <GET32> | ||
802c: e3c0160e bic r1, r0, #14680064 ; 0xe00000 | ||
8030: e3811602 orr r1, r1, #2097152 ; 0x200000 | ||
8034: e59f004c ldr r0, [pc, #76] ; 8088 <notmain+0x68> | ||
8038: ebfffff3 bl 800c <PUT32> | ||
803c: e59f0048 ldr r0, [pc, #72] ; 808c <notmain+0x6c> | ||
8040: e3a01902 mov r1, #32768 ; 0x8000 | ||
8044: ebfffff0 bl 800c <PUT32> | ||
8048: e3a04000 mov r4, #0 | ||
804c: e1a00004 mov r0, r4 | ||
8050: e2844001 add r4, r4, #1 | ||
8054: ebfffff0 bl 801c <dummy> | ||
8058: e3540601 cmp r4, #1048576 ; 0x100000 | ||
805c: 1afffffa bne 804c <notmain+0x2c> | ||
8060: e59f0028 ldr r0, [pc, #40] ; 8090 <notmain+0x70> | ||
8064: e3a01902 mov r1, #32768 ; 0x8000 | ||
8068: ebffffe7 bl 800c <PUT32> | ||
806c: e3a04000 mov r4, #0 | ||
8070: e1a00004 mov r0, r4 | ||
8074: e2844001 add r4, r4, #1 | ||
8078: ebffffe7 bl 801c <dummy> | ||
807c: e3540601 cmp r4, #1048576 ; 0x100000 | ||
8080: 1afffffa bne 8070 <notmain+0x50> | ||
8084: eaffffec b 803c <notmain+0x1c> | ||
8088: 20200010 eorcs r0, r0, r0, lsl r0 | ||
808c: 20200020 eorcs r0, r0, r0, lsr #32 | ||
8090: 2020002c eorcs r0, r0, ip, lsr #32 | ||
|
||
Disassembly of section .ARM.attributes: | ||
|
||
00000000 <.ARM.attributes>: | ||
0: 00002a41 andeq r2, r0, r1, asr #20 | ||
4: 61656100 cmnvs r5, r0, lsl #2 | ||
8: 01006962 tsteq r0, r2, ror #18 | ||
c: 00000020 andeq r0, r0, r0, lsr #32 | ||
10: 4d524105 ldfmie f4, [r2, #-20] ; 0xffffffec | ||
14: 54347620 ldrtpl r7, [r4], #-1568 ; 0x620 | ||
18: 08020600 stmdaeq r2, {r9, sl} | ||
1c: 12010901 andne r0, r1, #16384 ; 0x4000 | ||
20: 15011404 strne r1, [r1, #-1028] ; 0x404 | ||
24: 18031701 stmdane r3, {r0, r8, r9, sl, ip} | ||
28: Address 0x0000000000000028 is out of bounds. | ||
|
||
|
||
Disassembly of section .comment: | ||
|
||
00000000 <.comment>: | ||
0: 3a434347 bcc 10d0d24 <notmain+0x10c8d04> | ||
4: 4e472820 cdpmi 8, 4, cr2, cr7, cr0, {1} | ||
8: 34202955 strtcc r2, [r0], #-2389 ; 0x955 | ||
c: 332e382e teqcc lr, #3014656 ; 0x2e0000 | ||
... |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
MEMORY | ||
{ | ||
ram : ORIGIN = 0x8000, LENGTH = 0x10000 | ||
} | ||
|
||
SECTIONS | ||
{ | ||
.text : { *(.text*) } > ram | ||
.bss : { *(.bss*) } > ram | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
;@ | ||
;@------------------------------------------------------------------------- |