FreeRTOS Continuous Trace Streaming

Key to successfully implementing embedded applications these days is to have detailed visibility into what is going on with the application on the board. For this, I’m using the FreeRTOS+Trace from Percepio to inspect the runtime behaviour. Stop-Mode debugging is very useful, but visibility into the runtime is even more important. FreeRTOS+Trace is a tool to accomplish this, but it requires to dump the data off the target to the host (see “Updated Percepio Tracealyzer and Trace Library to Version V2.7.0“). Usually, I’m using the GDB debugger for this, and that works for shorter trace sequences like a few seconds. Yes, I can combine them, but it painful to stop, dump and continue. So what if I could collect trace for several minutes or hours without the need to stop the application? Why not stream the data to the host directly?

So here is it: I’m now able to get almost unlimited trace streaming off the target, witout user intervention. I can trace my application for hours πŸ™‚

Trace Recording

Trace Recording for almost one hour

Segger RTT and Percepio FreeRTOS+Trace

Segger announced their RTT technology last year, and I have been using the RTT functionality in several projects as a way of communicating with the microcontroller, similar like using semihosting (see “Using Segger Real Time Terminal (RTT) with Eclipse“). One usage of RTT is to stream off trace data from the target. I already started to experiment with RTT to stream off FreeRTOS+Trace data (see “Tracing FreeRTOS with a Hardware Probe” about that concept).

So no suprise to me, when Percepio made a press release back in March this year that they have now Segger RTT with FreeRTOS+Trace streaming, working with Segger embOS. But what about FreeRTOS?

Continuous FreeRTOS+Trace for Freescale Kinetis

I had to wait until June when Percepio started a beta program of RTT Trace streaming for FreeRTOS. And I was in :-).

How does it work? The same way as with the ‘normal’ Percepio Trace Library, except that it is a different library with the Segger RTT library integrated. The basic principle is that both the Application and RTOS can store events into a trace RAM buffer on the target (typically few KBytes RAM), which then is transferred to the host PC for inspection.

Percepio and FreeRTOS Trace Block Diagram

Percepio and FreeRTOS Trace Block Diagram

  • FreeRTOS needs to have configUSE_TRACE_FACILITY enabled in FreeRTOSConfig.h. With this the RTOS will call hooks into the recorder for all the configured RTOS events like creation of task, waiting for a semaphore, suspending a task, allocating a memory block, etc.
  • The Application can record events, including any interrupts or any user events or data.
  • The Percepio Trace Library is the recorder which manages the symbols (e.g. task names, etc) and the recorded events. Inside the RTT library, the task named ‘TzCtrl’ is running to receive start/stop commands from the host. According to the comments in the sources, the need for this task might to be eliminated in the future.
  • The recorded data then can be dumped to the host with the debugger, or to an SD card, etc. The new library includes the Segger RTT Library which uses a small RAM buffer to stream the data to the host.
  • On the Host PC the Segger J-Link Library reads the data through SWD/JTAG from the target.
  • The Percepio FreeRTOS+Trace application reads the data provided by the RTT channels and stores it on the host PC disk to be analyzed with the trace viewer.

And I’m excited: tonight I have continuous trace working with the FRDM-K64F and FRDM-KL25Z board!

Streaming Trace off a Freescale FRDM-K64F Board

Streaming Trace off a Freescale FRDM-K64F Board

The Pecepio FreeRTOS+Trace application has settings to configure the RTT up and down buffers:

Segger RTT Connection settings

Segger RTT Connection settings

Once the application is running, it will send the trace date through RTT. This trace data can can be collected by the Percepio Tracealizer FreeRTOS+Trace application on the host:

Connect to Target System

Connect to Target System

With Connect to Target System I open the dialog to collect the streaming:

While streaming and collecting data, the window shows me the current system load: very nice feature to watch the performance and CPU utilization of the application running:

Trace Performance Monitor

Trace Performance Monitor

I had no problems collecting data for more than 90 minutes, and I was able to collect more than 50 kBytes raw data per second:

Collecting data for over 90 minutes

Collecting data for over 90 minutes

I can stop the recording, save the trace and view it. The trace data can be inspected in various ways:

Inspecting Collected Trace

Inspecting Collected Trace

I mentioned that extra TzCtrl task which receives host commands. The collected performance data shows that this task really does not add much to the application load:

CPU Load

CPU Load

Processor Expert Component

I’m using the BETA1 version of the new RTT enabled Percepio Library with FreeRTOS v8.2.1 (available on GitHub). To make things easy to use, I have extended the current Processor Expert Percepio component to support the new RTT functionality:

Processor Expert Component

Processor Expert Component

Using the settings, I can configure the amount of buffers and RAM needed, plus configure the TzCtrl task. The component automatically calls Trace_Init() during startup of the application, so no special calls are needed from the application itself.

The new component supports for now only ARM (all Freescale Cortex-M cores)). Both Kinetis SDK and normal Processor Expert projects are supported :-).


When asking me why I’m using FreeRTOS, then the big plus (+) are things like FreeRTOS+Trace: it allows me to monitor and stream the application and RTOS data for a very long time, almost unlimited. All what I need is a Segger J-Link probe for RTT and the Percepio library and application. And you do not even need a physical Segger J-Link probe: it works fine with the OpenSDA circuit on the Freescale Freedom boards :-).

Naturally, this new feature is limited to Segger J-Link, and only the ARM Cortex-M cores are supported. Percepio has a Free Edition of their Tracealizer (FreeRTOS+Trace) product which allows a limited amount of trace, see Kinetis Design Studio with Processor Expert comes unlimited and free of charge, and for the price of a FRDM Board which can run an Segger J-Link OpenSDA Firmware (e.g. FRDM-KL25Z for ~US$15) this is a very inexpensive way to get trace data off an embedded target in a very convenient way.

Once the beta period is over, I will publish the updated components on SourceForge.

Happy Streaming πŸ™‚

PS: Many thanks to Percepio engineers for listening to my suggestions and feedback during the beta program!



13 thoughts on “FreeRTOS Continuous Trace Streaming

  1. Pingback: Erich Styger reviews FreeRTOS+Trace Beta - Percepio AB

  2. Pingback: Automatic Variable, Expression and Memory Display with GDB and Eclipse | MCU on Eclipse

  3. Pingback: Review - FreeRTOS trace streaming - Percepio AB

  4. Pingback: McuOnEclipse Components: 17-Oct-2015 Release | MCU on Eclipse

  5. Pingback: McuOnEclipse Components: 08-Nov-2015 Release | MCU on Eclipse

  6. Thank your for this great an informative article. I have a question though: You say that a Freescale FRDM board can run a Segger J-Link OpenSDA Firmware. Does this mean I can use this low cost eval board as J-Link debug-probe replacement? Because this sounds to good to be true πŸ˜‰ so what are the pros and cons, or to be precise, what are the drawbacks? Or can this really act as a debug probe that normally would cost several hundred dollars?


    • Hi Stefan,
      See the terms of use here:
      Beside of that: the OpenSDA performance is good, but not to the level a the normal J-Link because that one has a more powerful CPU in it. So the performance is not comparable to the several hundred dollar probe (which is worth every dollar I can say, and no, I’m not associated with Segger πŸ˜‰ ). For educational or non-commercial usage you can use the J-Link EDU (



      • Hi Erich,
        I’m learning a lot of RTOS concepts on your blog, thanks for all the info. Since some time ago i was looking for a excuse to buy the J-Link EDU and tracing FreeRTOS tasks with the free version of this tool seems like the perfect excuse.

        The performace of the J-Link EDU differs a lot from the standard version?
        Had you tried tracing with the EDU version?
        I understand that the J-Link EDU works with all the Cortex M microcontrollers, can you please confirm me this hehe?

        Thanks in advance πŸ™‚


      • Hi Carlos,
        great, that’s excactly why I put a lot of efforts into this blog, so others can learn from it :-).
        I did not measure the performance, but the J-Link EDU is somewhat faster compared to the OpenSDA version. I don’t feel much of a difference between the standard and EDU version.
        And yes, I do FreeRTOS tracing with the OpenSDA, EDU and J-Link Plus version: here I feel that the EDU and Plus are a bit faster too, but not by factors.
        About all the supported devices by Segger, have a look here:


      • Hi,
        It seems like it support all the Cortex M devices, will try to get the EDU then :).



  7. Pingback: McuOnEclipse Components: 12-Dec-2016 Release | MCU on Eclipse

  8. Pingback: What is “Realtime Debugging”? | MCU on Eclipse

What do you think?

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s