In the last several posts, we have been examining how important threads are to a real-time embedded system. Each thread acts as its own semi-independent program that must have its stack properly sized and the right priority to ensure that it gets its share of CPU time. Threads are a key concept and most discussions around real-time design is focused on task behavior and synchronization. In this post, we will examine TraceX and how developers can use it to see which threads are executing and when.
In the past, developers had to guess or worse, assume that their system was performing as expected. TraceX provides developers with a visualization for what is actually happening on their microcontroller as can be seen in the image below:
In the image, the left-hand side contains all the threads and interrupts that are running on the system and even provides developers with their static thread priority. As the code executes, it generates events which can be exported and then viewed in TraceX. Developers can see from the image exactly when a particular thread was executing and for how long. Careful examination can even spot potential issues such as thread starvation or threads that are missing their deadlines.
TraceX can provide developers with far more information than simply when a task is executing. Remember back a few blogs when we discussed worst case stack analysis. TraceX data can be used to determine the stack usage as well! Examine the image shown below:
This image shows all the different threads that are executing on the system along with information such as the stack size, available stack and then most importantly, the usage. If the trace information above were taken during the worst-case scenario then we could easily see that our thread stacks were grossly overestimated. Shrinking the stacks in half would decrease overall memory usage and could even potentially save BOM costs if a smaller flash device could be selected.
Setting up TraceX is really easy. In the Synergy Configurator, select the main HAL/Common thread. (Remember, there must be another thread in the system to turn-on thread usage, otherwise the system runs thread-less). The ThreadX source contains an option to enable tracing which by default is disabled. In order to enable tracing, add the ThreadX Source module by using Add>X-Ware>ThreadX>ThreadX Source.
After the ThreadX module has been added, it may show up with red text. Since the libraries are already included, it is possible that duplicate declarations will be detected by the linker. In most cases, there won’t be any issues and the developer can simply disable the linker warning in the TheadX Source module properties. Also, note that any other frameworks that exist such as USBX, may also need to have their source added. Not doing so can result in a linker error due to missing or undefined TraceX functions.
Once the ThreadX Source module has been added, click on it and then in the properties window search for Event Trace. Once it is found, changed it to Enabled as shown in the image below:
Developers will need to Generate Project Content and then rebuild their application. Once this is done, the debugger can then be started. In the Run menu, there is a TraceX entry. Developers will want to Launch TraceX Debugging as shown in the image below:
Once this has been done, developers can run their code and can then set a break-point or pause at their area of interest. Developers can then use ‘Update TraceX Data’ to export and view the data.
I always recommend to developers that they enable tracing a projects’ start and periodically take baseline measurements to ensure that their system is behaving as they expect. Any changes in behavior can then be traced back, using the trace data, to determine when the behavior changed and the code change that may have been involved. It’s important to understand what the trace data means and in order to do that, it is highly recommended to review the TraceX user manual that is located on the Renesas Synergy™ Gallery.
In the next few posts, we will push pause on our RTOS discussion and examine some new features that are coming to the Synergy Platform such as the Synergy Wi-Fi Framework before returning to task synchronization using semaphores, mutexes and event flags. Until next time,
Live long and profit!
Professor_IoT
Hot Tip of the Week
Check out this detailed application note for more information on how to debug your project using TraceX. It covers key topics such as installation, starting TraceX, and using the debug view to display executed functions. A simple example provides a step-by-step guide for your first use of TraceX. The application note also shows how to acquire and register the licenses needed to get TraceX working in your development environment. https://www.renesas.com/en-us/doc/products/renesas-synergy/apn/r20an0404ej0101-synergy-debugging-rtos-threadx.pdf
Hello Professor_IoT,
Can you update the link at the very end? It appears as 404 not found.
Thanks!