MB1549C: SWAPBANK is set 1 but its not run bank2 firmware. Always, starts with BANK1 firmware.
Hi,
I am using MB1549C DK which has STM32U575ZIT6 MCU.
I have enabled trust zone as well as dual bank.
I have four hex file,
- Two files for bank1, secure and non-secure firmware. uploaded at 0xC000 0000
- Two files for bank2, secure and non-secure firmware. uploaded at 0xC100 0000
At bootup, I have read swapbank bit of OPTR reg.
uint8_t getActiveBank() {
volatile uint32_t remap = READ_BIT(FLASH_NS->OPTR, 0x1 << 20);
return remap == 0 ? 1 : 2;
}I have used below reference function from standard example to modify swap bank bit.
NUCLEO-U575ZI-Q\Examples\FLASH\FLASH_SwapBanks
void toggleBankAndReset() {
/* Unlock the User Flash area */
HAL_FLASH_Unlock();
HAL_FLASH_OB_Unlock();
/* Get the boot configuration status */
FLASH_OBProgramInitTypeDef OBInit;
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();
} 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();
}
}I am able to update SWAPBANK bit and also able to read.
But when SWAPBANK is set to 1, at that time, firmware located at BANK2 doesn't run. It always run BANK1 firmware.
Here I have attached flash ld. file for all four hex file. and option byte configuration.



I want to switch between two firmware which are located in bank1 and bank2 in trust zone.
Can you please guide me, if anything I have missed ?
Does STM32U5 supports dual boot?
Thanks & Regards,
VIJAY
