2025-02-26 2:50 AM
Hi everyone
I'm currently trying to set RDP option bytes on STM32G070 chip with OpenOCD
I try :
> reset halt
[stm32g0x.cpu] halted due to breakpoint, current mode: Thread
xPSR: 0xf1000000 pc: 0xfffffffe msp: 0xfffffffc
> stm32g0x lock 0
flash write algorithm aborted by target
flash write failed at address 0x1fff7808
flash memory write protected
SWD DPIDR 0x0bc11477
Failed to write memory at 0x4002200c
stm32x failed to lock device
and :
> reset halt
[stm32g0x.cpu] halted due to breakpoint, current mode: Thread
xPSR: 0xf1000000 pc: 0xfffffffe msp: 0xfffffffc
> flash protect 0 0 last on
flash write algorithm aborted by target
flash write failed at address 0x1fff7808
flash memory write protected
SWD DPIDR 0x0bc11477
Failed to write memory at 0x4002200c
failed setting protection for blocks 0 to 63
I don't understand where the problem could come from because as you can see below I am able to erase and rewrite in flash without any problem...
Is anyone has already use that :
> reset halt
[stm32g0x.cpu] halted due to breakpoint, current mode: Thread
xPSR: 0xf1000000 pc: 0xfffffffe msp: 0xfffffffc
> flash erase_sector 0 0 last
erased sectors 0 through 63 on flash bank 0 in 0.025186s
> program "E:/OpenOCD/openocd-20240916/OpenOCD-20240916-0.12.0/bin/mon_firmware.hex" preverify verify
[stm32g0x.cpu] halted due to breakpoint, current mode: Thread
xPSR: 0xf1000000 pc: 0xfffffffe msp: 0xfffffffc
**pre-verifying**
checksum mismatch - attempting binary compare
** Programming Started **
** Programming Finished **
** Verify Started **
** Verified OK **
>
Thaks for your time
Regards
Solved! Go to Solution.
2025-02-26 10:46 PM
The "flash lock" and "flash unlock" commands just lock/unlock the FLASH_CR register. That's unrelated to RDP setting. You need (see OpenOCD docs, don't worry about the stm32l4x, this works for the g0xx as well):
Command: stm32l4x option_write num reg_offset value [reg_mask]
Write an option byte register of the stm32l4x device. The num parameter is a value shown by flash banks, reg_offset is the register offset of the Option byte to write, and reg_mask is the mask to apply when writing the register (only bits with a ’1’ will be touched).
Note: To apply the option bytes change immediately, use stm32l4x option_load.
For example to write the WRP1AR option bytes:
stm32l4x option_write 0 0x28 0x00FF0000 0x00FF00FF
The above example will write the WRP1AR option register configuring the Write protection Area A for bank 1. The above example set WRP1AR_END=255, WRP1AR_START=0. This will effectively write protect all sectors in flash bank 1.
2025-02-26 10:46 PM
The "flash lock" and "flash unlock" commands just lock/unlock the FLASH_CR register. That's unrelated to RDP setting. You need (see OpenOCD docs, don't worry about the stm32l4x, this works for the g0xx as well):
Command: stm32l4x option_write num reg_offset value [reg_mask]
Write an option byte register of the stm32l4x device. The num parameter is a value shown by flash banks, reg_offset is the register offset of the Option byte to write, and reg_mask is the mask to apply when writing the register (only bits with a ’1’ will be touched).
Note: To apply the option bytes change immediately, use stm32l4x option_load.
For example to write the WRP1AR option bytes:
stm32l4x option_write 0 0x28 0x00FF0000 0x00FF00FF
The above example will write the WRP1AR option register configuring the Write protection Area A for bank 1. The above example set WRP1AR_END=255, WRP1AR_START=0. This will effectively write protect all sectors in flash bank 1.