October 23rd 2020
By Azema Talam, Firmware Design Engineer
FreeRTOS is one of the leading real-time operating systems for microcontrollers. It is easy to learn, open-source, and with all extra tools like SEGGER SystemView it is a reason why it is used in many projects.
One of the most important aspects when developing an embedded application is getting insights into what is going on application. No matter how carefully you design and implement the application when there is an issue, developers are often making assumptions on code timing, code flows, interrupt firing, etc.
FreeRTOS comes with a bunch of cool features that can be used to make debugging easier and better. One of the features that can be enabled is collecting run time statistics. FreeRTOS can collect information on the amount of the time that each task spends in a running state. This is a very simple but powerful method of estimating task execution time and getting the percentage of total time spent on each task. But still, this gives us just a piece of information on what is happening in the system. Furthermore, we can add some trace capabilities to the FreeRTOS application. Trace hooks macros are a feature that can be used to trace the behavior and timing of the application and operating system. FreeRTOS source code contains empty macros that an application can re-define for the purpose of providing application-specific trace facilities. Trace hooks macros are really good to use if you want to toggle LED on task context switching and analyze timings using the scope. You can try to use trace hooks macros to make your own tool for real-time recording and visualization but adding more and more code to trace hooks will affect the timings of your application so be careful.
I am not trying to discourage you from implementing run-time statistics or using trace macros. Using it carefully together you can add great diagnostic to your production application. But this is where the power of trace tools such as SystemView is shown when debugging embedded systems.
SystemView is a tool that enables real-time recording and visualization of trace data on how embedded applications are behaving. By adding necessary files, our application can generate events when tasks become ready for execution, starts or stop executing, when an interrupt happens, and so on. It is based on the technology known as Real-Time Transfer (RTT) which is just a small memory buffer on the target device. With RTT it is possible to output information from the microcontroller at very high speed without affecting the device real-time behavior.
All it is needed is a few files on the target device that communicate with the host using J-Link debug connection.
In order to add SystemView to your project you need to:
1. Install SEGGER SystemView
2. SEGGER J-Link Install
3. Add the SystemView module to the project.
C:/Program Files (x86)/SEGGER/SystemView_V252d.
4. In your project add three folders
5. For SEGGER folder copy all the files from
6. For Config folder copy all the files from
7. For FreeRTOS_SEGGER folder copy the following files
8. Apply a patch to the FreeRTOS source code
9. Add SEGGER_SYSVIEW_GET_TIMESTAMP() function if needed.
10. Add #include "SEGGER_SYSVIEW_FreeRTOS.h" at the end of the “FreeRTOSConfig.h” file.
11. Modify the SYSVIEW_RAM_BASE (SEGGER_SYSVIEW_Config_FreeRTOS.c file) value to the lowest RAM address for your device.
12. Add #include "SEGGER_SYSVIEW.h" in main file.
13. Search the main function and add the following function calls
14. Build and run your example, run SystemView and start recording.
I used one of the development boards from NXP and wrote the simple application “Hello World”. After following the steps from above I was able to see how the application is behaving.