Setting RDP option byte in STM32L452
I have a problem programmatically setting RDP to level 1.
My code is:
OBInit.RDPLevel = OB_RDP_LEVEL_1;
OBInit.OptionType = OPTIONBYTE_RDP;
ret = HAL_FLASH_Unlock();
ret = HAL_FLASH_OB_Unlock();
/* Clear SR register */
CLEAR_BIT(FLASH->SR, FLASH_SR_BSY);
ret = HAL_FLASHEx_OBProgram(&OBInit);
ret = HAL_FLASH_OB_Lock();
ret = HAL_FLASH_Lock();
HAL_Delay(2000);
ret = HAL_FLASH_OB_Launch();
// shouldn't get to this point, as processor will reset
I had to put in the clear pf FLASH->SR, otherwise the "FLASH_WaitForLastOperation" would fail inside "FLASH_OB_RDPConfig". I've no idea why the flash should be busy at this stage.
Whether or not I run this under the debugger, the RDP byte never changes. The last HAL_Delay is to give the flash chance to be written properly before the launch resets the processor.
