cancel
Showing results for 
Search instead for 
Did you mean: 

Share variable between firmware and bootloader STM32WLE5JC

SBaro.11
Associate III

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 ?

1 ACCEPTED SOLUTION

Accepted Solutions

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;

 

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

4 REPLIES 4
TDK
Guru

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.

If you feel a post has answered your question, please click "Accept as Solution".

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 ?

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;

 

If you feel a post has answered your question, please click "Accept as Solution".

Ah yep nice solution maybe more simple no changes needed in linker just set 64k to 63k for my RAM region. Thanks @TDK