From ca7eaec90352eae4b1b2317c9f30c6416d35dfac Mon Sep 17 00:00:00 2001 From: Kyle Isom Date: Thu, 8 Mar 2018 11:31:00 -0800 Subject: [PATCH] blue-pill: cleaning some stuff up --- blue-pill/draugr/Makefile | 30 ++++++++++++++++++++++++------ blue-pill/draugr/blink.cc | 2 +- blue-pill/draugr/startup.s | 9 ++++----- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/blue-pill/draugr/Makefile b/blue-pill/draugr/Makefile index 34fefa9..210204d 100644 --- a/blue-pill/draugr/Makefile +++ b/blue-pill/draugr/Makefile @@ -15,6 +15,8 @@ CXX := $(ARMTC)-g++ LD := $(ARMTC)-ld ARMSIZE := $(ARMTC)-size OBJCOPY := $(ARMTC)-objcopy +PAGER ?= less +OPENOCD ?= /usr/share/openocd # compiler options CPUFLAGS := -mcpu=cortex-m3 -mthumb @@ -26,8 +28,7 @@ LDLIBS := -lc -lnosys # programmer options STARTMEM := 0x8000000 -# targets - +### build targets ### .PHONY: all all: $(BIN) @@ -38,6 +39,11 @@ $(ELF): $(OBJS) $(BIN): $(ELF) $(OBJCOPY) -O binary $< $@ +.PHONY: clean +clean: + rm -f *.o *.bin *.elf *.d *.map + +### programming targets ### .PHONY: flash flash: $(BIN) st-flash write $(BIN) $(STARTMEM) @@ -46,10 +52,22 @@ flash: $(BIN) erase: st-flash erase +.PHONY: reset +reset: + st-flash reset + .PHONY: install -install: erase flash +install: erase flash reset -.PHONY: clean -clean: - rm -f *.o *.bin *.elf *.d *.map +### miscellaneous targets ### +.PHONY: disass +disass: $(ELF) + $(ARMTC)-objdump -D $(ELF) | $(PAGER) +.PHONY: dump +dump: $(ELF) + $(ARMTC)-objdump -D $(ELF) > $(TARGET).dump + +.PHONY: ocd +ocd: + openocd -f $(OPENOCD)/scripts/interface/stlink-v2.cfg -f $(OPENOCD)/scripts/target/stm32f1x.cfg diff --git a/blue-pill/draugr/blink.cc b/blue-pill/draugr/blink.cc index 7de7ceb..81b9729 100644 --- a/blue-pill/draugr/blink.cc +++ b/blue-pill/draugr/blink.cc @@ -10,7 +10,7 @@ main() { GPIO_C->enable_clock(); GPIO_C->pin_mode(LED, true, OUTPUT_GPP, OUTPUT_MAX_2MHZ); - while(1) { + while (true) { GPIO_C->pin_clear(LED); delay(LDELAY); GPIO_C->pin_set(LED); diff --git a/blue-pill/draugr/startup.s b/blue-pill/draugr/startup.s index f55d87c..5c55a35 100644 --- a/blue-pill/draugr/startup.s +++ b/blue-pill/draugr/startup.s @@ -1,17 +1,17 @@ /* * Startup code for the STM32F103-based blue pill board. * - * TODO: revisit stack pointer - * TODO: is the IRQv buffer actually needed right now? + * The stack pointer is initialised to the top of the stack (which + * grows downward), so I pointed it to the end of the SRAM (where the + * stack should be). */ .cpu cortex-m3 .thumb -.globl vectors vectors: .align 2 -.long 0x20002000 /* best guess at stack pointer */ +.long 0x20005000 /* stack pointer points to top of SRAM */ .long reset_handler /* reset handler */ .long hang /* NMI handler */ .long hang /* hard_fault_handler */ @@ -30,7 +30,6 @@ vectors: .thumb_func hang: b . - .thumb_func reset_handler: bl main