From f8776a989fdd3fa76fa2199bbac42e1bc8f52a5b Mon Sep 17 00:00:00 2001 From: "Vinicius G. Guimaraes" Date: Fri, 3 Apr 2020 11:53:29 -0700 Subject: [PATCH] boards/blxxxpill: add support for stm32duino bootloader and for generic St-Link V2. --- boards/common/blxxxpill/Makefile.include | 16 ++++++++++++++++ boards/common/blxxxpill/dist/openocd-128kib.cfg | 13 ++++++++++++- boards/common/blxxxpill/dist/openocd.cfg | 13 ++++++++++++- makefiles/tools/openocd-adapters/stlink.inc.mk | 10 ++++++++++ 4 files changed, 50 insertions(+), 2 deletions(-) diff --git a/boards/common/blxxxpill/Makefile.include b/boards/common/blxxxpill/Makefile.include index 3d785078d7c2..ecbe5bfa912c 100644 --- a/boards/common/blxxxpill/Makefile.include +++ b/boards/common/blxxxpill/Makefile.include @@ -7,6 +7,22 @@ ifeq (dfu-util,$(PROGRAMMER)) # Leave some space at the beginning of the flash for the bootloader ROM_OFFSET ?= 0x2000 + + # If using STM32duino bootloader, this change is necessary. + # Bootloader available at + # github.com/rogerclarkmelbourne/STM32duino-bootloader/tree/master/binaries + ifeq (stm32duino,$(BOOTLOADER)) + FFLAGS_OPTS ?= -R + FFLAGS ?= --device $(DFU_USB_ID) \ + --alt $(DFU_ALT) \ + --download $(FLASHFILE) \ + $(FFLAGS_OPTS) + + # Flashing may be easier if using a software USB reset. + # Future updates may provide USB support for stm32f1 which benefits + # from this software reset. + endif + else ifeq (openocd,$(PROGRAMMER)) STLINK_VERSION ?= 2 endif diff --git a/boards/common/blxxxpill/dist/openocd-128kib.cfg b/boards/common/blxxxpill/dist/openocd-128kib.cfg index ccaf60b777c7..8fa2f66ed9e0 100644 --- a/boards/common/blxxxpill/dist/openocd-128kib.cfg +++ b/boards/common/blxxxpill/dist/openocd-128kib.cfg @@ -9,9 +9,20 @@ set STOP_WATCHDOG 1 # STlink Debug clock frequency set CLOCK_FREQ 4000 +# Some revisions of the Bluepills use a CS32F103C8T6 rather than the STM32Fx +# MCU, which has a different CPUTAPID than the official STM32F103C8T6. As of +# 2020-04-09, no upstream support in OpenOCD has been merged. You can uncomment +# the following line as a workaround until your OpenOCD supports this option: +#set CPUTAPID 0x2ba01477 + +# Set the default reset option in cases where "SRST=none" is not used for make +if { ![info exists SRST_OPT] } { + set SRST_OPT srst_only +} + # use hardware reset, connect under reset # connect_assert_srst needed if low power mode application running (WFI...) -reset_config srst_only srst_nogate connect_assert_srst +reset_config $SRST_OPT srst_nogate connect_assert_srst set CONNECT_UNDER_RESET 1 # brutally overwriting detected flash size with 128KiB (OpenOCD > 0.10.0) diff --git a/boards/common/blxxxpill/dist/openocd.cfg b/boards/common/blxxxpill/dist/openocd.cfg index dd5f286454d7..a61d142cdade 100644 --- a/boards/common/blxxxpill/dist/openocd.cfg +++ b/boards/common/blxxxpill/dist/openocd.cfg @@ -9,9 +9,20 @@ set STOP_WATCHDOG 1 # STlink Debug clock frequency set CLOCK_FREQ 4000 +# Some revisions of the Bluepills use a CS32F103C8T6 rather than the STM32Fx +# MCU, which has a different CPUTAPID than the official STM32F103C8T6. As of +# 2020-04-09, no upstream support in OpenOCD has been merged. You can uncomment +# the following line as a workaround until your OpenOCD supports this option: +#set CPUTAPID 0x2ba01477 + +# Set the default reset option in cases where "SRST=none" is not used for make +if { ![info exists SRST_OPT] } { + set SRST_OPT srst_only +} + # use hardware reset, connect under reset # connect_assert_srst needed if low power mode application running (WFI...) -reset_config srst_only srst_nogate connect_assert_srst +reset_config $SRST_OPT srst_nogate connect_assert_srst set CONNECT_UNDER_RESET 1 source [find target/stm32f1x.cfg] diff --git a/makefiles/tools/openocd-adapters/stlink.inc.mk b/makefiles/tools/openocd-adapters/stlink.inc.mk index 0e1fcaa1e62a..0c8c74984d08 100644 --- a/makefiles/tools/openocd-adapters/stlink.inc.mk +++ b/makefiles/tools/openocd-adapters/stlink.inc.mk @@ -11,6 +11,16 @@ ifneq (,$(DEBUG_ADAPTER_ID)) OPENOCD_ADAPTER_INIT += -c 'hla_serial $(DEBUG_ADAPTER_ID)' endif + +# Some stlink clones cannot signal reset properly, +# In this case, use SRST=none +ifneq (,$(SRST)) + #Change the adapter init to it + # Use STLINK_VERSION to select which stlink version is used + OPENOCD_ADAPTER_INIT += \ + -c 'set SRST_OPT $(SRST)' +endif + # if no openocd specific configuration file, check for default locations: # 1. Using the default dist/openocd.cfg (automatically set by openocd.sh) # 2. Using the common cpu specific config file