cancel
Showing results for 
Search instead for 
Did you mean: 

Power cycling after ROP setting

Michal Dubovsky
Associate II
Posted on June 28, 2017 at 13:34

Hello. My application hangs after setting the ROP to LVL1 and resetting the whole device. I have found some people had this issue as well and power cycling helped (which is my case as well). But it is kind of an inconvenience as my application is battery powered. Is there any way of avoiding having to do this?

My code for setting the ROP lvl:

/**

* @brief Enables a LVL1 read out protection (if it is not enabled yet)

*/

static void enable_ROP_LVL1(void)

{

   FLASH_OBProgramInitTypeDef OptionsBytesStruct;

   HAL_FLASH_Unlock(); // Unlock the Flash to enable the flash control register access

   HAL_FLASH_OB_Unlock(); // Unlock the Options Bytes

   HAL_FLASHEx_OBGetConfig(&OptionsBytesStruct); // Get pages write protection status

   // Check if read out protection is enabled

   if((OptionsBytesStruct.RDPLevel) == OB_RDP_LEVEL_0)

   {

      OptionsBytesStruct.OptionType = OPTIONBYTE_RDP;

      OptionsBytesStruct.RDPLevel = OB_RDP_LEVEL_1;

      if(HAL_FLASHEx_OBProgram(&OptionsBytesStruct) != HAL_OK)

      {

         _Error_Handler(__FILE__, __LINE__);

      }

      HAL_FLASH_OB_Launch(); // Generate System Reset to load the new option byte values

   }

   HAL_FLASH_OB_Lock(); // Lock the Options Bytes

}
1 REPLY 1
janmatik9
Associate II
Posted on November 10, 2017 at 16:13

Hi Michal, 

I had the same problem - setting protection level to 1 without need to make a power cycle.

According to datasheet, power reset happens also on exit from StandBy/Shutdown modes. So I tried to put CPU into StandBy after writing flash config and let IWDG to do a wakeup. I don't use OB_Launch call. IWDG is on by default in our app. This solution works for us.

Steps I do:

  • flash and OB unlock
  • write config
  • flash and OB lock
  • enter standby mode (IWDG is enabled)
  • after IWDG expiry, application starts with proper Protection level.

I think IWDG_STDBY must be on so watchdog is running also in StandBy mode.

Hope this will help.

PS: We are using STM32L471.