Resetting STM32 option bytes

Without too much thinking I wrote a code to Argon’s STM32 ARM processor that write protects its flash content. After a minute I encountered a problem that I was unable to program anything new to the chip as it protects writing into memory also with a debugging tool effectively bricking the device. It took an hour to figure out how to restore the chip option bytes that determine if the flash memory is protected or not. JLink’s small utility that is supposed to restore STM32 option bytes didn’t appear to work for write protection so alternative solution was necessary to avoid replacing the chip on PCB.

After some googling (found this useful forum post) and reading chip data sheets I figured out how to do it manually with JLink Commander tool. I’m posting JLink command list here as I’m sure there are people needing this info, too.

(unprotect option bytes)
w4 0x40023c08,0x08192A3B
w4 0x40023c08,0x4C5D6E7F

(restore non-write protected state. one could also reset other option bytes here such as read protection or brown out reset settings by modifying the next line)

w2 0x40023C16,0xffff

(write option bytes)
w1 0x40023C14,0xef

I’m not sure if g and haltĀ commands are necessary but used them just in case. This should work at least with STM32F2 series and probably also STM32F3 and STM32F4 chips too.

JLink Commander when unlocking STM32F2 write protection

JLink Commander screenshot after unlocking STM32F2 write protection

4 thoughts on “Resetting STM32 option bytes

  1. High, I messed up flash option bytes and was unable to program my STM32F103C8T6.

    And now what? The solution you provided worked like a charm! My chip is back on track once again! Thank you very very very much!

    P.S.: So I can confirm this solution is applicable to STM32F10x chips as well.

  2. Hi,

    I locked up my system with readout protection with level 1 and reterived with your information. The steps are usefull. Thank you,


Leave a Reply

Your email address will not be published. Required fields are marked *

* Copy This Password *

* Type Or Paste Password Here *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>