How to determine the task Stack size

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

How to determine the task Stack size

跳至解决方案
2,193 次查看
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 项奖励
回复
1 解答
1,523 次查看
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 项奖励
回复
2 回复数
1,524 次查看
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 项奖励
回复
1,523 次查看
davidzhou
Contributor V

Daniel,

Thank you. I will try TAD.

David Zhou

0 项奖励
回复