Skip to main content
ron23
Associate
March 24, 2018
Solved

stm32L496ZG dual boot

  • March 24, 2018
  • 2 replies
  • 782 views
Posted on March 24, 2018 at 22:22

hi

im trying to implement dual boot using BFB2 bank switching on this chip, and after the code is burned in the second bank (ox80800000), it doesnt boot.

i single stepped through the bootloader code, and it seems that the bootloader checks the first bank address to be between 0x20000000 and 0x20040000, which fails because the initial SP is located near the end of SRAM which is at 0x20050000.for this chip.

could it be a bug in the bootloader code, or something im missing ? 

alternatively, how can i locate __init_sp in some lower address ?

    This topic has been closed for replies.
    Best answer by Tesla DeLorean
    Posted on March 25, 2018 at 00:10

    Just write a lower value in the first vector and load the SP with __init_sp in Reset_Handler

    For GNU/GCC the stack is frequently defined in the .LD linker script.

    ...

    ; Vector Table Mapped to Address 0 at Reset

                    AREA    RESET, DATA, READONLY

                    EXPORT  __Vectors

                    EXPORT  __Vectors_End

                    EXPORT  __Vectors_Size

    __Vectors       DCD     0x20002000               ; Top of Stack - Nominal RAM address, set to __initial_sp later

                    DCD     Reset_Handler              ; Reset Handler

                    DCD     NMI_Handler                ; NMI Handler

                    DCD     HardFault_Handler          ; Hard Fault Handler

                    DCD     MemManage_Handler          ; MPU Fault Handler

    ...

    ; Reset handler

    Reset_Handler    PROC

                     EXPORT  Reset_Handler             [WEAK]

            IMPORT  SystemInit

            IMPORT  __main

                     LDR     SP,=__initial_sp ;; Set SP, for Keil also done in __main as I recall

                     LDR     R0, =SystemInit

                     BLX     R0

                     LDR     R0, =__main

                     BX      R0

                     ENDP

    2 replies

    Tesla DeLorean
    Tesla DeLoreanBest answer
    Guru
    March 24, 2018
    Posted on March 25, 2018 at 00:10

    Just write a lower value in the first vector and load the SP with __init_sp in Reset_Handler

    For GNU/GCC the stack is frequently defined in the .LD linker script.

    ...

    ; Vector Table Mapped to Address 0 at Reset

                    AREA    RESET, DATA, READONLY

                    EXPORT  __Vectors

                    EXPORT  __Vectors_End

                    EXPORT  __Vectors_Size

    __Vectors       DCD     0x20002000               ; Top of Stack - Nominal RAM address, set to __initial_sp later

                    DCD     Reset_Handler              ; Reset Handler

                    DCD     NMI_Handler                ; NMI Handler

                    DCD     HardFault_Handler          ; Hard Fault Handler

                    DCD     MemManage_Handler          ; MPU Fault Handler

    ...

    ; Reset handler

    Reset_Handler    PROC

                     EXPORT  Reset_Handler             [WEAK]

            IMPORT  SystemInit

            IMPORT  __main

                     LDR     SP,=__initial_sp ;; Set SP, for Keil also done in __main as I recall

                     LDR     R0, =SystemInit

                     BLX     R0

                     LDR     R0, =__main

                     BX      R0

                     ENDP
    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    ron23
    ron23Author
    Associate
    March 26, 2018
    Posted on March 26, 2018 at 08:26

    thanks, worked perfecly