2026-01-29 1:54 AM - last edited on 2026-01-29 1:56 AM by Andrew Neil
Hello,
I have a problem with setting readout protection in the STM32L496 device in software. The protection is set to "BB". After setting and power on reset, the microcontroller seems to not work (it looks like as if it was "stuck up"). I connected the ST-Link programmer and run STM32Cube programmer and it shows option byte RDP set correctly to BB value. Also, in the FAULT ANALYZER section it displays "CPU: LOCKUP". I don't know why it happens and how to solve it. The software code that sets the RDP protection is shown below:
__disable_irq();
while (FLASH->SR & FLASH_SR_BSY);
FLASH->KEYR = 0x45670123;
FLASH->KEYR = 0xCDEF89AB;
FLASH->OPTKEYR = 0x08192A3B;
FLASH->OPTKEYR = 0x4C5D6E7F;
FLASH->OPTR = 0xFFEFF8BB;
FLASH->CR |= FLASH_CR_OPTSTRT;
while (FLASH->SR & FLASH_SR_BSY);
FLASH->CR |= FLASH_CR_OBL_LAUNCH;
2026-01-29 3:43 AM
"CPU:LOCKUP" may be result of attempting to debug the RDP-protected mcu.
If you don't set RDP1 through your program, but e.g. using CubeProgrammer, does your program run after power-on reset?
If not, the problem is not in the code you presented above. Debug e.g. by outputting debug printouts at strategic places, or just blink LED, i.e. without involvement of the debugger.
JW