cancel
Showing results for 
Search instead for 
Did you mean: 

Can't activate readout protection using option bytes

GBout1
Associate

Hi

I try to activate readout protection using jlink/jflash.

The read out protection is level 0 (0xaa on last bytes of option byte currently 0xDFFFE1AA), I want to set level 1, using 0x00 value instead of AA.

After flashing my binary, lock and optlock protection are successfully removed using keys and optkeys writing in flash registers.

Then I write 32 bits option bytes at 0x01fff7800(w4 0x1FFF7800 0xDFFFE100), this command fails. According to reference manual, this writing sequence is supposed to erase option byte(including complemented option bytes?), then write option byte.

Here received error:

****** Error: Programming failed @ address 0x1FFF7804 (block verification error)
Failed to restore target. RAMCode never stops

0x1FFF7804 address corresponds to complemented option bytes(32 bits), which should be computed and written after setting OPT_START(this is the next step in my script).

device stm32g0b1re
//init and flash bin
[...]
//Remove Lock
w4 0x40022008, 0x45670123 // Send KEY1
w4 0x40022008, 0xCDEF89AB // Send KEY2
//Remove OptLock
w4 0x4002200C 0x08192A3B // Send OPTKEY1
w4 0x4002200C 0x4C5D6E7F // Send OPTKEY2
mem32 0x40022014 1 //check LOCK and OPT_LOCK is removed
//Write option byte
w4 0x1FFF7800 0xDFFFE100 //Write option bytes and activate RDP(command fails!)
w4 0x40022014 0x00020000 // Set OPTSTART to compute complemented option bytes
 

I try to erase option bytes before writing but this has no effects.

1 ACCEPTED SOLUTION

Accepted Solutions
Antoine Odonne
ST Employee

Hello,

In fact you are not allowed to modify the option bytes themselves in Non Volatile Memory (@0x1FFF7800), you must modify there copies in the Flash interface Registers (@0x40022020) and then launch programing in the NVM by setting OPTSTRT (this will erase Option bytes and there complement and reprogram new OB and computed complement too). After programmed you must load them to become effective thanks to OBL_LAUNCH bit. The adequate procedure will be described in Reference Manual RM0444, section 3.4.2 " Flash Option byte programming"

Thank you and regards,

Antoine

View solution in original post

3 REPLIES 3
Antoine Odonne
ST Employee

Hello,

In fact you are not allowed to modify the option bytes themselves in Non Volatile Memory (@0x1FFF7800), you must modify there copies in the Flash interface Registers (@0x40022020) and then launch programing in the NVM by setting OPTSTRT (this will erase Option bytes and there complement and reprogram new OB and computed complement too). After programmed you must load them to become effective thanks to OBL_LAUNCH bit. The adequate procedure will be described in Reference Manual RM0444, section 3.4.2 " Flash Option byte programming"

Thank you and regards,

Antoine

Thanks,

option bytes can be setted with the register (0x40022020).

Loading with OBL_LAUNCH set(or reset) is also needed.

After OPTSTRT position 1, the user options byte page is automatically erased,Is that right