Anyone knows if uVision can register the maximum stack usage in
debug mode?.. Is very useful to run the code in the target and then
check the maximum usage of the stack in any moment in order to be
safe about the size. Perhaps anyone knows a better way to calculate
This is easy to accomplish.
Fill the stack area with a known pattern (0xDEADBEEF or whatever) at
your program initialization in the code or using debug macros. Run
the program for a while. Inspect stack area to see how much of the
pattern was overwritten (can be automated as well.)
hehe... very good solution, I will do that, but, I think the
debuger can do it wihtout need to write code to fill it.
I think the debuger can do it wihtout need to write code to
I agree. That would be useful functionality to have.
The method described can be quite a useful indicator, but remember
when you look at the stack after your run don't assume it is the
absolute maximum use, because it may not be. It is the use of a run
up to that point. The absolute maximum would be the result of worst
case nestings and might only occur infrequently.
Any such test should be done togeter with a code coverage analysis
- what parts of the code was executed?
Another thing to remember is that some processors have a unified
stack also including interrupts. So knowledge about the used
processor is needed.
Can you describe more about it?what should i do ?Could you please make an example by code?
Where part i should write this code ?
What chip do you have?
Best place to "memset" the stack memory is in the Reset Handler, before you've called anything. If the routines managing the statics clears the memory, you could do the filling in main() as you enter.
You're filling it with a pattern that a) you can observe in a Memory View window, or b) walk upward with a pointer until the pattern can't be read any more. Not exactly complicated stuff here.
i use LPC1768. Can you tell me what should i do and how can i find how many stack byte i need?
There is a note. When i clean the project then rebuild all project then every thing are OK
This is this application note:
However I am having problems with the XML "print" element. It still works if these lines are removed.
You have to distinguish two radically different things here: you can either measure, or calculate.
Measuring is done either by the "check how much of my 0xDEADBEEF is left untouched" method, or by using real-time debuggers that can track the stack pointer(s) during execution. The reliability of the result is, at best, questionable, because you never really know if the test run hit the worst-case situation for stack usage, even remotely.
Calculating, if even possible, is done at compile and link time, and relies on the compiler's knowledge of two things: maximum stack usage of each compiled function, and the structure of which functions are called by which other ones (i.e.: the call tree). This method is extremely reliable, but has severe limits of applicability, because many common code patterns make it excessively hard, if not right-out impossible, to build a correct call tree.
Some related and helpful information can be found here:
- "µVISION DEBUGGER: Enabling the Stack Usage Watermark Feature"
- "µVISION DEBUGGER: Accessing Stack Usage Watermarking Results"
View all questions in Keil forum