2025-11-25 8:00 PM
Hello everyone!
I'm facing a problem when trying to switch a bank on STM32H745 MCU. The issue happens only when the debugger is disconnected. Our implementation uses the HAL library to perform Bank switch like this:
HAL_FLASH_Unlock();
HAL_FLASH_OB_Unlock();
FLASH_OBProgramInitTypeDef info;
HAL_FLASHEx_OBGetConfig(&info);
// swap banks in option bytes
info.OptionType = OPTIONBYTE_USER;
info.USERType = OB_USER_SWAP_BANK;
if (info.USERConfig & OB_SWAP_BANK_ENABLE)
info.USERConfig &= ~OB_SWAP_BANK_ENABLE;
else
info.USERConfig |= OB_SWAP_BANK_ENABLE;
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS_BANK1);
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_ALL_ERRORS_BANK2);
HAL_StatusTypeDef ret = HAL_FLASHEx_OBProgram(&info);
if (HAL_OK == ret)
{
// launch new configuration
ret = HAL_FLASH_OB_Launch();
}
(void)HAL_FLASH_OB_Lock();
(void)HAL_FLASH_Lock();
__HAL_RCC_CLEAR_RESET_FLAGS();
NVIC_SystemReset();In some of the builds it does not work and after reset it keeps running the previous image.
I found that