cancel
Showing results for 
Search instead for 
Did you mean: 

We are using STM32L476 in our application in which we have seen accidental change in RDP level when battery voltage drops below 0%. Is there any corner case we should take care?

kpate.11
Associate II

In code, we do not have call for changing RDP but we have a logic to reset IWDG_STOP bit after wakeup from sleep mode.

We are facing this option byte corruption problem when battery drops below 0%. (We do not have HW support for cutting off power for MCU when battery drops below 0%).

Is there any limitation for modifying option byte or erase/read/write flash (IAP mode) and VCC level. ? Can drop in voltage during ongoing flash read/write/erase operation corrupt Option byte?

13 REPLIES 13

Well, my question was because for F479, which was the closes match to the initial non-existing "F476", there is no IWDG_STOP bit and again the closest match was the DBG_IWDG_STOP bit. And now it turns out that "SLEEP" mode is actually STOP2 mode...

Now the question becomes even more relevant. Are you modifying option bytes after each wake-up? Again - why? Option bytes are not the ordinary registers, but effectively EEPROM stored in FLASH memory. Not only it is not necessary, but you are also wearing it out. Probably have already done that and that is why it fails...

Yes. My Bad. Appologies for wrong part number. Its actually L476.

We are not modifying IWDG_STOP bit after wakeup. But, system will check if it is set then only it will go for resetting it.

You have to expect abnormal behaviour in abnormal power condition, for sure. Abnormal behaviour can include corrupting option bytes, especially when the guard against unwanted write has been lifted before with preparation of flash write.

kpate.11
Associate II

Okay. I resolved the issue with work around. I changed logic to set option byte to just bootup time to reduce the probability of getting it corrupted.

Moreover, I have seen MCU to get stuck while option byte write. Which I solved using proper method to write and launch option byte as follow. (if someone want to use it. Strictly this is for STM32L476 only. For other series some other workaround may work)

	                       FLASH_OBProgramInitTypeDef    OBInit;
				HAL_FLASH_Unlock();
				HAL_FLASH_OB_Unlock();
				__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPTVERR);
				__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS);
 
				memset(&OBInit,0,sizeof(FLASH_OBProgramInitTypeDef));
 
				HAL_FLASHEx_OBGetConfig(&OBInit);
 
				//TBD: Change option byte for required operation
 
				FLASH_WaitForLastOperation((uint32_t)1000);
 
				__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPTVERR);
				__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS);
 
				HAL_FLASHEx_OBProgram(&OBInit);
 
				HAL_FLASH_OB_Lock();
				HAL_FLASH_Lock();
				HAL_Delay(20);
				HAL_FLASH_Unlock();
				HAL_FLASH_OB_Unlock();
 
				HAL_FLASH_OB_Launch(); // after this call MCU should reboot and load new option byte
 
//not sure if follwing is needed
				HAL_FLASH_OB_Lock();
				HAL_FLASH_Lock();
				NVIC_SystemReset();