Skip to main content
DBurr
Senior
Jun 8, 2022 7:29 PM UTC
Question

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

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
Jun 8, 2022 11:14 PM UTC

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
Jun 9, 2022 1:50 PM UTC

Thanks for the suggestions. Even if change that line to

FLASH_OBProgramInitTypeDef ob = {0};

it still results in the same outcome.