STM32L496 goes into lockup state when setting readout protection
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;
