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
Posted on October 26, 2017 at 18:37

It may be but typically it's not and it's left to the linker.

I don't know your toolchain - you should know how the vector table is filled, and if there is any other code which would modify the stack pointer after the reset SP/PC fetch.

JW

Posted on October 26, 2017 at 18:48

No, with GNU/GCC it is frequently in the .LD linker script, and wrong.

Post the entire .LD, debugging through a keyhole in undesirable.

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 27, 2017 at 07:40

The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6u5&d=%2Fa%2F0X0000000bxh%2F9g0OCrDlMj6KkfmAtTujdbLTNYDagx3cb0Ngode3FDY&asPdf=false
Posted on October 27, 2017 at 11:58

Okay so this is the usual GNU setup.

In the startup code the vector table is defined, and from there the processor picks SP upon reset:

g_pfnVectors:

.word _estack

It's also (here unnecessarily) reloaded as the very first thing in the startup:

Reset_Handler:

ldr r0, =_estack

mov sp, r0 /* set stack pointer */

As you see it's not defined anywhere in the startup code so it's an external symbol.

And, sure enough, it's defined in both linker scripts:

_estack = 0x20002000; /* end of RAM */

so the word at 0x20001FFC gets overwritten by the first thing which goes onto the stack.

JW

Posted on October 27, 2017 at 12:03

So, what approach would be the best way to establish some space that would not be overwritten at the startup? Shrink stack by 4 bytes ? 

Posted on October 27, 2017 at 12:54

Shrink? The stack goes down as far as the bottom of the RAM. _Min_Stack_Size is just a placeholder so that the linker warns if variables would reach too far - but that number is just randomly chosen by whomever who wrote that linker script - ultimately it's your (the programmer's) responsibility to find out how much stack is really needed.  There's no enforcement of it in hardware/runtime.

So just change _estack, that's all.

JW