This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

RTX task stack size how do you do it

I have a product running RTX with 16 tasks

when I started the project I was relaxed about the RAM of the micro (STM32F205ZE)
but in a recent code review I decided to look at the RAM usage and clean it up and make it "lean"

so I have a function to Start each task e.g.

void StartTPMTask(void)
{
#ifdef C_STACK_TEST
    memset(&TPM_task_stk[0],0xAA,(C_TPM_TASK_STK_SIZE*8));
#endif
  /*************************************/
   if(OS_TPM_Task_id == 0)
   {
      OS_TPM_Task_id =    os_tsk_create_user(TPM_task,eTask_Priority_TPM,&TPM_task_stk[0],sizeof(TPM_task_stk));
      if(OS_TPM_Task_id)
      {
#ifdef C_STACK_TEST
         AddStackToTest("TPM",OS_TPM_Task_id,&TPM_task_stk[0],C_TPM_TASK_STK_SIZE);
#endif

      }
   }
}
<\pre>

where as you can see I fill the stack RAM with a known value,
that is later then examined when the task it "stopped" and the last thing before shutdown of the system all the stack data is written to a SD card

e.g. an example of the print out

***************
* Stack Data
* 10:54:46
*************
71.4% Used-00080 Size-00112 ID-02 Battery Monitoring Task
89.3% Used-00800 Size-00896 ID-03 Display Task Task
84.0% Used-01344 Size-01600 ID-04 Data Manager Task
17.2% Used-00088 Size-00512 ID-05 ALARM Task
71.4% Used-01096 Size-01536 ID-06 GSM Task
63.9% Used-00184 Size-00288 ID-07 TPM Task
67.2% Used-00344 Size-00512 ID-08 Can TX Task
64.3% Used-00072 Size-00112 ID-09 GSM Timeout Task
75.0% Used-00072 Size-00096 ID-10 Send Data Timer Task


  28.0% Unused Total 5664 unused 1584

I leave the system running for at least 48 hours before I use the data to hopefully try and catch the exceptions where more stack data may be used than normal

I feel "safe" only using 80% of the task stack but it grates to see that I roughly don't use 30% of the RAM allocated to stacks

How do others go about setting task stack size and what safety margin do you use ?