cancel
Showing results for 
Search instead for 
Did you mean: 

Dual bank swap not working in STM32L4A6 but working in STM32L496

Nikhil D&K
Senior

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.

1 ACCEPTED SOLUTION

Accepted Solutions

@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 Accept as Solution on the reply which solved your issue or answered your question.

View solution in original post

13 REPLIES 13
FBL
ST Employee

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 Accept as Solution on the reply which solved your issue or answered your question.

FBL
ST Employee

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 Accept as Solution on the reply which solved your issue or answered your question.

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

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 Accept as Solution on the reply which solved your issue or answered your question.

When i read the nBOOT0 value of User configuration using ST Programmer it is enabled.

Before starting NFC DFU the status of BFB2 byte is cleared and nBOOT0 is set in User Configuration Register. After writing second bank and performing swap the the BFB2 byte get set in User Configuration Register but the firmware gets stuck.

Hello again @NK.13omalan​ 

To select the boot in flash memory, you should use the option bytes for setting the nSWBoot0 option bit to 0, the nBOOT0 option bit to 1, and the BFB2 option bit to 1. Otherwise, it won't work as described in Errata section 2.2.1 Dual-bank boot not working when the boot in flash memory is selected by BOOT0 pin.

If still having issue, it might be related to the binary generated with CubeIDE.

Thank you for your feedback.

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.

Hello @F.Belaid​ ,

In user configuration, nSWBoot0 option bit is set to 0, the nBOOT0 option bit to 1 using STM progrommer utility. Using BFB2 option bit i am just swapping the banks after successfully writing to flash.

After calling HAL_FLASH_OB_Launch function the controller hangs and isn't recovered by even pressing hardware reset button.

"it might be related to the binary generated with CubeIDE."

I don't think this would be the reason because the binary generated from project target based on STM32L496 works well on STM32L496 and STM32L4A6.

@NK.13omalan​ Hi again,

Note that HAL_FLASH_OB_Launch function triggers a reset,

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.