starting to separate each board time into its own directory tree.
This commit is contained in:
71
pizero/blinker01/Makefile
Normal file
71
pizero/blinker01/Makefile
Normal file
@@ -0,0 +1,71 @@
|
||||
|
||||
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
|
||||
OOPS = -std-link-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
|
||||
|
||||
|
||||
129
pizero/blinker01/README
Normal file
129
pizero/blinker01/README
Normal file
@@ -0,0 +1,129 @@
|
||||
|
||||
See the top level README for information on where to find documentation
|
||||
for the raspberry pi and the ARM processor inside. Also find information
|
||||
on how to load and run these programs.
|
||||
|
||||
This example is for the pi zero, see other directories for other flavors
|
||||
of raspberry pi.
|
||||
|
||||
This is an LED blinker example for the pi zero.
|
||||
|
||||
The pi zero has one led that is tied to gpio 47.
|
||||
|
||||
Being the first example I will spend a little more time describing it.
|
||||
I have some other ramblings on baremetal and the gnu tools so I will
|
||||
try not to duplicate that.
|
||||
|
||||
The primary use case for the raspberry pi is to run some version of
|
||||
linux. The three main files to do that are bootloader.bin, start.elf
|
||||
and kernel.img. The first two being GPU programs the last being ARM.
|
||||
If you have no other files (dont have a config.txt) they (starg.elf
|
||||
GPU code) copy the kernel.img file to 0x8000 in RAM, place some
|
||||
code at address 0x0000 that is intended to prepare the ARM for booting
|
||||
linux, then branch to 0x8000. We simply replace the kernel.img file
|
||||
with our own program. I prefer to not mess with config.txt stuff
|
||||
because it is not the primary use case, most pis out there do not use
|
||||
this, so without is significantly better tested. Also over time the
|
||||
config.txt things you can play with come and go and change name, some
|
||||
of the popular ones are undocumented and so on. So I really dont want
|
||||
to rely on that. Simply replace the kernel.img and otherwise be stock.
|
||||
|
||||
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.
|
||||
I have adopted the habit of using notmain() both to not be named main()
|
||||
and to emphasize this is bare metal and not your average application.
|
||||
|
||||
See my ramblings on .data and .bss, I dont need/use them so the
|
||||
bootstrap (little bit of assembly before calling the first C function)
|
||||
does not have to prepare those segments. I only need to setup the
|
||||
stack and call the first C function in the project.
|
||||
|
||||
I normally would set the stack pointer at the top of ram...Well that is
|
||||
a lie, normaly one would do such a thing, but with code like this that
|
||||
mostly ports across a number of boards, it becomes a pain keeping track
|
||||
of who has how much ram. Instead for simple examples I set the stack
|
||||
somewhere where it doesnt collide with the code, but also I dont have to
|
||||
change every board. Because I am using the 0x8000 entry point I can
|
||||
set the stack at 0x8000 and it will grow down toward 0x0000, and that
|
||||
is more than enough for these projects. The way the ARM works it
|
||||
subtracts then writes stuff so the first thing on the stack will really
|
||||
be at 0x7FFC, you dont have to set it to 0x7FFC to avoid the code at
|
||||
0x8000.
|
||||
|
||||
The gpio pin is setup as an output to drive the LED. The blink rate
|
||||
appears to be around a couple-three times a second, but may vary based
|
||||
on your compiler and settings. This program does not attempt to use
|
||||
any other peripherals (a timer) it relies on simply wasting time in a
|
||||
loop then changing the state of the LED. If you were to use this line
|
||||
of code:
|
||||
|
||||
for(ra=0;ra<0x1000;ra++) continue;
|
||||
|
||||
The optimizer will replace that with this one assignment:
|
||||
|
||||
ra = 0x1000;
|
||||
|
||||
And actually since that value isnt used again, it is dead code the
|
||||
optimizer will likely remove that as well.
|
||||
|
||||
One way to get around this is to make the loop variable volatile, this
|
||||
tells the compiler every time you use it grab it from and save it back
|
||||
to its home in ram. I prefer a different approach. I have a simple
|
||||
dummy function in assembly language, it simply returns.
|
||||
|
||||
.globl dummy
|
||||
dummy:
|
||||
bx lr
|
||||
|
||||
The assembly is outside the visibility of the optimizer as would
|
||||
anything basically not in the same file (llvm is a little different it
|
||||
might "see" those other objects and optimize across them, gnu wont).
|
||||
|
||||
So by having that external function and by passing the loop variable
|
||||
to it.
|
||||
|
||||
for(ra=0;ra<0x1000;ra++) dummy(ra);
|
||||
|
||||
We force the compiler to actually implement this code and run that loop
|
||||
that many times. Dont need to declare the variable volatile. If
|
||||
uncomfortable with assembly langauge you could create a dummy function
|
||||
in a separately compiled file
|
||||
|
||||
void dummy ( void )
|
||||
{
|
||||
}
|
||||
|
||||
Which produces the same code.
|
||||
|
||||
00000000 <dummy>:
|
||||
0: e12fff1e bx lr
|
||||
|
||||
Some toolchains have the ability to see across objects when they
|
||||
optimize so you still have to be careful. I prefer the assembly approach
|
||||
to defeating the optimizer.
|
||||
|
||||
So this program sets up the gpio to drive the LED. Uses the loop to kill
|
||||
some time, changes state of the LED, repeat forever. The blink rate
|
||||
will be the same for the same program. But compiler differences and
|
||||
options can cause one build to be different from another in the blink
|
||||
rate. It is not really deterministic, thus the desire to use timers in
|
||||
the examples that follow. If you change the number the loop counts to
|
||||
and re-build with the same tools, you should see a change in the
|
||||
blink rate.
|
||||
|
||||
Note the Broadcom documentation uses addresses 0x7Exxxxxx for the
|
||||
peripherals. That is we assume the GPU's address space to access those
|
||||
things. The ARM window into that is to date either at 0x20xxxxxx or
|
||||
0x3Fxxxxxx depending on the specific broadcom chip for that board type
|
||||
the pi zero uses 0x20xxxxxx so when you se 0x7Exxxxxx replace that
|
||||
0x7E with 0x20.
|
||||
|
||||
I normally dont leave the compiled output in the repository, but you
|
||||
may need it to compare with your results to see why for example mine
|
||||
works and yours doesnt, so I will leave these here for this example.
|
||||
|
||||
|
||||
BIN
pizero/blinker01/blinker01.bin
Executable file
BIN
pizero/blinker01/blinker01.bin
Executable file
Binary file not shown.
55
pizero/blinker01/blinker01.c
Normal file
55
pizero/blinker01/blinker01.c
Normal 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 0x2020000C
|
||||
#define GPFSEL4 0x20200010
|
||||
#define GPSET1 0x20200020
|
||||
#define GPCLR1 0x2020002C
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
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.
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
BIN
pizero/blinker01/blinker01.elf
Executable file
BIN
pizero/blinker01/blinker01.elf
Executable file
Binary file not shown.
12
pizero/blinker01/blinker01.hex
Normal file
12
pizero/blinker01/blinker01.hex
Normal file
@@ -0,0 +1,12 @@
|
||||
:1080000002D9A0E3050000EBFEFFFFEA001080E5C7
|
||||
:108010001EFF2FE1000090E51EFF2FE11EFF2FE164
|
||||
:1080200010402DE95C009FE5F9FFFFEB0E16C0E361
|
||||
:10803000021681E34C009FE5F3FFFFEB0219A0E37A
|
||||
:1080400044009FE5F0FFFFEB0040A0E30400A0E147
|
||||
:10805000014084E2F0FFFFEB010654E3FAFFFF1A50
|
||||
:108060000219A0E324009FE5E7FFFFEB0040A0E337
|
||||
:108070000400A0E1014084E2E7FFFFEB010654E3C6
|
||||
:10808000FAFFFF1AECFFFFEA10002020200020205A
|
||||
:048090002C00202080
|
||||
:040000030000800079
|
||||
:00000001FF
|
||||
79
pizero/blinker01/blinker01.list
Normal file
79
pizero/blinker01/blinker01.list
Normal file
@@ -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: e3a01902 mov r1, #32768 ; 0x8000
|
||||
8040: e59f0044 ldr r0, [pc, #68] ; 808c <notmain+0x6c>
|
||||
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: e3a01902 mov r1, #32768 ; 0x8000
|
||||
8064: e59f0024 ldr r0, [pc, #36] ; 8090 <notmain+0x70>
|
||||
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 ; 0xfffff9e0
|
||||
18: 08020600 stmdaeq r2, {r9, sl}
|
||||
1c: 12010901 andne r0, r1, #16384 ; 0x4000
|
||||
20: 15011404 strne r1, [r1, #-1028] ; 0xfffffbfc
|
||||
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: 35202955 strcc r2, [r0, #-2389]! ; 0xfffff6ab
|
||||
c: 302e332e eorcc r3, lr, lr, lsr #6
|
||||
...
|
||||
BIN
pizero/blinker01/blinker01.o
Normal file
BIN
pizero/blinker01/blinker01.o
Normal file
Binary file not shown.
11
pizero/blinker01/memmap
Normal file
11
pizero/blinker01/memmap
Normal file
@@ -0,0 +1,11 @@
|
||||
|
||||
MEMORY
|
||||
{
|
||||
ram : ORIGIN = 0x8000, LENGTH = 0x10000
|
||||
}
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
.text : { *(.text*) } > ram
|
||||
.bss : { *(.bss*) } > ram
|
||||
}
|
||||
BIN
pizero/blinker01/vectors.o
Normal file
BIN
pizero/blinker01/vectors.o
Normal file
Binary file not shown.
39
pizero/blinker01/vectors.s
Normal file
39
pizero/blinker01/vectors.s
Normal 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.
|
||||
;@
|
||||
;@-------------------------------------------------------------------------
|
||||
67
pizero/blinker02/Makefile
Normal file
67
pizero/blinker02/Makefile
Normal file
@@ -0,0 +1,67 @@
|
||||
|
||||
ARMGNU ?= arm-none-eabi
|
||||
|
||||
COPS = -Wall -O2 -nostdlib -nostartfiles -ffreestanding
|
||||
|
||||
gcc : blinker02.hex blinker02.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
|
||||
|
||||
blinker02.o : blinker02.c
|
||||
$(ARMGNU)-gcc $(COPS) -c blinker02.c -o blinker02.o
|
||||
|
||||
blinker02.elf : memmap vectors.o blinker02.o
|
||||
$(ARMGNU)-ld vectors.o blinker02.o -T memmap -o blinker02.elf
|
||||
$(ARMGNU)-objdump -D blinker02.elf > blinker02.list
|
||||
|
||||
blinker02.bin : blinker02.elf
|
||||
$(ARMGNU)-objcopy blinker02.elf -O binary blinker02.bin
|
||||
|
||||
blinker02.hex : blinker02.elf
|
||||
$(ARMGNU)-objcopy blinker02.elf -O ihex blinker02.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
|
||||
OOPS = -std-link-opts
|
||||
|
||||
clang : blinker02.clang.hex blinker02.clang.bin
|
||||
|
||||
|
||||
blinker02.clang.bc : blinker02.c
|
||||
clang $(LOPS) -c blinker02.c -o blinker02.clang.bc
|
||||
|
||||
blinker02.clang.opt.elf : memmap vectors.o blinker02.clang.bc
|
||||
opt $(OOPS) blinker02.clang.bc -o blinker02.clang.opt.bc
|
||||
llc $(LLCOPS) blinker02.clang.opt.bc -o blinker02.clang.opt.s
|
||||
$(ARMGNU)-as blinker02.clang.opt.s -o blinker02.clang.opt.o
|
||||
$(ARMGNU)-ld -o blinker02.clang.opt.elf -T memmap vectors.o blinker02.clang.opt.o
|
||||
$(ARMGNU)-objdump -D blinker02.clang.opt.elf > blinker02.clang.opt.list
|
||||
|
||||
blinker02.clang.hex : blinker02.clang.opt.elf
|
||||
$(ARMGNU)-objcopy blinker02.clang.opt.elf blinker02.clang.hex -O ihex
|
||||
|
||||
blinker02.clang.bin : blinker02.clang.opt.elf
|
||||
$(ARMGNU)-objcopy blinker02.clang.opt.elf blinker02.clang.bin -O binary
|
||||
|
||||
24
pizero/blinker02/README
Normal file
24
pizero/blinker02/README
Normal file
@@ -0,0 +1,24 @@
|
||||
|
||||
See the top level README for information on where to find documentation
|
||||
for the raspberry pi and the ARM processor inside. Also find information
|
||||
on how to load and run these programs.
|
||||
|
||||
There is a free-running 64 bit timer, super easy to use, just read it.
|
||||
|
||||
//0x01000000 17 seconds
|
||||
//0x00400000 4 seconds
|
||||
//#define TIMER_BIT 0x01000000
|
||||
#define TIMER_BIT 0x00400000
|
||||
|
||||
I think what they are doing is using a 1GHz clock for the ARM core
|
||||
(and GPU?) That is divided by 4 to get the 250MHz system clock (and
|
||||
or there is a 250MHz reference clock that is multiplied by 4). Either
|
||||
way there is a 250MHz system clock, and my guess is this is divided by
|
||||
256 to get 977KHz. 0x01000000 ticks would be 17.18 seconds and I am
|
||||
using a watch with a second hand, so very plausible.
|
||||
|
||||
Can change the TIMER_BIT to a different one to change the blink rate
|
||||
of the LED for example try:
|
||||
|
||||
#define TIMER_BIT 0x00100000
|
||||
|
||||
69
pizero/blinker02/blinker02.c
Normal file
69
pizero/blinker02/blinker02.c
Normal file
@@ -0,0 +1,69 @@
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
extern void PUT32 ( unsigned int, unsigned int );
|
||||
extern unsigned int GET32 ( unsigned int );
|
||||
extern void dummy ( unsigned int );
|
||||
|
||||
#define SYSTIMERCLO 0x20003004
|
||||
#define GPFSEL3 0x2020000C
|
||||
#define GPFSEL4 0x20200010
|
||||
#define GPSET1 0x20200020
|
||||
#define GPCLR1 0x2020002C
|
||||
|
||||
//0x01000000 17 seconds
|
||||
//0x00400000 4 seconds
|
||||
//#define TIMER_BIT 0x01000000
|
||||
#define TIMER_BIT 0x00400000
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
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));
|
||||
while(1)
|
||||
{
|
||||
ra=GET32(SYSTIMERCLO);
|
||||
if((ra&=TIMER_BIT)==TIMER_BIT) break;
|
||||
}
|
||||
PUT32(GPCLR1,1<<(47-32));
|
||||
//PUT32(GPSET1,1<<(35-32));
|
||||
while(1)
|
||||
{
|
||||
ra=GET32(SYSTIMERCLO);
|
||||
if((ra&=TIMER_BIT)==0) break;
|
||||
}
|
||||
}
|
||||
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
pizero/blinker02/memmap
Normal file
11
pizero/blinker02/memmap
Normal file
@@ -0,0 +1,11 @@
|
||||
|
||||
MEMORY
|
||||
{
|
||||
ram : ORIGIN = 0x8000, LENGTH = 0x1000
|
||||
}
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
.text : { *(.text*) } > ram
|
||||
.bss : { *(.bss*) } > ram
|
||||
}
|
||||
39
pizero/blinker02/vectors.s
Normal file
39
pizero/blinker02/vectors.s
Normal 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.
|
||||
;@
|
||||
;@-------------------------------------------------------------------------
|
||||
69
pizero/blinker03/Makefile
Normal file
69
pizero/blinker03/Makefile
Normal file
@@ -0,0 +1,69 @@
|
||||
|
||||
ARMGNU ?= arm-none-eabi
|
||||
|
||||
COPS = -Wall -O2 -nostdlib -nostartfiles -ffreestanding
|
||||
|
||||
gcc : blinker03.hex blinker03.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
|
||||
|
||||
blinker03.o : blinker03.c
|
||||
$(ARMGNU)-gcc $(COPS) -c blinker03.c -o blinker03.o
|
||||
|
||||
blinker03.elf : memmap vectors.o blinker03.o
|
||||
$(ARMGNU)-ld vectors.o blinker03.o -T memmap -o blinker03.elf
|
||||
$(ARMGNU)-objdump -D blinker03.elf > blinker03.list
|
||||
|
||||
blinker03.bin : blinker03.elf
|
||||
$(ARMGNU)-objcopy blinker03.elf -O binary blinker03.bin
|
||||
|
||||
blinker03.hex : blinker03.elf
|
||||
$(ARMGNU)-objcopy blinker03.elf -O ihex blinker03.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
|
||||
OOPSx = -std-compile-opts
|
||||
OOPS = -std-link-opts
|
||||
|
||||
clang : blinker03.clang.hex blinker03.clang.bin
|
||||
|
||||
|
||||
blinker03.clang.bc : blinker03.c
|
||||
clang $(LOPS) -c blinker03.c -o blinker03.clang.bc
|
||||
|
||||
blinker03.clang.opt.elf : memmap vectors.o blinker03.clang.bc
|
||||
opt $(OOPS) blinker03.clang.bc -o blinker03.clang.opt.bc
|
||||
llc $(LLCOPS) blinker03.clang.opt.bc -o blinker03.clang.opt.s
|
||||
$(ARMGNU)-as blinker03.clang.opt.s -o blinker03.clang.opt.o
|
||||
$(ARMGNU)-ld -o blinker03.clang.opt.elf -T memmap vectors.o blinker03.clang.opt.o
|
||||
$(ARMGNU)-objdump -D blinker03.clang.opt.elf > blinker03.clang.opt.list
|
||||
|
||||
blinker03.clang.hex : blinker03.clang.opt.elf
|
||||
$(ARMGNU)-objcopy blinker03.clang.opt.elf blinker03.clang.hex -O ihex
|
||||
|
||||
blinker03.clang.bin : blinker03.clang.opt.elf
|
||||
$(ARMGNU)-objcopy blinker03.clang.opt.elf blinker03.clang.bin -O binary
|
||||
|
||||
|
||||
16
pizero/blinker03/README
Normal file
16
pizero/blinker03/README
Normal file
@@ -0,0 +1,16 @@
|
||||
|
||||
See the top level README for information on where to find documentation
|
||||
for the raspberry pi and the ARM processor inside. Also find information
|
||||
on how to load and run these programs.
|
||||
|
||||
This example is for the pi zero, see other directories for other flavors
|
||||
of raspberry pi.
|
||||
|
||||
This example uses the free running ARM timer, not the 64 bit system
|
||||
timer as in blinker02 but the so called ARM timer. In free running mode
|
||||
which is a little different from blinker04 which uses the timer mode.
|
||||
|
||||
The system clock appears to come up at 250MHz as documented. Divide that
|
||||
by 250 to get 1Mhz on this free running ARM timer. Then count to four
|
||||
million ticks between LED state changes and the led will change state
|
||||
every four seconds. Count to 20 million, 20 seconds.
|
||||
82
pizero/blinker03/blinker03.c
Normal file
82
pizero/blinker03/blinker03.c
Normal file
@@ -0,0 +1,82 @@
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
extern void PUT32 ( unsigned int, unsigned int );
|
||||
extern unsigned int GET32 ( unsigned int );
|
||||
extern void dummy ( unsigned int );
|
||||
|
||||
#define ARM_TIMER_LOD 0x2000B400
|
||||
#define ARM_TIMER_VAL 0x2000B404
|
||||
#define ARM_TIMER_CTL 0x2000B408
|
||||
#define ARM_TIMER_DIV 0x2000B41C
|
||||
#define ARM_TIMER_CNT 0x2000B420
|
||||
|
||||
#define SYSTIMERCLO 0x20003004
|
||||
#define GPFSEL1 0x20200004
|
||||
#define GPSET0 0x2020001C
|
||||
#define GPCLR0 0x20200028
|
||||
#define GPFSEL3 0x2020000C
|
||||
#define GPFSEL4 0x20200010
|
||||
#define GPSET1 0x20200020
|
||||
#define GPCLR1 0x2020002C
|
||||
|
||||
//#define TIMEOUT 20000000
|
||||
#define TIMEOUT 4000000
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
int notmain ( void )
|
||||
{
|
||||
unsigned int ra;
|
||||
unsigned int rb;
|
||||
|
||||
ra=GET32(GPFSEL4);
|
||||
ra&=~(7<<21);
|
||||
ra|=1<<21;
|
||||
PUT32(GPFSEL4,ra);
|
||||
|
||||
//ra=GET32(GPFSEL3);
|
||||
//ra&=~(7<<15);
|
||||
//ra|=1<<15;
|
||||
//PUT32(GPFSEL3,ra);
|
||||
|
||||
PUT32(ARM_TIMER_CTL,0x00F90000);
|
||||
PUT32(ARM_TIMER_CTL,0x00F90200);
|
||||
|
||||
rb=GET32(ARM_TIMER_CNT);
|
||||
while(1)
|
||||
{
|
||||
PUT32(GPSET1,1<<(47-32));
|
||||
//PUT32(GPCLR1,1<<(35-32));
|
||||
while(1)
|
||||
{
|
||||
ra=GET32(ARM_TIMER_CNT);
|
||||
if((ra-rb)>=TIMEOUT) break;
|
||||
}
|
||||
rb+=TIMEOUT;
|
||||
PUT32(GPCLR1,1<<(47-32));
|
||||
//PUT32(GPSET1,1<<(35-32));
|
||||
while(1)
|
||||
{
|
||||
ra=GET32(ARM_TIMER_CNT);
|
||||
if((ra-rb)>=TIMEOUT) break;
|
||||
}
|
||||
rb+=TIMEOUT;
|
||||
}
|
||||
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
pizero/blinker03/memmap
Normal file
11
pizero/blinker03/memmap
Normal file
@@ -0,0 +1,11 @@
|
||||
|
||||
MEMORY
|
||||
{
|
||||
ram : ORIGIN = 0x8000, LENGTH = 0x1000
|
||||
}
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
.text : { *(.text*) } > ram
|
||||
.bss : { *(.bss*) } > ram
|
||||
}
|
||||
38
pizero/blinker03/vectors.s
Normal file
38
pizero/blinker03/vectors.s
Normal file
@@ -0,0 +1,38 @@
|
||||
|
||||
;@-------------------------------------------------------------------------
|
||||
;@-------------------------------------------------------------------------
|
||||
|
||||
.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.
|
||||
;@
|
||||
;@-------------------------------------------------------------------------
|
||||
71
pizero/blinker04/Makefile
Normal file
71
pizero/blinker04/Makefile
Normal file
@@ -0,0 +1,71 @@
|
||||
|
||||
ARMGNU ?= arm-none-eabi
|
||||
|
||||
AOPS = --warn --fatal-warnings
|
||||
COPS = -Wall -Werror -O2 -nostdlib -nostartfiles -ffreestanding
|
||||
|
||||
|
||||
|
||||
gcc : blinker04.hex blinker04.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
|
||||
|
||||
blinker04.o : blinker04.c
|
||||
$(ARMGNU)-gcc $(COPS) -c blinker04.c -o blinker04.o
|
||||
|
||||
blinker04.elf : memmap vectors.o blinker04.o
|
||||
$(ARMGNU)-ld vectors.o blinker04.o -T memmap -o blinker04.elf
|
||||
$(ARMGNU)-objdump -D blinker04.elf > blinker04.list
|
||||
|
||||
blinker04.bin : blinker04.elf
|
||||
$(ARMGNU)-objcopy blinker04.elf -O binary blinker04.bin
|
||||
|
||||
blinker04.hex : blinker04.elf
|
||||
$(ARMGNU)-objcopy blinker04.elf -O ihex blinker04.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
|
||||
OOPSx = -std-compile-opts
|
||||
OOPS = -std-link-opts
|
||||
|
||||
clang : blinker04.clang.hex blinker04.clang.bin
|
||||
|
||||
|
||||
blinker04.clang.bc : blinker04.c
|
||||
clang $(LOPS) -c blinker04.c -o blinker04.clang.bc
|
||||
|
||||
blinker04.clang.opt.elf : memmap vectors.o blinker04.clang.bc
|
||||
opt $(OOPS) blinker04.clang.bc -o blinker04.clang.opt.bc
|
||||
llc $(LLCOPS) blinker04.clang.opt.bc -o blinker04.clang.opt.s
|
||||
$(ARMGNU)-as blinker04.clang.opt.s -o blinker04.clang.opt.o
|
||||
$(ARMGNU)-ld -o blinker04.clang.opt.elf -T memmap vectors.o blinker04.clang.opt.o
|
||||
$(ARMGNU)-objdump -D blinker04.clang.opt.elf > blinker04.clang.opt.list
|
||||
|
||||
blinker04.clang.hex : blinker04.clang.opt.elf
|
||||
$(ARMGNU)-objcopy blinker04.clang.opt.elf blinker04.clang.hex -O ihex
|
||||
|
||||
blinker04.clang.bin : blinker04.clang.opt.elf
|
||||
$(ARMGNU)-objcopy blinker04.clang.opt.elf blinker04.clang.bin -O binary
|
||||
|
||||
|
||||
34
pizero/blinker04/README
Normal file
34
pizero/blinker04/README
Normal file
@@ -0,0 +1,34 @@
|
||||
|
||||
See the top level README for information on where to find documentation
|
||||
for the raspberry pi and the ARM processor inside. Also find information
|
||||
on how to load and run these programs.
|
||||
|
||||
This example is for the pi zero, see other directories for other flavors
|
||||
of raspberry pi.
|
||||
|
||||
This example uses the ARM timer, not in free running mode like blinker03
|
||||
but the other mode.
|
||||
|
||||
A few more typos in the datasheet. It is an SP804 not AP804 (page 196).
|
||||
Page 197, bit 1 32 bit counter not 23 bit counter. Page 198 neither
|
||||
the raw nor masked IRQ registers are at address 0x40C.
|
||||
|
||||
So if you want to poll an arbitrary time with a free running timer you
|
||||
take a reference count, and then take a sample, wait for the difference
|
||||
between the sample and reference count. You have to know if it is an
|
||||
up or down counter. You can turn this timer into a free running timer
|
||||
by setting the load registers to all ones. What you can also do with
|
||||
this kind of timer that you cannot with a free runing timer is set the
|
||||
load registers to some number of ticks (minus 1) and it will roll over
|
||||
the counter at that rate. Often these kinds of timers have an interrupt
|
||||
as does this one. And you can poll the interrupt bit without having to
|
||||
actually configure an interrupt. This example sets the prescaler to
|
||||
divide by 250. The clock as running here is 250Mhz, so this takes it
|
||||
down to 1Mhz, 1000000 clocks per second. Now if we set the load registers
|
||||
to 4 million counts (minus 1) then every 4 million counts at 1 million
|
||||
per second is 4 seconds. Every 4 seconds the timer interrupt will fire.
|
||||
Which you can read in the raw irq (not masked) register. Once it is
|
||||
set you have to write anything to the clear interrupt register. If you
|
||||
were to set up an interrupt service routine, you would clear that
|
||||
interrupt in the interrupt handler.
|
||||
|
||||
80
pizero/blinker04/blinker04.c
Normal file
80
pizero/blinker04/blinker04.c
Normal file
@@ -0,0 +1,80 @@
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
extern void PUT32 ( unsigned int, unsigned int );
|
||||
extern unsigned int GET32 ( unsigned int );
|
||||
extern void dummy ( unsigned int );
|
||||
|
||||
#define ARM_TIMER_LOD 0x2000B400
|
||||
#define ARM_TIMER_VAL 0x2000B404
|
||||
#define ARM_TIMER_CTL 0x2000B408
|
||||
#define ARM_TIMER_CLI 0x2000B40C
|
||||
#define ARM_TIMER_RIS 0x2000B410
|
||||
#define ARM_TIMER_MIS 0x2000B414
|
||||
#define ARM_TIMER_RLD 0x2000B418
|
||||
#define ARM_TIMER_DIV 0x2000B41C
|
||||
#define ARM_TIMER_CNT 0x2000B420
|
||||
|
||||
#define SYSTIMERCLO 0x20003004
|
||||
#define GPFSEL1 0x20200004
|
||||
#define GPSET0 0x2020001C
|
||||
#define GPCLR0 0x20200028
|
||||
#define GPFSEL3 0x2020000C
|
||||
#define GPFSEL4 0x20200010
|
||||
#define GPSET1 0x20200020
|
||||
#define GPCLR1 0x2020002C
|
||||
|
||||
//#define TIMEOUT 20000000
|
||||
#define TIMEOUT 4000000
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
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);
|
||||
|
||||
PUT32(ARM_TIMER_CTL,0x003E0000);
|
||||
PUT32(ARM_TIMER_LOD,TIMEOUT-1);
|
||||
PUT32(ARM_TIMER_RLD,TIMEOUT-1);
|
||||
PUT32(ARM_TIMER_DIV,0x000000F9);
|
||||
PUT32(ARM_TIMER_CLI,0);
|
||||
PUT32(ARM_TIMER_CTL,0x003E0082);
|
||||
|
||||
while(1)
|
||||
{
|
||||
PUT32(GPSET1,1<<(47-32));
|
||||
//PUT32(GPCLR1,1<<(35-32));
|
||||
while(1) if(GET32(ARM_TIMER_RIS)) break;
|
||||
PUT32(ARM_TIMER_CLI,0);
|
||||
PUT32(GPCLR1,1<<(47-32));
|
||||
//PUT32(GPSET1,1<<(35-32));
|
||||
while(1) if(GET32(ARM_TIMER_RIS)) break;
|
||||
PUT32(ARM_TIMER_CLI,0);
|
||||
}
|
||||
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
pizero/blinker04/memmap
Normal file
11
pizero/blinker04/memmap
Normal file
@@ -0,0 +1,11 @@
|
||||
|
||||
MEMORY
|
||||
{
|
||||
ram : ORIGIN = 0x8000, LENGTH = 0x1000
|
||||
}
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
.text : { *(.text*) } > ram
|
||||
.bss : { *(.bss*) } > ram
|
||||
}
|
||||
38
pizero/blinker04/vectors.s
Normal file
38
pizero/blinker04/vectors.s
Normal file
@@ -0,0 +1,38 @@
|
||||
|
||||
;@-------------------------------------------------------------------------
|
||||
;@-------------------------------------------------------------------------
|
||||
|
||||
.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.
|
||||
;@
|
||||
;@-------------------------------------------------------------------------
|
||||
Reference in New Issue
Block a user