0
0
FreeRTOSprogramming~7 mins

Trace hooks and FreeRTOS+Trace

Choose your learning style9 modes available
Introduction

Trace hooks help you watch what your FreeRTOS program is doing step-by-step. FreeRTOS+Trace shows this information in a clear way so you can find and fix problems easily.

You want to see when tasks start and stop in your FreeRTOS program.
You need to find why your program is slow or stuck.
You want to check how tasks share the CPU over time.
You want to learn how FreeRTOS schedules tasks by watching real events.
Syntax
FreeRTOS
/* Enable trace hooks in FreeRTOSConfig.h */
#define configUSE_TRACE_FACILITY 1

/* Include FreeRTOS+Trace header in your main file */
#include "trcRecorder.h"

/* Start trace recording */
vTraceEnable(TRC_START);

/* Stop trace recording */
vTraceEnable(TRC_STOP);

Trace hooks are enabled by setting configUSE_TRACE_FACILITY to 1 in FreeRTOSConfig.h.

FreeRTOS+Trace uses special functions to start and stop trace recording. Use the FreeRTOS+Trace tool to retrieve data from the RAM buffer.

Examples
This line in FreeRTOSConfig.h turns on trace hooks so FreeRTOS records task events.
FreeRTOS
/* Enable trace hooks */
#define configUSE_TRACE_FACILITY 1
This example shows how to start trace recording.
FreeRTOS
#include "trcRecorder.h"

int main(void) {
    vTraceEnable(TRC_START);  // Start tracing
    // Your FreeRTOS code here
    return 0;
}
Sample Program

This program enables trace hooks, creates a simple task, starts trace recording, and starts the scheduler. Use the FreeRTOS+Trace tool to read the trace buffer from RAM.

FreeRTOS
/* FreeRTOSConfig.h snippet */
#define configUSE_TRACE_FACILITY 1

/* main.c */
#include "FreeRTOS.h"
#include "task.h"
#include "trcRecorder.h"

void Task1(void *pvParameters) {
    for (;;) {
        // Simulate work
        vTaskDelay(pdMS_TO_TICKS(100));
    }
}

int main(void) {
    xTaskCreate(Task1, "Task1", 1000, NULL, 1, NULL);

    vTraceEnable(TRC_START);  // Start trace

    vTaskStartScheduler();    // Start FreeRTOS scheduler

    // Normally never reached
    return 0;
}
OutputSuccess
Important Notes

Trace hooks add a little overhead but help you see what tasks do in real time.

FreeRTOS+Trace shows a timeline of tasks switching, delays, and interrupts.

Always disable trace hooks in production to keep your program fast.

Summary

Trace hooks let you watch FreeRTOS tasks and events as they happen.

FreeRTOS+Trace helps you see this information clearly to debug and learn.

Enable trace hooks in config and use vTraceEnable to record data. Retrieve with the tool.