2021-01-25 06:17 AM
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?
2021-01-27 07:47 AM
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...
2021-01-28 03:56 AM
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.
2021-01-28 06:28 AM
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.
2021-02-09 08:36 AM
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();