Skip to main content
Explorer II
May 7, 2025
Solved

STM32L4P5xx system bootloader: is RAM3 valid SRAM for the stack pointer?

  • May 7, 2025
  • 3 replies
  • 417 views

Does the system memory bootloader for the STM32L4P5xx consider RAM3 as valid SRAM for the stack pointer?

After programming bank 2, and then setting BFB2, The device will not boot into bank 2.  The linker has the top of the stack at RAM3.  The value written to both 0x8000000 (bank 1) and 0x8040000 (bank 2) is 0x20050000.  I want to make sure this is correct.  By the way, this is the 512K part STM32L4P5xE.  The other relevant options bytes are set as follows: nBOOT1=1, nSWBOOT0=0, nBOOT0=1 (BOOT0=0).  When I clear BFB2 I can boot.  I have compared the flash memory from 0x08000000-Length with 0x8040000-Length, and they both match.

    This topic has been closed for replies.
    Best answer by dcooperch

    I think I found my problem.  The bootloader is executing my application, but since the system memory bootloader is jumping to my application, I need to explicitly set 

    SCB->VTOR = 0x08000000; // Point to the actual flash location of your vector table

    This should be documented somewhere, probably in AN2606.  I found this clue here Re: Dual bank booting problem 

    3 replies

    Super User
    May 7, 2025

    Anything accessible to the CPU can be used as the stack pointer. Using SRAM3 at 0x20050000 is valid.

    Is your program compiled to run correctly when it's at 0x08040000? Code is typically position dependent. You would need to modify the linker file to run it at a different position.

    See the  FB_MODE field in the SYSCFG_MEMRMP register for actually remapping bank 2 as if it were bank 1.

    dcooperchAuthor
    Explorer II
    May 7, 2025

    When I mean valid, I mean valid to the system bootloader, not the CPU.  Referring to AN2606 (73.2 Bootloader selection), the bootloader has to determine if the value is a valid SRAM address in order to boot from bank 2.  I do read the FB_MODE to determine what bank I am currently running, but I can't tell until my code in bank 2 is actually executed.

    dcooperchAuthorAnswer
    Explorer II
    May 8, 2025

    I think I found my problem.  The bootloader is executing my application, but since the system memory bootloader is jumping to my application, I need to explicitly set 

    SCB->VTOR = 0x08000000; // Point to the actual flash location of your vector table

    This should be documented somewhere, probably in AN2606.  I found this clue here Re: Dual bank booting problem