Skip to main content
Nikhil D&K
Associate III
April 14, 2023
Solved

Dual bank swap not working in STM32L4A6 but working in STM32L496

Hello Devs,

Currently i have 2 firmware performing same task with different target board selected i.e:

  1. Firmware 1: NFC DFU with STM32L496ZG
  2. Firmware 2: NFC DFU with STM32L4A6ZG

Firmware 1:

Currently in my project with target board selected as "STM32L496" and NFC Tag ST25DV04KC tag, i am performing NFC DFU using dual bank mode. Now everything works fine in this firmware, i am able to download the firmware in Banks and by setting/resetting BFB2 optional byte, i am able to swap banks as well. And also when i flash the same project on "STM32L4A6ZG" i am still able to perform Dual Bank update.

Firmware 2:

But when i create new STM32 project with target selected as "STM32L4A6ZG" and rest firmware is same like Firmware 1 still after storing the packets from the NFC in Bank 2 and after setting BFB2 optional byte my program stucks after execution of function "HAL_FLASH_OB_Launch". So can anyone please help me with this issue.

Below is the ToggleBankandReset function which i call after successfully transfering firmware:

void toggleBankAndReset(void) {
 
	/* Set BFB2 bit to enable boot from Flash Bank2 */
	/* Allow Access to Flash control registers and user Flash */
	HAL_FLASH_Unlock();
 
	/* Clear OPTVERR bit set on virgin samples */
	__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_OPTVERR);
 
	/* Allow Access to option bytes sector */
	HAL_FLASH_OB_Unlock();
 
	/* Get the Dual boot configuration status */
	HAL_FLASHEx_OBGetConfig(&OBInit);
 
	/* Enable/Disable dual boot feature */
	OBInit.OptionType = OPTIONBYTE_USER;
	OBInit.USERType = OB_USER_BFB2;
 
	if (((OBInit.USERConfig) & (OB_BFB2_ENABLE)) == OB_BFB2_ENABLE) {
		OBInit.USERConfig = OB_BFB2_DISABLE;
		logUsart("Bank1 mapped to 0x00000000 at boot");
	} else {
		OBInit.USERConfig = OB_BFB2_ENABLE;
		logUsart("Bank2 mapped to 0x00000000 at boot");
	}
 
	if (HAL_FLASHEx_OBProgram(&OBInit) != HAL_OK) {
		/*
		 Error occurred while setting option bytes configuration.
		 User can add here some code to deal with this error.
		 To know the code error, user can call function 'HAL_FLASH_GetError()'
		 */
		/* Infinite loop */
		while (1) {
 
		}
	}
 
	/* Start the Option Bytes programming process */
	if (HAL_FLASH_OB_Launch() != HAL_OK) {
		/*
		 Error occurred while reloading option bytes configuration.
		 User can add here some code to deal with this error.
		 To know the code error, user can call function 'HAL_FLASH_GetError()'
		 */
		/* Infinite loop */
		while (1) {
 
		}
	}
 
	/* Prevent Access to option bytes sector */
	HAL_FLASH_OB_Lock();
 
	/* Disable the Flash option control register access (recommended to protect
	 the option Bytes against possible unwanted operations) */
	HAL_FLASH_Lock();
 
}

And referring to STM32L496 Dual Boot examples, i have also modified the "System Init" function called from the startup file. Below is the code snippet:

 void SystemInit(void) {
 
 
 	/* FPU settings ------------------------------------------------------------*/
 #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
 	SCB->CPACR |= ((3UL << 10 * 2) | (3UL << 11 * 2)); /* set CP10 and CP11 Full Access */
 #endif
 	/* Reset the RCC clock configuration to the default reset state ------------*/
 	/* Set MSION bit */
 	RCC->CR |= RCC_CR_MSION;
 
 	/* Reset CFGR register */
 	RCC->CFGR = 0x00000000;
 
 	/* Reset HSEON, CSSON , HSION, and PLLON bits */
 	RCC->CR &= (uint32_t) 0xEAF6FFFF;
 
 	/* Reset PLLCFGR register */
 	RCC->PLLCFGR = 0x00001000;
 
 	/* Reset HSEBYP bit */
 	RCC->CR &= (uint32_t) 0xFFFBFFFF;
 
 	/* Disable all interrupts */
 	RCC->CIER = 0x00000000;
 
 	/* Configure the Vector Table location add offset address ------------------*/
 #ifdef VECT_TAB_SRAM
 SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */
 #else
 	SCB->VTOR = FLASH_BASE ; /* Vector Table Relocation in Internal FLASH */
 #endif
 
 }

So can anyone please have a look at this issue what could be the issue here ? Because the exact same program works for the STM32L496 but not for STM32L4A6.

This topic has been closed for replies.
FBLBest answer
ST Technical Moderator
April 24, 2023

@NK.13omalan​ Thank you for the reference, indeed same SystemInit.

Attached the project.

Hope this helps!

To give better visibility on the answered topics, please click on "Best answer" on the reply which solved your issue or answered your question.Best regards,FBL

13 replies

ST Technical Moderator
April 17, 2023

Hello @NK.13omalan​, 

I have reproduced the issue. I will check internally and get back to you soon.

Thank you for your feedback.

To give better visibility on the answered topics, please click on "Best answer" on the reply which solved your issue or answered your question.Best regards,FBL
ST Technical Moderator
April 18, 2023

Hello @NK.13omalan​,

I came up with some news related to Dual Bank Boot on STM32L4A6. Could you please check defined symbols. Make sure STM32L4A6xx is used.

To give better visibility on the answered topics, please click on "Best answer" on the reply which solved your issue or answered your question.Best regards,FBL
Nikhil D&K
Associate III
April 18, 2023

Hello, STM32L4A6xx is already defined in preprocessor as the project is generated using Cube IDE with STM32L4A6ZG selected as target board.

ST Technical Moderator
April 18, 2023

Could you check the status of the User Configuration Option Bytes? Boot0 can you take it from PH3/Boot0?

To give better visibility on the answered topics, please click on "Best answer" on the reply which solved your issue or answered your question.Best regards,FBL