Stack Pointer Not Initialized in startup_mmxrt1064.c Module

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Stack Pointer Not Initialized in startup_mmxrt1064.c Module

656 Views
mjpovi
Contributor III

Hi,

My question is, how should the stack pointer be initialized to my application's starting value as defined by the vector table?  Isn't ResetISR supposed to handle this ?

I noticed that the stack pointer is not initialized by the startup_mimxrt1064.c module in ResetISR(). However, the Reset_Handler in startup_MIMXRT1064.S sets the stack pointer using the __isr_vector table.  

If startup_mimxrt1064.c is used as the startup function, how is the stack pointer supposed to be initialized to the application's working value as defined by the vector table?  It seems that the application must initialize the stack pointer or the startup_mimxrt1064.c has to be modified to initialize the stack pointer.   SystemInitHook() cannot be used easily to set the stack pointer because it itself has its either the CPU context and/or return address of ResetISR on the stack when it is called from ResetISR. 

This is how my application's stack is defined in the linker load file, and ResetISR is entered with the stack pointer set to some other value, presumably the bootloader's

SRAM_DTC (rwx) : ORIGIN = 0x20000000, LENGTH = 0x20000 /* 128K bytes (alias RAM) */

/* Reserve and place Stack within memory map */
_StackSize = 0xa000;
.stack : ALIGN(4)
{
_vStackBase = .;
. += _StackSize;
. = ALIGN(4);
_vStackTop = .;
} > SRAM_DTC
/* DATA section for SRAM_DTC */

PROVIDE(__StackTop = _vStackBase)

.stack 0x0000000020000000 0xa000
0x0000000020000000 _vStackBase = .
0x000000002000a000 . = (. + _StackSize)
*fill* 0x0000000020000000 0xa000
0x000000002000a000 . = ALIGN (0x4)
0x000000002000a000 _vStackTop = .

0 Kudos
3 Replies

647 Views
jeremyzhou
NXP Employee
NXP Employee

Hi,
Thank you for your interest in NXP Semiconductor products and for the opportunity to serve you.
1) How should the stack pointer be initialized to my application's starting value as defined by the vector table? Isn't ResetISR supposed to handle this?
-- Once power-up, the RT MCU will execute the ROM code prior to jumping to the application actually, so the PS and PC registers should be set in the ROM code.
Have a great day,
TIC

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos

641 Views
mjpovi
Contributor III

Hi, and thank-you for the quick response to my question.  Will the ROM code set the SP to the value as defined by the first entry of the application's own vector table ??

0 Kudos

639 Views
jeremyzhou
NXP Employee
NXP Employee

Hi,
Thanks for your reply.
1) Will the ROM code set the SP to the value as defined by the first entry of the application's own vector table ??
-- Yes, or it can't implement jump operation successfully.
Have a great day,
TIC

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos