0

The STM32 has a read-out protection level 2 feature so code can't be read out via the debug interface (SWD).

Using OpenOCD, how can I enable the read-out protection LEVEL 2 via a SWD interface?

kahan
  • 1
  • 1

2 Answers2

0

you will ned to write the script unloncking option bytes and programming them.

Use st-link utility instead

0___________
  • 60,014
  • 4
  • 34
  • 74
0

openocd script for STM32F42x:

// unlock Option bytes
mww 0x40023C08 0x08192A3B; // OPT key1
mww 0x40023C08 0x4C5D6E7F; // OPT key2
mdw 0x40023c0c // wait until returns 00000000 that signifies flash write done

mww 0x40023C14 0x8000AAEC; // enable SPRMOD (8), disable write protection
mww 0x40023C18 0x00000000;
mww 0x40023C14 0x8000AAEE; // execute option start
mdw 0x40023c0c // wait until returns 00000000 that signifies flash write done

// at this point SPRMOD should be set, but no protection. Now invert protection bits
mww 0x40023C14 0x8FFFCCEC; // enable WRP on bank 1 and read protection lvl2
mww 0x40023C18 0x0FFF0000; // WRP on bank 2
mww 0x40023C14 0x8FFFCCEE; // execute option start
mdw 0x40023c0c // wait until returns 00000000 that signifies flash write done

Note, I haven't done this myself (at least not intentionally), but reference manual is your friend.

Note 2: this might brick your MCU

stiebrs
  • 379
  • 3
  • 13