STM32 firmware command line tools (please adjust 0x200000
):
STM32_Programmer_CLI.exe -c port=SWD --upload 0x8000000 0x200000 firmware.bin # extract from board
STM32_Programmer_CLI.exe -c port=SWD -w firmware.bin 0x08000000 -rst # flash to board
STM32 firmware command line tools (please adjust 0x200000
):
STM32_Programmer_CLI.exe -c port=SWD --upload 0x8000000 0x200000 firmware.bin # extract from board
STM32_Programmer_CLI.exe -c port=SWD -w firmware.bin 0x08000000 -rst # flash to board
Flashing an updated demo2.elf
firmware to a NUCLEO-G071RB board:
$ STM32_Programmer_CLI.exe -c port=SWD -w demo2.elf 0x08000000 -rst
-------------------------------------------------------------------
STM32CubeProgrammer v2.17.0
-------------------------------------------------------------------
ST-LINK SN : 066CFF3031454D3043094425
ST-LINK FW : V2J46M31
Board : NUCLEO-G071RB
Voltage : 3.22V
SWD freq : 4000 KHz
Connect mode: Normal
Reset mode : Software reset
Device ID : 0x460
Revision ID : Rev B
Device name : STM32G07x/STM32G08x
Flash size : 128 KBytes
Device type : MCU
Device CPU : Cortex-M0+
BL Version : 0xB2
Debug in Low Power mode enabled
Warning: Write address is ignored for hex, Srec, s19 and elf files
Memory Programming ...
Opening and parsing file: demo2.elf
File : demo2.elf
Size : 10.77 KB
Address : 0x08000000
Erasing memory corresponding to segment 0:
Erasing internal memory sectors [0 5]
Download in Progress:
██████████████████████████████████████████████████ 100%
File download complete
Time elapsed during download operation: 00:00:00.435
MCU Reset
Software reset is performed
NOTE: The extracted firmware.bin
and the updated demo2.elf
(from an IDE build) are in different format. The openocd
, while usable, is not as flexible, so I find it best to use STM32_Programmer_CLI.exe
. For example, we can extract the firmware using either openocd
or STM32_Programmer_CLI
command:
STM32_Programmer_CLI.exe -c port=SWD --upload 0x8000000 0x20000 firmware1.bin
openocd -f interface/stlink-v2.cfg -f target/stm32g0x.cfg -c init -c "reset halt" -c "flash read_bank 0 firmware2.bin 0 0x20000" -c "reset" -c shutdown
$ md5sum firmware1.bin firmware2.bin
bd345b8cf8334ff7ffaf4993922d8012 *firmware1.bin
bd345b8cf8334ff7ffaf4993922d8012 *firmware2.bin
Furthermore, you can flush to the board using:
openocd -f interface/stlink-v2.cfg -f target/stm32g0x.cfg -c init -c "reset halt" -c "flash write_image erase firmware2.bin 0x08000000" -c "reset" -c shutdown
But, YOU CANNOT flush demo2.elf
using openocd
. Hence, this is why I prefer STM32_Programmer_CLI
because it can flush to the board both binary formats.
Extracting the firmware from a NUCLEO-G071RB board and saving to
firmware.bin
file: