cancel
Showing results for 
Search instead for 
Did you mean: 

Writing Option Bytes on STM32F1

guandast
Associate

Hello,

Im developing an program that controls an ST-Link to flash an STM32F1. The program needs to be able to remove RDP on the MCU its trying to flash.

Im doing the following steps:

1) Unlocking Flash - confirmed working (registers confirm)

2) Unlocking option bytes - confirmed working (registers confirm)

3) Erasing Option Bytes - confirmed Working (If I have no RDP on, and erase, RDP gets set, as 0xFF = RDP on)

4) Writing new Option Bytes, 16 Bit Operation. Here it fails.

 

Any Ideas? Ive attached two Logic Analyser captures (Saleae Logic 2 Software), one from slightly modified OpenOCD which unlocks successfully, and my implementation, which doesnt work.

 

My implementation:

guandast_2-1729788721514.png

 

OpenOCD:

guandast_1-1729788647355.png

 

Happy to hear your Ideas!

5 REPLIES 5
Uwe Bonnes
Principal III

After optiion byte erase, a reset happens. You need to reconnect.

BUt why do you want to write a new stlink program?

Are they? Kind of hard to believe:

- OPTB is still unlocked after erasing

- If I have an GPIO (LED) high, the LED stays on, even after erase, and only turns off when I do an actual reset

 

Please correct my if Im wrong.

Why I want to build an STLink Program? Because there isnt anything out there yet that is WebUSB based. (or well there is, but that doesnt allow option bytes)

jiangfan
ST Employee

Do you mean you develop a PC program that controls an ST-Link to flash an STM32F1?

In such case, you may 1st try with STM32CubeProgrammer, to be able to remove RDP on the MCU its trying to flash. Then you just need to repeat the same steps with your PC program.

Thats exactly what Im trying to do, however with OpenOCD as I can browse the source code. My question is, why the Option Byte Write fails, what part I am missing.

You need to take care of following point.

The options must be reloaded after every change of the Option bytes in the NVM, so that the
changes can apply.