Skip to content

Instantly share code, notes, and snippets.

@nunb
Forked from uxp/Makefile
Created April 9, 2017 15:55
Show Gist options
  • Select an option

  • Save nunb/e1802cf2fb54d71f0542f1e1c19f9667 to your computer and use it in GitHub Desktop.

Select an option

Save nunb/e1802cf2fb54d71f0542f1e1c19f9667 to your computer and use it in GitHub Desktop.
/* locore.s
* Assembler startup file for the STM32F103
* Tom Trebisky 9-24-2016
*/
# The Cortex M3 is a thumb only processor
.cpu cortex-m3
.thumb
.word 0x20005000 /* stack top address */
.word _reset /* 1 Reset */
.word spin /* 2 NMI */
.word spin /* 3 Hard Fault */
.word spin /* 4 MM Fault */
.word spin /* 5 Bus Fault */
.word spin /* 6 Usage Fault */
.word spin /* 7 RESERVED */
.word spin /* 8 RESERVED */
.word spin /* 9 RESERVED*/
.word spin /* 10 RESERVED */
.word spin /* 11 SV call */
.word spin /* 12 Debug reserved */
.word spin /* 13 RESERVED */
.word spin /* 14 PendSV */
.word spin /* 15 SysTick */
.word spin /* 16 IRQ0 */
.word spin /* 17 IRQ1 */
.word spin /* 18 IRQ2 */
.word spin /* 19 ... */
/* On to IRQ67 */
spin: b spin
.thumb_func
_reset:
bl startup
b .
/* THE END */
# Makefile for blink demo
#TOOLS = arm-linux-gnu
TOOLS = arm-none-eabi
# Assembling with gcc makes it want crt0 at link time.
#AS = $(TOOLS)-gcc
AS = $(TOOLS)-as
# Use the -g flag if you intend to use gdb
#CC = $(TOOLS)-gcc -mcpu=cortex-m3 -mthumb
CC = $(TOOLS)-gcc -mcpu=cortex-m3 -mthumb -g
#LD = $(TOOLS)-gcc
LD = $(TOOLS)-ld.bfd
OBJCOPY = $(TOOLS)-objcopy
DUMP = $(TOOLS)-objdump -d
GDB = $(TOOLS)-gdb
OBJS = locore.o blink.o
all: blink.bin blink.dump
blink.dump: blink.elf
$(DUMP) blink.elf >blink.dump
blink.bin: blink.elf
$(OBJCOPY) blink.elf blink.bin -O binary
blink.elf: $(OBJS)
$(LD) -T blink.lds -o blink.elf $(OBJS)
locore.o: locore.s
$(AS) locore.s -o locore.o
blink.o: blink.c
$(CC) -c blink.c
# To burn the image:
# Connect the STLINK gadget to the target.
# Be sure and start openOCD in this directory.
# (or else it won't be able to find the bin file).
# Then use "make flash" to start an openocd console session.
# Type: reset halt
# Type: flash write_image erase blink.bin 0x08000000
flash:
@echo "type: flash write_image erase blink.bin 0x08000000"
telnet localhost 4444
gdb:
$(GDB) --eval-command="target remote localhost:3333" blink.elf
gdbtui:
$(GDB) -tui --eval-command="target remote localhost:3333" blink.elf
clean:
rm -f *.o blink.elf blink.bin blink.dump
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment