2025-05-15 7:01 AM
Hello,
I work on a STM32F042G6Ux mounted on a custom board, and I want to automatize the flash by using command line and STLink (I'm using V2-1 one).
STM_CLI works well to unlock the reading, unfortunately I read that ST won't deploy it on ARM architecture, and I want to work on Raspberry Pi.
That's why I decided to use OpenOCD (v0.12.0) to flash my STM32. However, there's a problem using it : I have to switch power supply to apply the changes on the option bytes. I want my command line fully automated, and this is problematic.
config.cfg :
adapter driver hla
hla layout stlink
hla stlink_backend usb
hla_vid_pid 0x0483 0x3744 0x0483 0x3748 0x0483 0x374b 0x0483 0x374d 0x0483 0x374e 0x0483 0x374f 0x0483 0x3752 0x0483 0x3753 0x0483 0x3754 0x0483 0x3755 0x0483 0x3757
transport select hla_swd
source [find target/stm32f0x.cfg]
reset_config srst_only srst_nogate
openocd command :
openocd
-f config.cfg
-c 'adapter serial stlinkid'
-c init
-c 'reset halt'
-c 'stm32f1x unlock 0'
-c 'reset halt'
-c 'program mybinary.hex verify reset exit'
and it results in this error :
** Programming Started **
Error: stm32x device protected
Error: failed erasing sectors 0 to 7
** Programming Failed **
When I connect with STMCubeProgrammer, I have this error (normal , read is protected) :
But when I read Option Bytes, RDP =0xAA!
I strongly suspect the Hardware didn't work on openocd, even if I configured it with "reset_config srst_only srst_nogate".
How can STM_CLI can do a good HW reset and not OpenOCD?
The wires connexions are the same for STM_CLI and OpenOCD, and it's SWD connexion ones : SWDIo, SWCLK and SRST are connected. I used SWD connexion in both OpenOCD, STM_CLI and STMCubeProgrammer.