Hi,
I'm using MPC5744P MCU and S32DS IDE.
I need to access the range of allocated Stack memory after compilation.
My linker file includes the keywords:
.stack (NOLOAD) : ALIGN(16)
{
_stack_end = . ;
. += __STACK_SIZE ;
_stack_addr = . ;
__SP_INIT = . ;
. += 4;
} > m_data
How can I access _stack_end and _stack_addr in my C source code?
I will be using these addresses to monitor stack overflow/underflow during runtime.
Thanks in advance.
Julius
已解决! 转到解答。
Hi Julius,
see Accessing GNU Linker Script Symbols from C/C++ | MCU on Eclipse
I hope this helps,
Erich
Hi Julius,
see Accessing GNU Linker Script Symbols from C/C++ | MCU on Eclipse
I hope this helps,
Erich
Hi Erich,
Thank you very much. This is very helpful.
By the way, I'm using a 32-bit MPC5744P MCU.
Which should be the correct type of extern?
extern unsigned int _stack_end?
Or
extern unsigned long _stack_end?
Thanks again!
Julius
Hi Julius,
the type really does not matter, because the linker does not know about types. All what the linker knows and provides you is an address (or to the essence a number). So you can use whatever makes sense in your application.
Because your stack entries are 32bit, you probably want to use uint32_t as you don't know how many bits int or long can have.
I hope this helps,
Erich