Skip to main content
Explorer
October 6, 2023
Solved

Share variable between firmware and bootloader STM32WLE5JC

  • October 6, 2023
  • 1 reply
  • 2642 views

Hi all,

I'm working on STM32WLE5JC, I've develop very simple bootloader starting at flash memory at 0x08000000 for 20K. My booloader is simple just blink a user led and jump to the firmware.

Right now I'd like to have the possibility to jump to the bootloader from my appplication, I've read this very usefull article I've understand what I have to do, instead of jump to 0x1FFF000 jump to 0x0800000 (my flash memory where my own bootloader is saved).

But my question is, is it possible when I jump to the booloader from my application to set a variable somewhere and have access to it from my bootloader ? Maybe use RAM, because if I jump to booloader from application, my board will always power up so RAM content will be present, am I right ?

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

    That looks roughly right, but the test would be to try it. I don't know the linker well enough to know if it'll work just by reading.

    An alternative is to explicitly specify the memory address they're at. This gets around having to create a new linker section, you would only need to reduce the length of the current RAM section.

    struct MySettings {
     uint8_t x;
     uint32_t y;
    }
    
    MySettings* settingsPtr = (MySettings*)(0x2000FC00);
    settingsPtr->x = 42;

     

    1 reply

    Super User
    October 6, 2023

    If you carve out a section of RAM and put variables there, they can be accessed by both programs. RAM isn't erased when jumping between bootloader and program.

    Typically this is done by making the RAM section a little smaller in the linker script and explicitly placing variables at the end of the RAM section.

    SBaro.11Author
    Explorer
    October 6, 2023

    Ok nice thanks @TDK . So if my RAM start at 0x20000000 for 64K if I want to reserve 1K for me at the end of the ram region in my linker

     

    .myDataBlockRAM 0x2000FC00 (NOLOAD):
    {
     KEEP(*(.myDataSectionRAM))
    } > RAM

     

    And in my application

     

    uint8_t __attribute__((section(".myDataSectionRAM))) example = 0;

     

    Am I right ?

    TDKAnswer
    Super User
    October 6, 2023

    That looks roughly right, but the test would be to try it. I don't know the linker well enough to know if it'll work just by reading.

    An alternative is to explicitly specify the memory address they're at. This gets around having to create a new linker section, you would only need to reduce the length of the current RAM section.

    struct MySettings {
     uint8_t x;
     uint32_t y;
    }
    
    MySettings* settingsPtr = (MySettings*)(0x2000FC00);
    settingsPtr->x = 42;