2022-11-01 10:48 AM
Hi I have been trying to change the read protection level on my device using the ST HAL driver library:
The code I am using is:
FLASH_OBProgramInitTypeDef OB_Config;
//Read Option byte configuration
HAL_FLASHEx_OBGetConfig(&OB_Config);
//Update read protection option byte
OB_Config.OptionType = OPTIONBYTE_RDP;
OB_Config.RDPLevel = OB_RDP;
//Program new option byte configuration
bool option_bytes_failed_to_update{true};
if(HAL_FLASH_OB_Unlock() == HAL_OK)
{
if(HAL_FLASH_Unlock() == HAL_OK)
{
if(HAL_FLASHEx_OBProgram(&OB_Config) == HAL_OK)
{
if(HAL_FLASH_OB_Launch() == HAL_OK)
{
if(HAL_FLASH_OB_Lock() == HAL_OK)
{
if(HAL_FLASH_Lock() == HAL_OK)
{
option_bytes_failed_to_update = false;
}
}
}
}
}
}
When the function HAL_FLASH_OB_Launch() is makes a call to status = FLASH_OB_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE); which causes a hard fault.
Has anyone had a similar experience with this device and possibly a pointer to what I am doing wrong?
2022-11-25 6:42 AM
Hello @ILave.1,
If debugger access is detected then R/W/Erase to FLASH memory, SRAM, and Backup registers are blocked (hard fault generated).
So, I suggest the following sequence
You can check this MOOC and its attached resources
STM32 Security tips - 4 RDP without POR in STM32F4 - YouTube
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
We’re moving the ST Community to a new platform to give you a better and more reliable community experience.