cancel
Showing results for 
Search instead for 
Did you mean: 

How can a bootloader and application share RAM-variables?

arnold_w
Senior
Posted on June 18, 2015 at 14:51

I am working with the

Discovery development board

STM32F407 microcontroller and building using Eclipse/GNU. My project has a bootloader and an application and I would like to have a variable in RAM that both the bootloader and the application can access and pass information to each other. I tried to tell the linker that the RAM is smaller than it actually is and then store my variable in the ''outside'' area:

MEMORY
{
/* Pretend that the RAM is only 127 kByte even though in reality it is 128 kByte */
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 127K
CCMRAM (xrw) : ORIGIN = 0x10000000, LENGTH = 64K
.
.
.
}

// Store a variable in the RAM area the linker doesn't think exist
*((uint32_t*) (127 * 1024 + 16)) = 0xAABBCCDD;

However, it doesn't work, I seem to always read 0xFFFFFFFF, even if I store it in bootloader mode and immediately read it in bootloader mode again. Can anybody please help me?
2 REPLIES 2
arnold_w
Senior
Posted on June 18, 2015 at 14:59

I figured it out, I was using the wrong address (need an offset of0x20000000 to get to the RAM area):

*((uint32_t*) (0x20000000 + 127 * 1024 + 16)) = 0xAABBCCDD;

Posted on June 18, 2015 at 15:03

The RAM doesn't have a zero basis, it starts at 0x20000000

Consider using a structure, and casting a pointer at that.

typedef struct _FOO {

  int bar;

//...

} FOO;

FOO *foo = (FOO *)0x2001FC00; // 0x20000000 + 127 * 1024

foo->bar = 123456;

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..