System Utilities
Overview
Section titled “Overview”Helpful utilities when debugging and tuning a system:
vTaskList()— table of all tasks and statesvTaskGetInfo()— details for a specific taskuxQueueMessagesWaiting()— items currently in a queuexTaskGetCurrentTaskHandle()— handle of the running task
Enable stats formatting in FreeRTOSConfig.h:
#define configUSE_TRACE_FACILITY 1#define configUSE_STATS_FORMATTING_FUNCTIONS 1List All Tasks
Section titled “List All Tasks”#include "FreeRTOS.h"#include "task.h"
void print_task_table(void){ char buf[512]; vTaskList(buf); // Name State Prio Stack Num uart_puts("Task State Prio Watermark\n"); uart_puts(buf);}Get Info for One Task
Section titled “Get Info for One Task”void dump_task(TaskHandle_t h){ TaskStatus_t s; vTaskGetInfo(h, &s, pdTRUE /*include stack high watermark*/, eInvalid); // now s contains name, state, priority, watermark, etc.}Queue Backlog
Section titled “Queue Backlog”#include "queue.h"extern QueueHandle_t qSamples;
void monitor(void){ UBaseType_t n = uxQueueMessagesWaiting(qSamples); if (n > 12) { uart_puts("Consumer falling behind!\n"); }}Current Task Handle
Section titled “Current Task Handle”TaskHandle_t me = xTaskGetCurrentTaskHandle();// e.g., self-suspend:vTaskSuspend(me);vTaskList()and stats require enough buffer space and enabled config macros.- Avoid calling these utilities in time-critical paths; use them for debugging and telemetry.