Skip to main content
DBurr
Senior
June 8, 2022
Question

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

  • June 8, 2022
  • 2 replies
  • 860 views

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 topic has been closed for replies.

2 replies

Piranha
Principal III
June 8, 2022

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
DBurrAuthor
Senior
June 9, 2022

Thanks for the suggestions. Even if change that line to

FLASH_OBProgramInitTypeDef ob = {0};

it still results in the same outcome.