How to determine the task Stack size

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to determine the task Stack size

Jump to solution
1,518 Views
davidzhou
Contributor V

Hi,

I have K60 tower board, and am using Code Warrior 10.6.4 with MQX 4.2.

I have only two tasks.

TASK_TEMPLATE_STRUCT  MQX_template_list[] =
{
{ UART_TASK,     Uart_Task,  20000,   5,    "Uart", MQX_AUTO_START_TASK,     0,         0 },
{ MAIN_TASK,       Main_Task,  25000,   6, "Main", MQX_AUTO_START_TASK,       0,        0 },
{ 0 }
};
 

And I have increased stack size to 25000 for Main task. It still triggers stack overflow. I am wandering how to determine the stack size for safety of not getting overflowed. Is there anyway to optimize the code for smaller stack size?

Thank you,

David Zhou

0 Kudos
1 Solution
848 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi David:

I think you can use MQX tool, TAD (Task Aware Debugging).

There are TAD plugins for Code warrior, IAR, and Keil IDEs.

The plugins add MQX menu into your debugger environment and allow you to display various information about MQX OS kernel like stack usage per task, system memory pools etc.

You can start with a safe stack size , and fine tune it, try to decrease it a little each time, until the stack usage to 80-90% and no overflow, then I think the stack size is OK now.

pastedImage_1.png

Regards

Daniel

View solution in original post

0 Kudos
2 Replies
849 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi David:

I think you can use MQX tool, TAD (Task Aware Debugging).

There are TAD plugins for Code warrior, IAR, and Keil IDEs.

The plugins add MQX menu into your debugger environment and allow you to display various information about MQX OS kernel like stack usage per task, system memory pools etc.

You can start with a safe stack size , and fine tune it, try to decrease it a little each time, until the stack usage to 80-90% and no overflow, then I think the stack size is OK now.

pastedImage_1.png

Regards

Daniel

0 Kudos
848 Views
davidzhou
Contributor V

Daniel,

Thank you. I will try TAD.

David Zhou

0 Kudos