For reasons related to debugging our application we use the function uxTaskGetSystemState(). It populates a vector of structures TaskStatus_t. In this structure is also present the field usStackHighWaterMark, whose comment says:
/ * The minimum amount of stack space that has remained for the task since the task was created. The closer this value is to zero the closer the task has come to overflowing its stack. * /
For the same reasons of debugging, we also need to know the size of the stack, and the maximum usage percentage of it.
How can I get this information with the functions and structures available?
If you set configRECORD_STACK_HIGH_ADDRESS to 1 in FreeRTOSConfig.h then
the other end of the stack is also recorded in the task’s TCB -
depending on which version of FreeRTOS you are using (its quite a new
feature), but I don’t think there is a function to retrieve it so you
would have to look in the TCB manually.
However, as the size of a task’s stack is defined by the application
writer when the task is created I would suggest you already know the
total size of the stack.
It would be better if we could get the information from the process structures, because it’s true that I know the information when I create tasks, but it’s also true that in the moment in which the vector of TaskStatus_t is populated it’s difficult, if not impossible, to access such information.
However, I use version 10.0.1
If you look at the bottom of tasks.c you will see that, with the correct #defines, you can insert your own code into tasks.c by providing header
files that are included into the c file directly. That enables any
extensions you want for your project without the need to edit the
kernel’s source files.
To enable this function is necessary that also the symbol FREERTOS_ADDITIONAL_FEATURE_TOTAL_STACK_API is defined to 1. I do it on the command line when I launch make.