FreeRTOS

Watch the video for a quick start with Snapshot trace, or see the detailed guides below that also covers streaming.

 

  1. Copy the TraceRecorder files into your project. The folder structure is a bit different depending on if the code is copied from the Tracealyzer installation directory or from the official git repository.

    • If the code is copied from the Tracealyzer directory (see links in Help menu): copy all files in the root of the TraceRecorder folder, and also the include and config subfolders.

    • If the code is cloned from the git repository: copy all c and h files from the following folders:

     /
     /config
     /include
     /kernelports/FreeRTOS
     /kernelports/FreeRTOS/config
     /kernelports/FreeRTOS/include
    
    _images/files_in_folder.png
  2. Make sure to add the path to the h files to the compiler’s “include paths” so the compiler can find them. This step is different depending on your development environment.

    _images/STMCube_include.png

    Include options for an project in STM32CubeIDE.

  3. In trcConfig.h set TRC_CFG_HARDWARE_PORT to the architecture used. For some hardware ports you need to #include the processor header file by replacing the row #error "Trace Recorder: Please include your processor's header file here and remove this line.". If the error line is removed and your project compiles, the header file isn’t needed. All available hardware ports can be found at the bottom of trcDefines.h.

    _images/trcConfig_setup.png

    An example with a STM32 L4 Cortex-M device.

  1. TRC_CFG_FREERTOS_VERSION needs to be set in trcKernelPortConfig.h.

  2. In FreeRTOSConfig.h configUSE_TRACE_FACILITY needs to be set to 1 and #include "trcRecorder.h" needs to be included at the end of the file as described below.

    How to include trcRecorder.h with different compilers.
     /* Integrates the Tracealyzer recorder with FreeRTOS */
     #if ( configUSE_TRACE_FACILITY == 1 )
         #include "trcRecorder.h"
     #endif
    
     /* Note: Since FreeRTOSConfig.h is also included from some FreeRTOS assembly files,
     depending on your IDE you may need to use a conditional include, like in the examples below.*/
    
     /* IAR Embedded Workbench */
     #ifndef __IASMARM__
         #if ( configUSE_TRACE_FACILITY == 1 )
                 #include "trcRecorder.h"
         #endif
     #endif
     /* Microchip MPLAB X IDE */
     #ifndef __LANGUAGE_ASSEMBLY
         #if ( configUSE_TRACE_FACILITY == 1 )
                 #include "trcRecorder.h"
         #endif
     #endif
    

6. Call xTraceEnable(TRC_START) in your main function to initialize and start the recorder. This must be done after the initial hardware setup, but before any RTOS objects (tasks etc.) have been created. Optionally, xTraceInitialize() can be used to only initialize the trace system and then xTraceEnable() can be used later when appropriate. Other start options for xTraceEnable are described in trcRecorder.h.

_images/xTraceEnable_call.png

xTraceEnable is called right after the system clocks has been initiated.

  1. Configure the project for snapshot or streaming as mentioned below.

    Note

    For hardware ports that use the same time source as FreeRTOS tick interrupt (for example the hardware port for Pic32/24 and Cortex-A9) xTraceInitialize() needs to be called in the main function before any RTOS objects are created. Then xTraceEnable() needs to be called after the kernel has started. This ensures that the clock used for timestamps have been correctly configured by FreeRTOS.

Snapshot Trace

In snapshot tracing, trace data is stored in a local RAM buffer on the target device that can later be read from the host. The recorder can be configured to either stop or overwrite the start when the buffer becomes full.

  1. Copy the files from the RingBuffer streamport folder into your project. Make sure to include all .c files and the header files from the Config and Include folders.

  2. For RingBuffer settings, see trcStreamPortConfig.h

    • TRC_CFG_STREAM_PORT_BUFFER_SIZE decides the size of the trace buffer that is stored in RAM.

    • TRC_CFG_STREAM_PORT_RINGBUFFER_MODE can be set to TRC_CFG_STREAM_PORT_RINGBUFFER_MODE_OVERWRITE_WHEN_FULL for continuously recording or TRC_CFG_STREAM_PORT_RINGBUFFER_MODE_STOP_WHEN_FULL for stopping when the buffer is full.

Now the project should compile and write data to the ring buffer, from which snapshots can be taken when the target is halted.

Note that the “Snapshot Mode” setting in trcKernelPortConfig.h refers to a legacy solution that is limited to snapshot tracing only. This mode is deprecated and is no longer recommended for new projects. The config file trcSnapshotConfig.h belongs to the legacy snapshot mode.

The default and recommended setting is “Streaming Mode” which allows for both streaming and snapshot tracing by selecting different stream ports. The RingBuffer stream port provides snapshot tracing support.

Reading a snapshot

There are a few ways to read a snapshot. More information is found in the Tracealyzer User Manual and also in some of the vendor-specific guides found on the main Getting Started page (e.g. for STM32CubeIDE, IAR and Keil).

For convenience we provide two examples below - the Percepio plugins for Eclipse and MPLAB X IDE. But basically you can use any method to save the contents of your RAM buffer to a .hex or .bin file, and then simply open that file in Tracealyzer.

The Eclipse plugin can be found on Eclipse Marketplace. This plugin will work for most versions of Eclipse. After the plugin has been installed the Percepio option can be found in the toolbar. To save a snapshot, start a debugging session, halt the application and then select Percepio -> Save Snapshot.

_images/eclipse_plugin.png

The preference menu for the Percepio plugin.

The MPLAB x plugin can be downloaded here then it can be installed following these instructions. To save a snapshot first open the Tracealyzer plugin by going to Tools -> Embedded -> Tracealyzer Export Plugin. Then start a debugging session, halt it, and press the “Save Trace” button.

_images/mplab_plugin.png

A view of the MPLAB X plugin.

Streaming

Streaming is a method where trace data are offloaded from the target continuously, this means that a streaming trace can run for hours or even days depending on the setup. The different streaming methods included can be found in the stream ports folder. If there are no stream ports available that work with the target and/or application a custom stream port can be made, as long as an interface with high enough bandwidth is used.

Follow the below steps to integrate a stream port:

  1. Copy the files from the selected stream port into the project.

_images/included_stream_ports.png

The different stream ports that are included.

Now the project should compile and streaming can be started using the selected interface.