usStackDepth with more byte allocation in the task routine

Hi, I have a doubt when I create un task. If in the task routine I have a byte allocation same this void prvMainTask(void pvParameters) { char readtext[1024]; / File read buffer */ How will be usStackDepth in create task? Thanks in advance Michele

usStackDepth with more byte allocation in the task routine

FreeRTOS is just C code, it does not, and indeed cannot, change the behaviour of the compiler. Therefore, if you place 1024 bytes on the stack as you have done in the code snippet you provided, then you will need an ADDITIONAL 1024 bytes of stack allocated to your task when you create the task (so best not to do it). Remember when creating a task the stack size is specified in words, not bytes.

usStackDepth with more byte allocation in the task routine

Thanks Richard, but my doubt if I have to allocation more byte. In my task I read 1024byte from SDMMCard, then I parser this bytes… can you check my reasoning? 1) I use a micro STM32 ARM that has 32bit WORD 2) I create my TASK “xReturned = xTaskCreate( prvKEYTask, “KEY”, configMINIMALSTACKSIZE * 4, ( void * ) 1, tskIDLEPRIORITY + 1, &xKEYHandle ); ” …. where configMINIMALSTACK_SIZE = 128 word so my task has 128word * 32bit = 4096bit / 8 = 512byte 3) But in my task I will allocation 1024byte where > 512byte 4) I’ve got to increase these bytes on the task words… right? Thanks a lot Michele

usStackDepth with more byte allocation in the task routine

If you task allocates a 1024 byte buffer, than you need to increase the allocation size by at least 1024 byte (256 32bit words). One of the programmers tasks when creating a FreeRTOS task is to estimate how much stack space that task will use (some compilers may be able to help with this). It is the programmers responsibility to allocate enough stack space to make this work. Generally, it is easier to allocate large buffers like that in global static memory rather than on the stack, and let the compiler automatically worry about it. Some major times you might need the buffers on the stack is if you have two functions needing their own buffers, and in a given task sometimes you are in one of the functions and sometimes in the other, or if the function needing the buffer is reentrant, possibly being used by multiple tasks, and needing seperate buffer for each. Sometimes, even in these cases it make more sense to put the buffer on the heap so you can detect easily at run time that you have run out of memory.

usStackDepth with more byte allocation in the task routine

If you task allocates a 1024 byte buffer, than you need to increase the allocation size by at least 1024 byte (256 32bit words). One of the programmers tasks when creating a FreeRTOS task is to estimate how much stack space that task will use (some compilers may be able to help with this). It is the programmers responsibility to allocate enough stack space to make this work. Generally, it is easier to allocate large buffers like that in global static memory rather than on the stack, and let the compiler automatically worry about it. Some major times you might need the buffers on the stack is if you have two functions needing their own buffers, and in a given task sometimes you are in one of the functions and sometimes in the other, or if the function needing the buffer is reentrant, possibly being used by multiple tasks, and needing seperate buffer for each. Sometimes, even in these cases it make more sense to put the buffer on the heap so you can detect easily at run time that you have run out of memory.

usStackDepth with more byte allocation in the task routine

Thanks Richard, I move the allocation in the main program