We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Is there a way to check the stack size during runtime?
I use a Freescale K10 MCU.
Do you mean checking it from inside the running program, or from the debugger? If you run an OS, the debugger will be able to tell you something about stack useage.
If you need to check it from the running program itself, you could of course fill the stack with a pre-defined content and make a small functeion that runs thru the stack area, looking for the amount of stack that don't have the pre-defind content anymore.
I'm not running an OS.
How would i fill the stack with a pattern? This must be done before calling main()?
Or can I fill the stack with the debugger after reset before i run my code?
You can do it before or after calling main(), but it has to be done in a manner that does not destroy the content of the running stack. I haven't done this on ARM, so I can't tell you the exact details. But I presume there is a way to find where the stack is (and its size) perhaps from some global variables, and just make a pointer and fill the stack using this pointer in a loop.
Hi,
with RTX, create U64 taskStack[STACKSIZE/8] arrays, and memset them to 0xcc in the main function before creating a task. Then simply add this variable to the watch Window and let your application run.
The stack gets filled from top, the last entry you see is the magic word which gets checked by the OS.
By counting the remaining "0xcc" you can see the maximal stack usage.
BR, /th.