AnsweredAssumed Answered

Stack pointer in wrong memory

Question asked by Gary Metalle on Jan 9, 2019
Latest reply on Jan 17, 2019 by Gary Metalle

Hi

 

I'm having trouble trying to get the stack pointer to be where I want it using MCUExpresso with the imxrt1052.

 

I'm using version 10.2.1 of the IDE and version 2.5.0 of the EVKB-IMXRT1050 SDK.

 

My memory is configured thus which is pretty standard:

 

memory layout

 

And I've configured the linker to link the application to RAM and to set the heap and stack to SDRAM as shown below:

 

Linker settings

 

However when I set a breakpoint in the ResetISR function the stack pointer (r13) is always in the internal SRAM_OC area:

 

registers showing sp in SRAM_OC area

 

The linker map file shows exactly what I expect it to show as shown here:

 

/* Reserve and place Heap within memory map */
_HeapSize = 0x800000;
.heap : ALIGN(4)
{
_pvHeapStart = .;
. += _HeapSize;
. = ALIGN(4);
_pvHeapLimit = .;
} > BOARD_SDRAM

_StackSize = 0x200000;
/* Reserve space in memory for Stack */
.heap2stackfill :
{
. += _StackSize;
} > BOARD_SDRAM
/* Locate actual Stack in memory map */
.stack ORIGIN(BOARD_SDRAM) + LENGTH(BOARD_SDRAM) - _StackSize - 0: ALIGN(4)
{
_vStackBase = .;
. = ALIGN(4);
_vStackTop = . + _StackSize;
} > BOARD_SDRAM

 

I've tried cleaning the build and also creating a small application with no frills straight from the SDK and that doesn't help. I've also tried removing the BOARD_FLASH memory and also the internal SRAMs so that I only have SDRAM and that makes no difference.

 

If you look carefully at the code snippet in the last pic you can see where I've commented out manually setting the sp using the _vStackTop value set by the linker. This kinda does work in that the stack pointer gets set properly, but I find that the application dies after a while due to stack corruption of a C++ object that was created on the stack within main.

 

Any ideas?

Outcomes