AnsweredAssumed Answered

Problem with stack overflow detection magic pattern

Question asked by Tom on Jun 10, 2013
Goog morning everybody,
I am programming an application on the STM32F100C8T6 which is using the STL - safety lib. As part of this library there is a stack overflow implemented which uses an array of four variables with a magic pattern to detect changes of the data in this area. This array is defined in the "stm32f10x_STLclassBvar.h" as :

  /* Magic pattern for Stack overflow in this array */
  EXTERN __IO uint32_t StackOverFlowPtrn[]   __attribute__((section("STACK_BOTTOM"), zero_init));

The map file shows this:
    STACK                                    0x200001c0   Section      512  startup_stm32f10x_md.o(STACK)
    STACK_BOTTOM                             0x200003c0   Section        4  stm32f10x_stlstartup.o(STACK_BOTTOM)
Because the stack is filled from higher addresses to lower addresses is seems that the magic pattern is located on the "stack empty" end of the stack. This is where the trouble starts:
My software consists of two parts, a bootloader which manages updates of the main application and the main application. The bootloader reads the stack address from the first address of the application and sets the MSP, and reads the address of the main() from the second address of the programm code. When the bootloader passes the program flow to the application there is a jump to the main() which causes the controller to push data (0x00000000) to the very first word of the stack which corrupts the magic pattern. Changing the address which is passed to the MSP has no influence to this behavior. I use the KEIL µVision v4.70.
How can I change the location of the "STACK_BOTTOM" variables to be located at the "full" side of the stack, so it is not corrupted on startup?