stmhal: Add makefile target and configuration to deploy via OpenOCD.

This commit is contained in:
Christopher Arndt 2016-03-08 11:29:22 +01:00 committed by Damien George
parent ad725a6661
commit 9b5e05a7c7
3 changed files with 63 additions and 0 deletions

View File

@ -30,6 +30,8 @@ PYDFU ?= ../tools/pydfu.py
DFU_UTIL ?= dfu-util DFU_UTIL ?= dfu-util
DEVICE=0483:df11 DEVICE=0483:df11
STFLASH ?= st-flash STFLASH ?= st-flash
OPENOCD ?= openocd
OPENOCD_CONFIG ?= boards/openocd_stm32f4.cfg
CROSS_COMPILE = arm-none-eabi- 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" $(ECHO) "Writing $(BUILD)/firmware1.bin to the board via ST-LINK"
$(Q)$(STFLASH) --reset write $(BUILD)/firmware1.bin 0x08020000 $(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 $(BUILD)/firmware.dfu: $(BUILD)/firmware.elf
$(ECHO) "Create $@" $(ECHO) "Create $@"
$(Q)$(OBJCOPY) -O binary -j .isr_vector $^ $(BUILD)/firmware0.bin $(Q)$(OBJCOPY) -O binary -j .isr_vector $^ $(BUILD)/firmware0.bin

View File

@ -82,6 +82,21 @@ and set the `STLINK_DEVICE` environment variable accordingly, using the format
$ make BOARD=STM32F4DISC deploy-stlink $ 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 Accessing the board
------------------- -------------------

View File

@ -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
}