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 🙂
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).
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.
- 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!
The Pecepio FreeRTOS+Trace application has settings to configure the RTT up and down buffers:
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:
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:
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:
I can stop the recording, save the trace and view it. The trace data can be inspected in various ways:
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:
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:
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 http://percepio.com/licensing/. 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!
- Segger Real Time Terminal: https://www.segger.com/jlink-real-time-terminal.html
- Using RTT with Eclipse: Using Segger Real Time Terminal (RTT) with Eclipse
- Using Percepio Trace: Tracing with FreeRTOS+Trace from Percepio