minimal stack usage of tasks with PIC32

nilssch wrote on Wednesday, April 13, 2011:

Hi,

I currently need to estimate whether I will have enough available RAM for my project when using freeRTOS with PIC32. 

One important point is memory usage of tasks. Am I right that will need at least following amount of RAM for each task?
760byte (config_Minimal_Stack_Size=190 words)  + 64 byte for task-organization + more stack for any local/non-static data

As I will need to realize a “large” project requiring at least 20 tasks and 20 queues I am concerned that I might run out of RAM soon. So can you give me a hint how I can lower the memory usage? I read about the function attribute “naked” for task functions - about how much would it help to lower config_Minimal_Stack_Size? Or is there some related freeRTOS configuration switch that might help to further reduce the memory usage?

Regards,
Nils

rtel wrote on Wednesday, April 13, 2011:

The MIPS core uses a lot of stack.  FreeRTOS minimises the stack requirements by provided a separate stack for any interrupts (which may be nested many deep) - thus removing the requirement for each task stack to allocate enough stack for interrupts too. 

The figures you state sound about right, but it depends on what the tasks are doing.  If the tasks are calling standard C library functions (especially things like printf()), then they will need more.  You can minimise that again by providing cut down versions of such library functions (FreeRTOS contains a file to replace the printf()/sprintf() functions, but with limited functionality).

If you are using FreeRTOS V7.0.0 then you have the option to include a lot of functionality in timer callback functions.  If a task has “run to completion” type functionality, you can have it in a timer rather than a task, and save yourself lots of stack space.

There is always the option of using co-routines too, which are ultra light weight threads, but they have limited functionality and are a bit legacy now (going back to when 8-bit was used more).

Regards.