cancel
Showing results for 
Search instead for 
Did you mean: 

can i share a variable between custom bootloader and user application?

moustaid jamal
Associate II
Posted on March 08, 2017 at 15:51

Hi

I have a custom bootloader that I flash to the first sector (0x8000000)  and when it receives a new program it loads it to 0x8003000. I can jumps to the user application,and also

jumps

 from user application to the bootloader.

I

want to know if there

 are any methods to tell the custom boot

loader

, there are not a simple start-up, but it's a jump from user application.

can i share a variable between bootloader and user application? 

Thank you in advance !

#custom-bootloader #stm32f1
6 REPLIES 6
Posted on March 08, 2017 at 16:33

You'd need to carve out an area of RAM, which you app doesn't clear, where you can place variables or a structure, to communicate data between them

typedef struct _FOO {

 int a;

 int b;

} FOO;

FOO *foo = (FOO *)0x2000FF00; // some upper RAM area for your part, pick something appropriate

foo->a = 1234;

foo->b = 4321;

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on March 08, 2017 at 17:05

should i do that in my custom bootloader?

typedef struct _FOO {

 int a;

 int b;

} FOO;

FOO *foo = (FOO *)0x2000FF00;

if (foo->a == 1234) // thats mean i was in application 

{

   //do ......

}

Thank you

Posted on March 08, 2017 at 17:11

The CPU doesn't inherently clear RAM over a reset, so the technique is viable either way. The example assumes your part has 64KB of SRAM, and you hide 256 bytes from the linker so you can pass parameters. This could be a command line, or whatever.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on March 08, 2017 at 18:14

How can i choose the adresse 

0x2000FF00, should be before the bootloader or in application memory?

thnak's

Posted on March 08, 2017 at 19:18

It will depend on the specific part you are using. The boot loader and application share the same RAM resources, the linker settings typically assume they can use all available memory.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on March 09, 2017 at 12:05

I chosed 0x200001DC as an adresse for FOO, but when i jump from user application to bootloader 'foo->a' and 'foo->b' equals zero, so  foo->x change when i jump. any suggestion  

thank's