2021-01-28 10:25 PM
I want to apply Read Protection to the STM32L552CCT6 .
If you execute HAL_FLASH_OB_Launch(); after setting Read Protection, reboot does not work.
Read Protection is applied only when the power is physically rebooted.
I want Read Protection to be applied as ST reboots after executing HAL_FLASH_OB_Launch();.
Below is the code I used.
----------------------------------------------------------------------------------------------------------------------------
///* Unlock the Flash to enable the flash control register access *************/
HAL_FLASH_Unlock();
///* Unlock the Options Bytes *************************************************/
HAL_FLASH_OB_Unlock();
OptionsBytesStruct.RDPLevel = OB_RDP_LEVEL_1;
OptionsBytesStruct.OptionType = OPTIONBYTE_RDP;
if(HAL_FLASHEx_OBProgram(&OptionsBytesStruct) != HAL_OK)
{
/* Error occurred while options bytes programming. **********************/
}
else
{
/* Generate System Reset to load the new option byte values ***************/
HAL_FLASH_OB_Launch();
}
/* Lock the Options Bytes *************************************************/
HAL_FLASH_OB_Lock();
HAL_FLASH_Lock();
---------------------------------------------------------------------------------------------------------------------------------------
Help
2021-01-29 03:13 AM
Maybe try to call HAL_FLASH_OB_Lock(); & HAL_FLASH_Lock();
before calling OB_Launch ?
You have another function like NVIC_SystemReset() in case you need to reset.
2021-02-01 01:45 PM
Hello Kjoon,
this behaviour is "normal" if a debugger was detected.
For instance if you flash your code with debugger and then launch the firmware, as soon as RDP1 is set, the flash is locked because of this debugger connection.
One way to overcome this is to go through a standby transition. This transition is equivalent to a power-on reset for this purpose.
So, instead of calling OB_Launch, just setup a RTC wakeup in 10ms and go to standby. After wakeup RDP1 will be set and code will run.
My colleague made a video on this specific point here: https://www.youtube.com/playlist?list=PLnMKNibPkDnGxKqGyLbiGygmlrvISIBIT
Just select: STM32 Security tips - 3 RDP without POR
Best regards
Jocelyn