From 9b5e05a7c793ae0f3817af3ecba63f7b02713dea Mon Sep 17 00:00:00 2001 From: Christopher Arndt Date: Tue, 8 Mar 2016 11:29:22 +0100 Subject: [PATCH] stmhal: Add makefile target and configuration to deploy via OpenOCD. --- stmhal/Makefile | 6 +++++ stmhal/README.md | 15 +++++++++++ stmhal/boards/openocd_stm32f4.cfg | 42 +++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 stmhal/boards/openocd_stm32f4.cfg diff --git a/stmhal/Makefile b/stmhal/Makefile index 93ff92bc8f..847cb4e8b2 100644 --- a/stmhal/Makefile +++ b/stmhal/Makefile @@ -30,6 +30,8 @@ PYDFU ?= ../tools/pydfu.py DFU_UTIL ?= dfu-util DEVICE=0483:df11 STFLASH ?= st-flash +OPENOCD ?= openocd +OPENOCD_CONFIG ?= boards/openocd_stm32f4.cfg CROSS_COMPILE = arm-none-eabi- @@ -293,6 +295,10 @@ deploy-stlink: $(BUILD)/firmware.dfu $(ECHO) "Writing $(BUILD)/firmware1.bin to the board via ST-LINK" $(Q)$(STFLASH) --reset write $(BUILD)/firmware1.bin 0x08020000 +deploy-openocd: $(BUILD)/firmware.dfu + $(ECHO) "Writing $(BUILD)/firmware{0,1}.bin to the board via ST-LINK using OpenOCD" + $(Q)$(OPENOCD) -f $(OPENOCD_CONFIG) -c "stm_flash $(BUILD)/firmware0.bin $(BUILD)/firmware1.bin" + $(BUILD)/firmware.dfu: $(BUILD)/firmware.elf $(ECHO) "Create $@" $(Q)$(OBJCOPY) -O binary -j .isr_vector $^ $(BUILD)/firmware0.bin diff --git a/stmhal/README.md b/stmhal/README.md index 457aaf9964..6ebee35258 100644 --- a/stmhal/README.md +++ b/stmhal/README.md @@ -82,6 +82,21 @@ and set the `STLINK_DEVICE` environment variable accordingly, using the format $ make BOARD=STM32F4DISC deploy-stlink +### Flashing the Firmware with OpenOCD + +Another option to deploy the firmware on ST Discovery or Nucleo boards with a +ST-LINK interface uses [OpenOCD](http://openocd.org/). Connect the board with +a mini USB cable to its ST-LINK USB port and then use the make target +`deploy-openocd`. For example, if you have the STM32F4DISCOVERY board: + + $ make BOARD=STM32F4DISC deploy-openocd + +The `openocd` program, which writes the firmware to the target board's flash, +is configured via the file `stmhal/boards/openocd_stm32f4.cfg`. This +configuration should work for all boards based on a STM32F4xx MCU with a +ST-LINKv2 interface. You can override the path to this configuration by setting +`OPENOCD_CONFIG` in your Makefile or on the command line. + Accessing the board ------------------- diff --git a/stmhal/boards/openocd_stm32f4.cfg b/stmhal/boards/openocd_stm32f4.cfg new file mode 100644 index 0000000000..e03ea87a15 --- /dev/null +++ b/stmhal/boards/openocd_stm32f4.cfg @@ -0,0 +1,42 @@ +# This script configures OpenOCD for use with an ST-Link V2 programmer/debugger +# and an STM32F4 target microcontroller. +# +# To flash your firmware: +# +# $ openocd -f openocd_stm32f4.cfg \ +# -c "stm_flash build-BOARD/firmware0.bin build-BOARD/firmware1.bin" +# +# For a gdb server on port 3333: +# +# $ openocd -f openocd_stm32f4.cfg + + +source [find interface/stlink-v2.cfg] +transport select hla_swd +source [find target/stm32f4x.cfg] +reset_config srst_only +init + +proc stm_flash { BIN0 BIN1 } { + reset halt + sleep 100 + wait_halt 2 + flash write_image erase $BIN0 0x08000000 + sleep 100 + verify_image $BIN0 0x08000000 + sleep 100 + flash write_image erase $BIN1 0x08020000 + sleep 100 + verify_image $BIN1 0x08020000 + sleep 100 + reset run + shutdown +} + +proc stm_erase {} { + reset halt + sleep 100 + stm32f4x mass_erase 0 + sleep 100 + shutdown +}