You want to look into GetTaskHighWaterMark.
This is what I use on all my tasks to see how close they come to running out of stack.
Code: Select all
#define STACK_SIZE_IdleLoop 2048 // stack size for idleLoop
TaskHandle_t TaskHandle_IdleLoop;
/* -----------------------------------------------------------------------------
GetTaskHighWaterMark( TaskHandle_t task_handle )
Input Params:
- task_handle: The task name you want to examine
Returns: high water mark for tasks stack
Example: printf("Stack Water Mark: %u\r\n", GetTaskHighWaterMark( xTask1 ) );
Notes: The lower the result, means the closer you are to running out of
stack space.
-----------------------------------------------------------------------------*/
UBaseType_t GetTaskHighWaterMark( TaskHandle_t task_handle )
{
UBaseType_t uxHighWaterMark;
uxHighWaterMark = uxTaskGetStackHighWaterMark( task_handle );
return uxHighWaterMark;
}
/* -----------------------------------------------------------------------------
GetTaskHighWaterMarkPercent( TaskHandle_t task_handle, uint32_t stack_allotment )
Input Params:
- task_handle: The task name you want to examine
- stack_allotment: How much stack space did you allocate to it when you created it
Returns: float with the % of stacke used
Example: printf("Stack Used %04.1f%%\r\n", GetTaskHighWaterMarkPercent(xTask1, 2048) );
Notes:
-----------------------------------------------------------------------------*/
float GetTaskHighWaterMarkPercent( TaskHandle_t task_handle, uint32_t stack_allotment )
{
UBaseType_t uxHighWaterMark;
uxHighWaterMark = uxTaskGetStackHighWaterMark( task_handle );
uint32_t diff = stack_allotment - uxHighWaterMark;
float result = ((float)diff / (float)stack_allotment) * 100.0;
return result;
}
/* -----------------------------------------------------------------------------
idleloop()
-----------------------------------------------------------------------------*/
void idleloop(void * parameter)
{
for (;;)
{
printf("Stack Used %04.1f%%\r\n", GetTaskHighWaterMarkPercent(TaskHandle_IdleLoop, STACK_SIZE_IdleLoop) );
vTaskDelay(500 / portTICK_PERIOD_MS);
}
}
/* -----------------------------------------------------------------------------
app_main
-----------------------------------------------------------------------------*/
void app_main()
{
xTaskCreate(idleloop, "idleloop", STACK_SIZE_IdleLoop, NULL, 1, &TaskHandle_IdleLoop);
}