This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

stack

I am writing a code in embedded C.I would like to know how much should be my stack? How to calculate it?.

Parents
  • The primary driver in the size of the stack is the level of nested function calls. At least, it would be in most environments and compilers. Since Keil goes to great lengths to speed things up and use registers to pass function arguments, things get a bit muddied.

    The simplest answer is that you need "enough that things will work." One thing that I have done before is write a routine to initialize the stack to a known value (the character 'x' for example). Let your program run for a while. Then, if you have an ICE, just break and take a look at the stack space. If you've still got a fair amount of 'x's left, odds are you'll be ok. If you don't have an ICE, you can write a routine to spit the stack contents out the serial port on some external event.

Reply
  • The primary driver in the size of the stack is the level of nested function calls. At least, it would be in most environments and compilers. Since Keil goes to great lengths to speed things up and use registers to pass function arguments, things get a bit muddied.

    The simplest answer is that you need "enough that things will work." One thing that I have done before is write a routine to initialize the stack to a known value (the character 'x' for example). Let your program run for a while. Then, if you have an ICE, just break and take a look at the stack space. If you've still got a fair amount of 'x's left, odds are you'll be ok. If you don't have an ICE, you can write a routine to spit the stack contents out the serial port on some external event.

Children
No data