Is there any way I can get stack requirements of task practically?
In recent FreeRTOS project, somehow my application was crashing. After debugging I realised one of the tasks was crossing the assigned stack size which was 256 bytes which was sufficient as per my calculations. Is there any method so I can get runtime info about the stack used by task in FreeRTOS?
3 Replies
@Swapnil @Marvee Amasi @Andru-Khan @Umesh Lokhande do you have any insight here?
Yes @Prahallad . There is API in FreeRTOS which returns the watermark of stack used by task.
• In FreeRTOSconfig.h, enable “INCLUDE_uxTaskGetStackHighWaterMark” (define it as 1)
• Add below piece of code in a task for which you want used stack size.
Uint32_t watermark = uxTaskGetStackHighWaterMark(NULL);
This API will return the value of unused stack in words. For ex. on a 32-bit machine a return value of 1 would indicate that 4 bytes of stack were unused.
• Once you freeze your code and clear with stack requirements, in production code you can remove this code and disable this API.
• Once you freeze your code and clear with stack requirements, in production code you can remove this code and disable this API.
It worked for me, Thank you!