configASSERT() helps catch mistakes early by stopping the program when something unexpected happens. It is like a safety net during development to find bugs quickly.
configASSERT() for development debugging in FreeRTOS
configASSERT( condition );
The condition is an expression that should be true for the program to continue.
If condition is false, the program will stop (usually in an infinite loop) to help you find the problem.
x is not NULL before using it.configASSERT( x != NULL );
configASSERT( uxQueueMessagesWaiting(queue) < QUEUE_LENGTH );
configASSERT( taskHandle != NULL );
This program creates a task that uses configASSERT() to check if the pointer passed to the task is not NULL. If the pointer is NULL, the program will stop, helping you find the bug early.
#include "FreeRTOS.h" #include "task.h" #include <stdio.h> void vTaskFunction(void *pvParameters) { int *ptr = (int *)pvParameters; configASSERT(ptr != NULL); // Check pointer is valid printf("Value pointed to: %d\n", *ptr); vTaskDelete(NULL); } int main(void) { int value = 42; xTaskCreate(vTaskFunction, "Task1", configMINIMAL_STACK_SIZE, &value, 1, NULL); vTaskStartScheduler(); return 0; }
configASSERT() is usually enabled only in development builds to avoid slowing down the final product.
If configASSERT() fails, the program typically enters an infinite loop to halt execution for debugging.
You can customize the behavior of configASSERT() by defining your own assert handler in FreeRTOSConfig.h.
configASSERT() helps catch bugs early by stopping the program when a condition is false.
Use it to check pointers, task creation, and other important assumptions during development.
It improves debugging by making errors obvious and easy to find.