Skip to content

Commit 9b5e05a

Browse files
SpotlightKiddpgeorge
authored andcommitted
stmhal: Add makefile target and configuration to deploy via OpenOCD.
1 parent ad725a6 commit 9b5e05a

3 files changed

Lines changed: 63 additions & 0 deletions

File tree

stmhal/Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ PYDFU ?= ../tools/pydfu.py
3030
DFU_UTIL ?= dfu-util
3131
DEVICE=0483:df11
3232
STFLASH ?= st-flash
33+
OPENOCD ?= openocd
34+
OPENOCD_CONFIG ?= boards/openocd_stm32f4.cfg
3335

3436
CROSS_COMPILE = arm-none-eabi-
3537

@@ -293,6 +295,10 @@ deploy-stlink: $(BUILD)/firmware.dfu
293295
$(ECHO) "Writing $(BUILD)/firmware1.bin to the board via ST-LINK"
294296
$(Q)$(STFLASH) --reset write $(BUILD)/firmware1.bin 0x08020000
295297

298+
deploy-openocd: $(BUILD)/firmware.dfu
299+
$(ECHO) "Writing $(BUILD)/firmware{0,1}.bin to the board via ST-LINK using OpenOCD"
300+
$(Q)$(OPENOCD) -f $(OPENOCD_CONFIG) -c "stm_flash $(BUILD)/firmware0.bin $(BUILD)/firmware1.bin"
301+
296302
$(BUILD)/firmware.dfu: $(BUILD)/firmware.elf
297303
$(ECHO) "Create $@"
298304
$(Q)$(OBJCOPY) -O binary -j .isr_vector $^ $(BUILD)/firmware0.bin

stmhal/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,21 @@ and set the `STLINK_DEVICE` environment variable accordingly, using the format
8282
$ make BOARD=STM32F4DISC deploy-stlink
8383

8484

85+
### Flashing the Firmware with OpenOCD
86+
87+
Another option to deploy the firmware on ST Discovery or Nucleo boards with a
88+
ST-LINK interface uses [OpenOCD](http://openocd.org/). Connect the board with
89+
a mini USB cable to its ST-LINK USB port and then use the make target
90+
`deploy-openocd`. For example, if you have the STM32F4DISCOVERY board:
91+
92+
$ make BOARD=STM32F4DISC deploy-openocd
93+
94+
The `openocd` program, which writes the firmware to the target board's flash,
95+
is configured via the file `stmhal/boards/openocd_stm32f4.cfg`. This
96+
configuration should work for all boards based on a STM32F4xx MCU with a
97+
ST-LINKv2 interface. You can override the path to this configuration by setting
98+
`OPENOCD_CONFIG` in your Makefile or on the command line.
99+
85100
Accessing the board
86101
-------------------
87102

stmhal/boards/openocd_stm32f4.cfg

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# This script configures OpenOCD for use with an ST-Link V2 programmer/debugger
2+
# and an STM32F4 target microcontroller.
3+
#
4+
# To flash your firmware:
5+
#
6+
# $ openocd -f openocd_stm32f4.cfg \
7+
# -c "stm_flash build-BOARD/firmware0.bin build-BOARD/firmware1.bin"
8+
#
9+
# For a gdb server on port 3333:
10+
#
11+
# $ openocd -f openocd_stm32f4.cfg
12+
13+
14+
source [find interface/stlink-v2.cfg]
15+
transport select hla_swd
16+
source [find target/stm32f4x.cfg]
17+
reset_config srst_only
18+
init
19+
20+
proc stm_flash { BIN0 BIN1 } {
21+
reset halt
22+
sleep 100
23+
wait_halt 2
24+
flash write_image erase $BIN0 0x08000000
25+
sleep 100
26+
verify_image $BIN0 0x08000000
27+
sleep 100
28+
flash write_image erase $BIN1 0x08020000
29+
sleep 100
30+
verify_image $BIN1 0x08020000
31+
sleep 100
32+
reset run
33+
shutdown
34+
}
35+
36+
proc stm_erase {} {
37+
reset halt
38+
sleep 100
39+
stm32f4x mass_erase 0
40+
sleep 100
41+
shutdown
42+
}

0 commit comments

Comments
 (0)