Last active
August 29, 2015 14:03
-
-
Save apparentlymart/2a83e5779f71d9ba810a to your computer and use it in GitHub Desktop.
mbed LPC1768 LLVM GPIO Example
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
define void @main() { | |
; Set pin as output (and all other pins on this port as input, since we're lazy.) | |
store i32 128, i32* inttoptr(i32 537509922 to i32*) | |
; LPC1768 GPIOs have both a basic value register, allowing the | |
; port to be read and written as a single integer, and special | |
; set/clear registers that will set/clear (respectively) any | |
; bit set to 1 when written, leaving any 0 bits unchanged. | |
; This allows individual bits to be modified without having to | |
; read and preserve the other bits. | |
; Clear LED (by writing 1 to the "clear" bit for this port) | |
store i32 128, i32* inttoptr(i32 537509950 to i32*) | |
; Set LED (by writing 1 to the "set" bit for this port) | |
store i32 128, i32* inttoptr(i32 537509946 to i32*) | |
ret void | |
} |
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
/* Boot stub. Must be linked first to be at the beginning of the program ROM. */ | |
/* Main program must provide an entry point function called "main". */ | |
.cpu cortex-m3 | |
.thumb | |
.word 0x10008000 /* stack top address */ | |
.word _start /* 1 Reset */ | |
.word hang /* 2 NMI */ | |
.word hang /* 3 HardFault */ | |
.word hang /* 4 MemManage */ | |
.word hang /* 5 BusFault */ | |
.word hang /* 6 UsageFault */ | |
.word hang /* 7 RESERVED */ | |
.word hang /* 8 RESERVED */ | |
.word hang /* 9 RESERVED*/ | |
.word hang /* 10 RESERVED */ | |
.word hang /* 11 SVCall */ | |
.word hang /* 12 Debug Monitor */ | |
.word hang /* 13 RESERVED */ | |
.word hang /* 14 PendSV */ | |
.word hang /* 15 SysTick */ | |
.word hang /* 16 External Interrupt(0) */ | |
.word hang /* 17 External Interrupt(1) */ | |
.word hang /* 18 External Interrupt(2) */ | |
.word hang /* 19 ... */ | |
.thumb_func | |
hang: b . | |
.thumb_func | |
.globl _start | |
_start: | |
bl main | |
bl hang | |
.end |
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
/* GCC Linker Script */ | |
MEMORY | |
{ | |
rom(RX) : ORIGIN = 0x00000000, LENGTH = 0x40000 | |
ram(WAIL) : ORIGIN = 0x10000000, LENGTH = 30K | |
} | |
SECTIONS | |
{ | |
.text : { *(.text*) } > rom | |
.bss : { *(.bss*) } > ram | |
} |
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
all: blink.bin | |
blink.bc: blink.ll | |
opt-3.4 blink.ll -o blink.bc -basiccg -domtree -reg2mem -inline -constprop -die -adce -mem2reg | |
blink.s: blink.bc | |
llc-3.4 -march=thumb blink.bc -o blink.s | |
%.o: %.s | |
arm-none-eabi-as $< -o $@ | |
blink.elf: boot.o blink.o | |
arm-none-eabi-ld -T linker boot.o blink.o -o blink.elf | |
blink.bin: blink.elf | |
arm-none-eabi-objcopy blink.elf blink.bin -O binary | |
clean: | |
rm -f blink.s blink.o boot.o blink.elf blink.bin blink.bc | |
upload: blink.bin | |
cp blink.bin /media/MBED/blink.bin |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment