Task stack size?

yyang2000 wrote on Wednesday, September 02, 2009:


Does any one know how to determine a stack size when I create a task? Or tell me what factors need to be consider for calculating a task stack size? I have read it from FreeRTOS web stie, but I am still not clear how. I used the demo of Cortex_LM3Sxxxxx_Keil. I tried to figure out how the demo does to determine a stack size. For example, the default configMINIMAL_STACK_SIZE is 70, but I modified it to 250.  I wonder if it is a proper setting. 

Also the mainBASIC_WEB_STACK_SIZE for uIP web server was set to configMINIMAL_STACK_SIZE * 3 which the original was 70*3=210. However, since I modified to 250, now it is 250*3=750. Is it waste memory space?

Any help will be appreciated.

wdeninger wrote on Wednesday, September 02, 2009:

As you know, the stack size is determined during the creation of the task.  Determining stack size has never been an automated process. For instance, FreeBSD has a default of 64MB stack for each application thread, and RedHat has 10MB user, and 8kB kernel, etc…  Generally, you should estimate the required stack space for each thread.  If you do have any recursive calling code within your task, you will need to program them for a maximum recursion depth. 

FreeRTOS does have a compile mode supporting stack overflow detection, and I plan on having it compiled in automatically with the DEBUG build.


incrediball wrote on Wednesday, September 02, 2009:

You can also use the uxTaskGetStackHighWaterMark function to determine how much stack has actually been used and fine tune it. Important is that interrupts also use the stack of the task that is interrupted (although I’m not sure if all ports do this) so their usage needs to be added to the task’s own usage.

wdeninger wrote on Wednesday, September 02, 2009:

Just remember that in FreeRTOS, the stack size is specified as an unsigned portSHORT, which generally means 65535 words max.  -W