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:
- Firmware 1: NFC DFU with STM32L496ZG
- 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.
