Skip to main content
Senior
September 5, 2024
Solved

How to Use a Variable in SRAM to Communicate between Bootloader and Application

  • September 5, 2024
  • 2 replies
  • 2911 views

Hi,

I have a bootloader for my application, at the moment they exchange their working status by flash write. I think a better way is to declare a variable in RAM with the same address in both bootloader and application. Someone mentioned, in a post, that the linker script could be used for this, but didn't give an example.

Anybody could do me a favour and show me an example ? Thanks.

Best answer by mƎALLEm

Set the memory origin at 0x20000004 and your common variable at 0x20000000.

 

_estack = ORIGIN(RAM) + LENGTH(RAM); /* end of "RAM" Ram type memory */

/* Memories definition */
MEMORY
{
...
RAM (xrw) : ORIGIN = 0x20000004, LENGTH = 49152 /* 48K - 4 bytes*/
...
}

 

#define COMMON_VAR_ADDRESS 0x20000000 /* Define a common RAM address */

uint32_t* common_var = (uint32_t*)COMMON_VAR_ADDRESS; /* Declare a pointer at that address */
*common_var = y; /* access to that address */

2 replies

mƎALLEm
Technical Moderator
September 5, 2024

@Chao wrote:

Someone mentioned, in a post, that the linker script could be used for this, but didn't give an example.

Anybody could do me a favour and show me an example ? Thanks.


Using __attribute . See this link: https://www.openstm32.org/Using%2BCCM%2BMemory

"To give better visibility on the answered topics, please click on ""Accept as Solution"" on the reply which solved your issue or answered your question."
MM..1
Chief III
September 5, 2024

Maybe we require info how working status you mean... And most simple method to share is move start RAM +somethink for example 0x20000020 and use direct pointers to 0-1F arrea. 

mƎALLEm
Technical Moderator
September 5, 2024

Yes @MM..1 it could be also a solution.

 

 

#define COMMON_VAR_ADDRESS 0x2000XXXX /* Define a common RAM address */

uint32_t* common_var = (uint32_t*)COMMON_VAR_ADDRESS; /* Declare a pointer at that address */
*common_var = y; /* access to that address */

 

"To give better visibility on the answered topics, please click on ""Accept as Solution"" on the reply which solved your issue or answered your question."
ChaoAuthor
Senior
September 7, 2024

Many thanks to @mƎALLEm  and @MM..1 .

Is the way given in the example safe? How could we be sure that the variable  value would not be modified by other part of the bootloader code and app code? The both code are written in C++.