STM32H743 Flash bank swap leads to WWDG reset
Hello,
I am trying to perform a flash bank swap from bank1 to bank2. Executing the following code:
FLASH_OBProgramInitTypeDef OBInit;
/* Unlock tha User Flash area */
HAL_FLASH_Unlock();
HAL_FLASH_OB_Unlock();
/* Get the Dual boot configuration status */
HAL_FLASHEx_OBGetConfig(&OBInit);
/* Get FLASH_WRP_SECTORS write protection status */
OBInit.Banks = FLASH_BANK_1;
HAL_FLASHEx_OBGetConfig(&OBInit);
/* Check Swap Flash banks status */
if ((OBInit.USERConfig & OB_SWAP_BANK_ENABLE) == OB_SWAP_BANK_DISABLE) {
/*Swap to bank2 */
/*Set OB SWAP_BANK_OPT to swap Bank2*/
OBInit.OptionType = OPTIONBYTE_USER;
OBInit.USERType = OB_USER_SWAP_BANK;
OBInit.USERConfig = OB_SWAP_BANK_ENABLE;
HAL_FLASHEx_OBProgram(&OBInit);
/* Launch Option bytes loading */
HAL_FLASH_OB_Launch();
SCB_InvalidateICache();
NVIC_SystemReset();
} else {
/* Swap to bank1 */
/*Set OB SWAP_BANK_OPT to swap Bank1*/
OBInit.OptionType = OPTIONBYTE_USER;
OBInit.USERType = OB_USER_SWAP_BANK;
OBInit.USERConfig = OB_SWAP_BANK_DISABLE;
HAL_FLASHEx_OBProgram(&OBInit);
/* Launch Option bytes loading */
HAL_FLASH_OB_Launch();
SCB_InvalidateICache();
NVIC_SystemReset();
}
return 0;During the code fragment execution HAL_FLASH_OB_Launch() is called and I get a reset. Reset reason is WWDG reset.
When I execute this in step by step mode it is successful as the WWDG debug option is enabled.
If I enable the WWDG ISR and execute the bank swap function the ISR handler is not called but the reset reason is still WWDG reset and flash bank swap is not successful.
I have modified the HAL_FLASH_OB_Launch() and FLASH_OB_WaitForLastOperation(50000) to get some timestamps in a no_init ram section and saw that after SET_BIT(FLASH->OPTCR, FLASH_OPTCR_OPTSTART); I get a WWDG reset. The counter did not expire and ISR Handler was not called.
PS. Interrupts are not disabled.
Watchdog refresh was added on few extra steps (in wait conditions) and before function calls to guarantee that this is not an issue.
Micro:STM32H743XIH6 revision V.
