[En-Nut-Discussion] Stack Size

Harald Kipp harald.kipp at egnite.de
Fri Sep 8 10:58:23 CEST 2006


Hello Tim,


At 15:11 07.09.2006 -0500, you wrote:

>Ethernut 4.1.9 rc
>AT91SAM7X256
>
>I guess I am confused on the stack size.  I have a program that is running 
>out of space, but if I check the memory that is left, I have over 45KB (of 
>64KB) left.  This would leave me to believe that the stack is getting filled.

You're confusing me too, a little bit. :-) NutHeapAvailable()
returns the number of bytes available in the heap. When a
new thread is started, the specified amount is taken from
the heap. If the thread runs out of stack space, the whole
application may crash, because the CPU will simply use more
memory than allocated and overwrite other items.



>Is the stack not allocated from RAM?
>
>If so, is there a way to increase the total amount of RAM to use for the 
>stack or to increase the total stack size?

There is no total stack size. Each thread needs its own stack.




>I see that I can change the main and idle thread stack sizes in the 
>Configurator, but how does that affect my available stack size?

It only affects your heap space.



>Also is it wise to turn down the idle thread stack size?

If you need a few more bytes from heap, this may be an option.
But as you got 45k left, you still got plenty of heap space
available.

The 32-bit ARM requires much more stack space than the 8-bit AVR.
Also be aware, that local variables are located in stack space.
Thus, it is no good idea to declare large local arrays or structures.
Better declare pointers and allocate the required memory from heap.
Or use globals.

Harald





More information about the En-Nut-Discussion mailing list