cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H745 raising hard fault when changing RDP level from 0 to 1

ILave.1
Associate

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?

1 REPLY 1
FBL
ST Employee

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

  1. boot from FLASH
  2. jump to execute code from RAM ( __RAM_FUNC )
  3. change RDP and enter StandBy (executed from RAM).
  4. wakeup with RTC

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.