2017-10-19 01:46 AM
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.2017-10-26 11:37 AM
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
2017-10-26 11:48 AM
No, with GNU/GCC it is frequently in the .LD linker script, and wrong.
Post the entire .LD, debugging through a keyhole in undesirable.
2017-10-27 12:40 AM
2017-10-27 02:58 AM
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 _estackIt'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
2017-10-27 05:03 AM
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 ?
2017-10-27 05:54 AM
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