cancel
Showing results for 
Search instead for 
Did you mean: 

Shared memory between BL and Main application

Martynas Mickus
Associate II
Posted on October 19, 2017 at 10:46

I am working on the project with STM32F030R8T6. So far I have bootloader and main application with memory space allocated. My problem is that currently I am jumping between main and bootleader using address of reset handler and I need to somehow let BL know if it is startup or jump from main. I have been trying to allocate 4 bytes to store this information in memory and access using the address, but it seems that value at the address get reset after jump. My question is — what would be the best approach to have some flag between BL and Main application ?

Note: this post was migrated and contained many threaded conversations, some content may be missing.
15 REPLIES 15
AvaTar
Lead
Posted on October 19, 2017 at 12:08

I have been trying to allocate 4 bytes to store this information in memory and access using the address, but it seems that value at the address get reset after jump.

Most probably in the startup code, that runs from reset vector to main.

You can modify the startup (assembler code) or the linker map t not initialize certain areas, but that depends on the toolchain.

I guess you speak about a custom BL, not the system BL in ROM.

Posted on October 19, 2017 at 12:25

Shrink the RAM size slightly in the linker script or scatter file so you can use the last 4 or 16 bytes, or whatever you need to pass state information between the two.

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

Ok, I have left last 4 bytes of RAM out of both linker scripts, but it seems that this value still get reset when jumping. There is no power cycle reset, so I am not sure why this behavior exists.

In linker script I just do 

RAM (xrw)       : ORIGIN = 0x20000000, LENGTH =  8K - 4 

And then I use address

0x20000000 + 8K - 4 to store 32 bit int, it seems I am successful but after the jump it gets reset even if this 4 byte area is not allocated in any linker script and should not be touched by reset handlers.

Posted on October 25, 2017 at 09:42

Debugging ?

I would set a data breakpoint at your reserved location.

Depending on your IDE, single-step might only be possible in instruction/assembler mode, since the application is started the BL.

Posted on October 25, 2017 at 09:55

Look at the startup code you are using, from where does it acquire the constants used for the clear loop.

JW

Posted on October 25, 2017 at 14:31

Don't know how you access, but the Linker and startup code shouldn't mess with things. Check where GNU is placing the stack. If 0x20002000 then move to 0x20001FFC, it will then predecrement that before use.

Then

uint32_t *myvar = (uint32_t *)0x20001FFC;

printf('%08X\n', *myvar);

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on October 26, 2017 at 13:54

Ok, here is my linker scripts..

BL: 

{

FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 20K /* 64K total, 20k boot, 44k main program */

RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 8K - 4

}

Main application: 

{

FLASH (rx) : ORIGIN = (0x08000000+20K), LENGTH = (64K-20K-4)

VTRAM (xrw) : ORIGIN = 0x20000000, LENGTH = 0xc0 /* First part of RAM is reserved to the vector table */

RAM (xrw) : ORIGIN = 0x200000C0, LENGTH = 8K - 0xc0 - 4

}

Also, in mu linker scripts I have values set: 

__flags = 0x20000000 + 8K - 4;

From source code: 

&sharpdefine

FLAGS

((

uint32_t

)

&

__flags)

extern

uint32_t

__flags;

dbg_printf

(

'Flag addr: %x

\n

'

, FLAGS);

volatile

int32_t

*

ptr

=

(

int32_t

*

) FLAGS;

dbg_printf

(

'flags: %d

\n

'

,

*

ptr);

*

ptr

=

1

;

volatile

int32_t

*

ptr2

=

(

int32_t

*

) FLAGS;

dbg_printf

(

'flags2: %d

\n

'

,

*

ptr2);

Flag addr prints the address you said: 

0x20001FFC

flags print some random value whitch is alwasy the same on startup.

flags2 print 1

Now when I jump, I read from very same address and it is again some random value which is very similar to random value from before but different. 

Posted on October 26, 2017 at 14:08

I repeat,

Look at the startup code

As Clive said, that includes stack definition.

JW

Posted on October 26, 2017 at 14:20

Isn't stack defined at the compile time ?