From 237ca864da1bde97969bb887362a2d5431e1c10b Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Mon, 17 Feb 2020 21:48:46 +0100 Subject: [PATCH] Programming using serial boot loader --- bin/stm32flash | 3 +++ mk/bluepill.mk | 17 ++++++++++++++++- test-blink/Makefile | 5 +++-- test-blink/test.c | 3 +++ 4 files changed, 25 insertions(+), 3 deletions(-) create mode 100755 bin/stm32flash diff --git a/bin/stm32flash b/bin/stm32flash new file mode 100755 index 0000000..d660f9c --- /dev/null +++ b/bin/stm32flash @@ -0,0 +1,3 @@ +#!/bin/sh +# Flashing via serial boot loader +exec ~/stm/stm32flash/stm32flash "$@" diff --git a/mk/bluepill.mk b/mk/bluepill.mk index d6146ab..e762525 100644 --- a/mk/bluepill.mk +++ b/mk/bluepill.mk @@ -105,15 +105,30 @@ ifdef WITH_DFU_FLASH else +ifdef WITH_SERIAL_FLASH + +BOOT_SERIAL ?= /dev/ttyUSB0 + %.flash: %.bin @printf " FLASH $<\n" - $(Q)$(ROOT)/bin/st-flash write $(*).bin 0x8000000 + $(Q)$(ROOT)/bin/stm32flash $(BOOT_SERIAL) -i 'dtr,-dtr' -w $< -g 0 .PHONY: reset reset: all + $(Q)$(ROOT)/bin/stm32flash $(BOOT_SERIAL) -i 'dtr,-dtr' -g 0 + +else + +%.flash: %.bin + @printf " FLASH $<\n" + $(Q)$(ROOT)/bin/st-flash write $(*).bin 0x8000000 + +.PHONY: reset +reset: $(ROOT)/bin/st-flash reset endif +endif .SECONDEXPANSION: .SECONDARY: diff --git a/test-blink/Makefile b/test-blink/Makefile index 81ed48b..953160a 100644 --- a/test-blink/Makefile +++ b/test-blink/Makefile @@ -3,7 +3,8 @@ BINARY=test OBJS=test.o LIB_OBJS=util-debug.o -WITH_BOOT_LOADER=1 -WITH_DFU_FLASH=1 +# WITH_BOOT_LOADER=1 +# WITH_DFU_FLASH=1 +WITH_SERIAL_FLASH=1 include $(ROOT)/mk/bluepill.mk diff --git a/test-blink/test.c b/test-blink/test.c index 50ca8ba..e56426c 100644 --- a/test-blink/test.c +++ b/test-blink/test.c @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -48,6 +49,8 @@ int main(void) clock_setup(); gpio_setup(); tick_setup(); + // This is needed when programming via serial boot loader, harmless otherwise. + SCB_VTOR = 0x08000000; cm_enable_interrupts(); for (;;) { -- 2.39.2