Skip to content

System Utilities

Helpful utilities when debugging and tuning a system:

  • vTaskList() — table of all tasks and states
  • vTaskGetInfo() — details for a specific task
  • uxQueueMessagesWaiting() — items currently in a queue
  • xTaskGetCurrentTaskHandle() — handle of the running task

Enable stats formatting in FreeRTOSConfig.h:

#define configUSE_TRACE_FACILITY 1
#define configUSE_STATS_FORMATTING_FUNCTIONS 1
#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);
}
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.
}
#include "queue.h"
extern QueueHandle_t qSamples;
void monitor(void){
UBaseType_t n = uxQueueMessagesWaiting(qSamples);
if (n > 12) { uart_puts("Consumer falling behind!\n"); }
}
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.