Welcome to the first post on getting started with using a Real-Time Operating System (RTOS) and Percepio Tracealyzer. In earlier posts we have talked a lot about how you can use Tracealyzer to find unwanted behavior in your RTOS-based system, but here and in a few later articles we will discuss how to actually do this in practice. I assume you know something about RTOS, at least on a high level, otherwise I recommend our article series “RTOS 101”.

Embedded developers such as myself are often a bit skeptical about using tools to produce code, “If I haven´t written it, I do not trust it!” For me that used to be true while working on small systems, perhaps a few kB of code. When projects grew, with multiple developers I needed to learn to trust the other people in the project, and the step from that to trusting auto-generated code is not that far.

Yes: Auto-generated code.

Some parts you will probably not think of writing yourself: RTOS, communication stacks, or for that matter the compiler. Today all chip vendors will give you code to incorporate into your project for handling peripherals and also example code on how to use them. A processor user guide can be many thousands of pages so learning every important aspect of the device is probably not efficient for you. Since a while back most chip vendors have created tools to generate code for you that will setup the device in a manner that you specify, and I urge you: Use them!
I know it might feel weird, and some of you will probably think the code is ugly, arranged in a strange way, might even be tabulated using the WRONG method! Why should you then use this shortcut?

– First of course because it is a shortcut! You will save time!

– Second: Even if you are an experienced developer, how many projects have you written startup and peripheral setup for? Many hundreds? The chip vendor examples beat you here with a factor of tens, hundreds even thousands. And as many safety standards point out there is safety in numbers. Code being used in ten thousand places will have every flaw exposed soon, but your custom solution might have a problem only discovered in very special cases, perhaps not encountered until a special circumstance occur.

– Third: Consider it a black box. You probably have some code running that the linker decided you needed, such as variable initialization, math routines and other runtime library items. Build a library from the generated code if you don’t want to look at it.

Next I’ll describe how to get started with FreeRTOS using ST Microelectronics code generation tool STM32CubeMX on a STM32 Nucleo board. I begin by starting STM32CubeMX and then create a new project, using the wizard:


As I am using a recognized board I select it, the Nucleo-L476.

STM32CubeMX - Board Selection

Setting up the clocks can be quite complex, but STM32CubeMX makes it simple. Do you really want to write this code manually, to set all these bits in several registers?

STM32CubeMX - Clocks

STM32CubeMX also allows me to include FreeRTOS, and thereafter give the option to specify tasks to create at startup.


Now I can generate code and project files for my IDE of choice, and then I am up and running with a multi-tasking FreeRTOS-based system. And this within 3 minutes after starting development!

Next, to get Tracealyzer working I need to include Percepio’s recorder library. The board is equipped with a ST-Link debug probe, which doesn’t allow for real-time trace streaming, so I decided to use the Snapshot Recorder in this case. I simply add the 5 source code files for the Snapshot Recorder and put them into a separate group in the project.

Snapshot Recorder Files

To get the Tracealyzer recorder working, I need to make minor updates of the FreeRTOS configuration and the recorder library, and also make sure that trcKernelPort.h is included when building FreeRTOS. The only part left is to add two function calls into main to initialize the recorder library and to start the recording. All these steps are described in the Tracealyzer User Manual.

Using Tracealyzer recorder library

Congratulations, you have now in less than 6 minutes created a very solid base for your next development project.

Tracealyzer is available for several common RTOS, including FreeRTOS, SafeRTOS, Linux, VxWorks, Micrium µC/OS-III, and a version for ThreadX will be released during 2016. And we have several new and exciting analysis features in development that allows for even better performance analysis, so stay tuned!

Download Tracealyzer

Want to learn more about RTOS-based development and Tracealyzer? More articles here!