From:http://www.cnblogs.com/suozhang/p/5301054.html
1. The official document provides functions to query the remaining stack space of the task, first of all to look at the Official document interpretation (the official document of a great god translator. )
Parameter explanation: Xtask: The handle of the queried task--for information on how to get the task handle, see the parameter pxcreatedtask of the API function Xtaskcreate (). If a NULL handle is passed in, the task queries the high watermark of its own stack space.
return value: The actual usage of the task stack space floats up and down as the task executes and the interrupt process progresses. Uxtaskgetstackhighwatermark () returns the minimum amount of stack space that is left in the run history from which the task started execution. This value is the remaining unused stack space when the stack space is used to reach the deepest. The closer the value is to 0, the more the task is not far from the stack overflow.
Here's how I'm going to use it:
You first need to add a task handle when creating a task:
The specific methods are:
1, Xtaskhandle pvcreatedtask_toggleled4; This code is defined as a null pointer variable. (typedef void * XTASKHANDLE;)
2,xtaskcreate (TOGGLELED4, (int8_t *) "LED4", Configminimal_stack_size, NULL, Led_task_prio,& Pvcreatedtask_toggleled4);//Create a task
3, to use Uxtaskgetstackhighwatermark this function, first of all have to look at the following description:
* Include_uxtaskgetstackhighwatermark must is set to 1 in FreeRTOSConfig.h for
* This function is available.
The meaning is in FreeRTOS.h (English description error, actually in this FreeRTOS. h) file to change the Include_uxtaskgetstackhighwatermark macro definition to 1, can not be changed, Modify the properties of the document to remove the read-only!
4,///The following is the task I want to query the remaining stack space, which called Uxtaskgetstackhighwatermark this function
void ToggleLed4 (void * pvparameters)
{
unsigned portbase_type Uxhighwatermark;
for (;;)
{
/* Toggle LED4 each 250MS */
Stm_eval_ledtoggle (LED4);
Uxhighwatermark=uxtaskgetstackhighwatermark (PVCREATEDTASK_TOGGLELED4);
printf ("ToggleLed4 remaining stack space is what:%d.\r\n", Uxhighwatermark);//gxp, serial detection, November 17, 2015 11:26:42
Vtaskdelay (500);
}
}
5. Look at the results:
6. Analysis:
1, the "74" here, it should be 74*4=296 bytes (1 bytes = 8 bits), because freertos in the setting of the stack is in accordance with the "word" calculation, in STM32 a word is 32 bit!
2, according to the data returned to judge, this task also remaining 296 bytes are not used, resulting in waste, so in the setting of the stack space should be reduced settings, to avoid waste!
FreeRTOS How to query the remaining stack space of a task