cancel
Showing results for 
Search instead for 
Did you mean: 

Dual bank swap not working in STM32L4A6 but working in STM32L496

Nikhil D&K
Associate II

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.

13 REPLIES 13

Hello,

I know that HAL_FLASH_OB_Launch function trigger the reset. But on reset the controller get's stuck somehwere, even on the hard reset it doesn't boot up.

Hello @F.Belaid​ ,

Can you please provide me a project where a dual bank swap is working on STM32L4A6, so that i can check if there is any issue in the System Init function called from startup file. Currently i am using the System Init function similar to the one given in dual bank example given in STM32L496 repository.

For reference i have also provided the "System Init" function defintion in my main question above.

@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.

 

Hello @FBL 

Hope you are doing well. I am once again stuck with the dual bank issue.

 

In our product we have changed our MCU to  STM32L496VGTX. Currently i was able to download new firmware into the bank 2 but after swapping banks and reset the new firmware is not getting loaded.  Used the system init and swap bank function provided by you before.  

I have tried to implement the same issue in a standalone project which i have attached for your reference. Where demo binary example (Red led blinking f.w)  is programmed at address 0x08080000 (bank 1) using STLink Utility. 

 

 

Now using STM32Cube IDE i am running code on bank 0, with Blue led blinking. On button press the banks will swap and reset will take place. But for some reason i am unable to switch to new firmware. 

 

Can you please look into this issue. I have attached  the project file containing all the code needed for bank swap.