2025-08-04 4:02 AM
Hello,
I'm having an issue with the STM32L4A6(1Mb) and the dual-bank.
First of all, I tried with the NUCLEO-L476 and a simple blink led. It worked fine.
Now, my project is based on a STM32L4A6, but the firmware doesn't start in BANK2.
For simplicity, I did the same program blink led as for the STM32L476
This is what I implemented in SystemInit():
VECT_TAB_OFFSET is 0x80000
void SystemInit(void)
{
#if defined(USER_VECT_TAB_ADDRESS)
/* Configure the Vector Table location -------------------------------------*/
FLASH_OBProgramInitTypeDef FLASH_OBProgramInit = {0};
//Read all options bits
HAL_FLASHEx_OBGetConfig(&FLASH_OBProgramInit);
//Check the BFB2 bit
if (FLASH_OBProgramInit.USERConfig & FLASH_OPTR_BFB2)
SCB->VTOR = VECT_TAB_BASE_ADDRESS | VECT_TAB_OFFSET;
else
SCB->VTOR = VECT_TAB_BASE_ADDRESS;
#endif
/* FPU settings ------------------------------------------------------------*/
#if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
SCB->CPACR |= ((3UL << 20U)|(3UL << 22U)); /* set CP10 and CP11 Full Access */
#endif
}
I flashed the same code at 0x8000000 and at 0x8080000(half memory).
I did the workaround as mentionned in the errata sheet:
But nothing to do, the program never starts in BANK2.
May be an idea?
Pierre
Solved! Go to Solution.
2025-08-17 12:46 PM
The problem comes from the linker script:
The linker script from example for L496 is correct, but the linker script generated by STM32CubeIDE is wrong:
MEMORY
{
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 256K/*320K*/
RAM2 (xrw) : ORIGIN = 0x10000000, LENGTH = 64K
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 512K
}
The length of RAM must be 256K and not 320K!
320K is the total of RAM and RAM2
Pierre
2025-08-06 2:30 AM - edited 2025-08-06 2:31 AM
Hello @PCu1,
Did you set the PH3-Boot0 pin?
Check if the BOOT pin is connected to GND?
PH3 may be used as boot pin (BOOT0) or as a GPIO. Depending on the nSWBOOT0 bit in the user option byte, it switches from the input mode to the analog input mode:
• After the option byte loading phase if nSWBOOT0 = 1.
• After reset if nSWBOOT0 = 0.
You can test and check if it works with this project: STM32CubeL4/Projects/NUCLEO-L496ZG/Examples/FLASH/FLASH_DualBoot at master · STMicroelectronics/STM32CubeL4 · GitHub
2025-08-06 3:34 AM - edited 2025-08-06 3:35 AM
Thank you @Imen.D for your support.
On my project, the PH3 pin is left floating. This pin is free and I could test by pulling to GND.
But in the errata sheet and if I understand well, booting with pin PH3 doesn't work:
Dual-bank boot not working when the boot in flash memory is selected by BOOT0 pin
Description
When the nSWBoot0 option bit is set and the BOOT0 pin level is low, the dual.bank boot does not work (BFB2
option bit = 1).
The user code is only executed when BANK 0 is valid.
Workaround
Do not rely on the BOOT0 pin to select the boot in flash memory. Instead, use the option bytes for that purpose,
setting the nSWBoot0 option bit to 0, the nBOOT0 option bit to 1, and the BFB2 option bit to 1. This setting allows
the correct check of the address 0 of the two memory banks, in order to execute from the correct one.
Does it mean that in all cases the PH3 pin must be set at 0?
I don't own NUCLEO-L496ZG but I have the P-L496G-CELL02, the same example is given.
In the example with NUCLEO-L496ZG, there is no change of VTOR in the code, regardless of the BANK used.
With the previous test I did with the NUCLEO-L476, changing VTOR was mandatory...
2025-08-06 7:30 AM
A clarification regarding pin PH3: it is not left floating on my board as mentioned, this pin is connected to GND via a resistor!
I performed the "FLASH_DualBoot" test with the P-L496G-CELL02 and it worked fine.
However, the same test with my own board on L4A6 (with a few modifications for the LED and SW) does not work. The processor never boots in BANK2.
It seems that the issue only affects on L4A6...
2025-08-17 12:46 PM
The problem comes from the linker script:
The linker script from example for L496 is correct, but the linker script generated by STM32CubeIDE is wrong:
MEMORY
{
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 256K/*320K*/
RAM2 (xrw) : ORIGIN = 0x10000000, LENGTH = 64K
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 512K
}
The length of RAM must be 256K and not 320K!
320K is the total of RAM and RAM2
Pierre