cancel
Showing results for 
Search instead for 
Did you mean: 

Memory requirement on RTOS task?

antonius
Senior
Posted on April 15, 2017 at 01:21

Everyone,

How can I know memory requirement for each task on RTOS ?

I put already 512 bytes per task, and the setting on freertos configuration is larger than needed, but I can not execute

repeated function on one task, it works if I put the function on seperated task.

Anyone got ideas ?

Thanks for reading my post

#memory #rtos #task #function
4 REPLIES 4
Posted on April 15, 2017 at 01:59

Well you need to look at your call-tree (what functions you call, and what functions they call), and the auto/local variables called by each. If you recurse this can be large and unbounded. This would be a static analysis.

For a dynamic analysis, ie how it works when observed in a real system, you'd want to fill the stack with a recognizable pattern, and then measure the maximum depth at different times, and under different loadings. If you've don't your static review properly these numbers should be very close. Of course external code/libraries can be harder to quantify.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Barry.Richard
Associate III
Posted on April 15, 2017 at 02:45

In any given task the RTOS only consumes a few tens of bytes over and above the stack that would be consumed were the RTOS not being used.  The additional bytes are only consumed when a task is swapped out, at which time all the CPU registers are pushed to the stack.  So the stack required is basically the same as in a non-RTOS program, which means it depends on what your application puts on the stack, how deep your function call nesting is, the compiler you use, and the compiler optimisation level.

You can calculate this, or have GCC tell you what it is, but really the simplest way is to try it and see how much stack your task is using, then adjust as necessary.  There are RTOS features you can use to see how much stack is used.  First you could use one of the StateViewer IDE plug-ins which show stack usage.  Alternatively you could use the

http://www.freertos.org/uxTaskGetStackHighWaterMark.html

() API function to see how much unused stack space there is.  Make sure, at least during development and debugging, you have the

http://www.freertos.org/Stacks-and-stack-overflow-checking.html

(set to 2).
Posted on April 15, 2017 at 02:18

 ,

 ,

I put this in my function :

♯ define MAX_ALBMS 15 /* Maximum number of albums */

♯ define MAX_TRKS 100 /* Maximum number of tracks in an album */

♯ define F_LEN 14

char AlbumTbl[MAX_ALBMS][F_LEN],

char TrackTbl[MAX_TRKS][F_LEN],

....

strcpy(filename, AlbumTbl[Cdir]), /* Play a

track */

strcat(filename, '/'),

strcat(filename, TrackTbl[Ctrk]),

Could they be the issue on my stack and heap ? that's why I need a

separate task ?

It works find if I separate each directory, but if I combine 2

directories in 1 task, the first one will go,

but the other one will only read the name, but never read the content.

♯ define configTOTAL_HEAP_SIZE ((size_t)16384)

..

osThreadDef(sixthTask, StartSixthTask, osPriorityNormal, 0, 512),

I was thinking that, I can divide 2 directories per task, but in the

reality, it's not possible.

Posted on April 15, 2017 at 02:42

From the context that looks to be globally allocated static data (neither heap/stack), and is therefore *not* thread unique.

If 'filename' is a local/auto variable to the function, then that would be unique and on the stack of the thread. Two threads could run the same function, they wouldn't see each others copy of 'filename'

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..