cancel
Showing results for 
Search instead for 
Did you mean: 

Why when writing flash option bytes causes an infinite reboot cycle?

DBurr
Senior

I'm running this code in my application and it continuously reboots. I've since moved the writing of the option bytes to the programming stage to avoid it but want to understand what I'm doing wrong.

  FLASH_OBProgramInitTypeDef ob;                                                
 
  HAL_FLASH_Unlock();                                                           
  __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPTVERR);                                   
  HAL_FLASH_OB_Unlock();                                                        
  HAL_FLASHEx_OBGetConfig(&ob);                                                 
                                                                                
  if (ob.USERConfig & OB_IWDG_STOP_RUN) {                                       
      ob.USERConfig &= ~OB_IWDG_STOP_RUN;                                       
      HAL_FLASHEx_OBProgram(&ob);                                               
      HAL_FLASH_OB_Launch();                                                    
  }                                                                             
                                                                                
  HAL_FLASH_OB_Lock();                                                          
  HAL_FLASH_Lock();

This discussion is locked. Please start a new topic to ask your question.
2 REPLIES 2
Piranha
Chief II

The ob structure is not initialized and that is not correct even for HAL_FLASHEx_OBGetConfig() function.

There is no need to unlock FLASH/OB for reading. Unlocking should be performed only when modifying FLASH/OB.

DBurr
Senior

Thanks for the suggestions. Even if change that line to

FLASH_OBProgramInitTypeDef ob = {0};

it still results in the same outcome.