cancel
Showing results for 
Search instead for 
Did you mean: 

MB1549C: SWAPBANK is set 1 but its not run bank2 firmware. Always, starts with BANK1 firmware.

vijay_03
Associate II

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,

  1. Two files for bank1, secure and non-secure firmware. uploaded at 0xC000 0000
  2. 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.


_legacyfs_online_stmicro_images_0693W00000bjTA3QAM.png
_legacyfs_online_stmicro_images_0693W00000bjTAIQA2.png
_legacyfs_online_stmicro_images_0693W00000bjTLfQAM.png
_legacyfs_online_stmicro_images_0693W00000bjTLuQAM.png 

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

1 REPLY 1
FBL
ST Employee

Hello @vijay_03​,

Linker file should not get changed from Flash bank 1 to bank2.

An internal ticket (ID 152745) is submitted in order to update the example swap bank.

(PS: ID 152745 is an internal tracking number and is not accessible or usable by customers).

STM32U5 does not support dual boot.

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.