Many embedded developers new to ARM Cortex-M devices are unaware of the powerful debug capabilities these devices enable in their silicon design. Professional IDEs, like Atollic TrueSTUDIO Pro, leverage these and provide debugging power any professional embedded developer should be aware of.
In this blog post, I will explain how Cortex-M cores enable highly useful debugger features for “live” visualization of variable values in real-time.
How variable polling can turn your system live
ARM Cortex-M processors support live variable watch, a debugger feature that updates the variables in a watch view in (almost) real-time as the target system executes at full speed. This capability is implemented by polling with supported JTAG probes.
This feature is incredibly useful and can quickly help identify many bugs, yet it seems that many Cortex-M developers are not aware of this important debug capability. I would argue this capability is so useful and important, that professional embedded developers should not use an IDE without this!
Live variable watch debugger windows can be a very powerful tool in your debugging toolbox but it can also be used for system-level testing and customer demos during prototyping or early development phases.
As you know, there are many situations where you do not want to stop the execution on a breakpoint to query the target system variable values. Maybe you run the embedded system during field tests or in the lab, and the target system reads and processes live sensor data. You don’t want to debug the software, but rather just “look inside” to see what is going on as the system performs its regular duties. In this situation, wouldn’t it be great to see how the variable values change in real-time right from within the debugger?
Another scenario is when your embedded product has moving parts, and you want to read the axis positions as a machine turns or moves. Or you are in the metering or industrial control business, continuously reading values from various sensors as they are processed. In situations like these, it is useful to read and display variable values live when the target runs at full speed.
Atollic TrueSTUDIO Pro has a “Live Expressions” view in the debugger perspective, providing developers with this capability. TrueSTUDIO not only show an unlimited number of variables with live update but can also compute and display the result of complex mathematical expressions in “real-time” as well. The Live Expressions view also supports structures and array elements for a full, “at-a-glance” visualization of complex data structures.
If you are using a Cortex-M processor with Atollic TrueSTUDIO Pro and a SEGGER J-Link JTAG probe, you may want to try this capability.
Using data tracing to monitor variables in real time
Cortex-M devices can also feed advanced debuggers with real-time updates on variable values as the target system executes at full speed, using SWV data tracing. This is implemented using a hardware-supported real-time data access trace capability, (not polling) so that all variable reads or writes are truly detected (assuming no buffer overflows).
In addition to displaying live variable values (but not complex data structures) at full-speed execution, this capability can also be used to provide a true memory/variable access history trace log; showing you exactly which reads or writes have been made to a memory location or variable.
This is incredibly useful, if for example a variable is inadvertently getting an illegal value and you cannot understand where this value is written to the variable, or why.
By enabling real-time variable watch monitoring on certain variables using the SWV event- and data- trace configuration dialog, you are all set to benefit also from a complete variable read/write access history trace log.
Once you have enabled SWV trace recording and started execution, the top of the SWV Trace Data view in the Atollic TrueSTUDIO debugger shows the variable values updated in real-time.
Select the desired variable being monitored in the top (Watch) part, and the bottom part (History) of the view will show all reads and/or writes that has been done to this variable or memory location. The memory access history trace log is even updated in real-time as the target system executes at full speed!
The power of this feature is not to be underestimated. A very common use-case is that a variable sometimes gets an illegal value for unclear reasons.
Perhaps there is a stack overflow corrupting the memory location of the variable, or some pointer error overwrites the variable with data, or there is a calculation bug in an assignment.
By studying the variable access history trace log, you can easily see exactly which write operation did write that faulty value. And not only that, provided that the SWV tracing is configured to emit also program counter (PC) values, the debugger also knows what machine code instruction (and thus, which C line) made that faulty variable update.
In Atollic TrueSTUDIO Pro, you can quite simply double-click on any variable access in the history trace log of the SWV Data Trace view, and the debugger immediately moves you to the responsible C line in the source code editor!
You can also visualize variable values graphically in real-time, using an “oscilloscope style” data plot graph as the Cortex-M target system executes at full speed.
This gives developers instant and highly visual feedback, non-intrusively, from running target systems.
This view shows the variable values graphically in real-time as the target system executes at full speed, and the graph scrolls automatically to the left in an animated manner as execution fills the timespan of the graph.
Visualizing variable values in this way is highly useful, in particular in these situations; values are expected to follow a certain pattern. It is very easy to see if the pattern is broken. It is easy to see how different variable values correlate to each other over time. The view also permits zooming and panning in the graph, and saving “screenshots” of the graph to image files too.
One particular strength of the Serial Wire Viewer (SWV/SWO) data tracing in the Cortex-M core is that all changes to a variable are detected; with periodic polling there is a high risk the variable can take other values between the samples. With SWV, all changes to the variable are detected, providing a fully correct picture of what happens (the only exception is buffer overflows if too many SWV trace packages are sent to the debugger, but that is easily detected).
To use data tracing with TrueSTUDIO Pro you will need a Segger J-Link or ST-LINK debug probe.
By using SWV tracing in Cortex-M devices ARM developers can leverage very powerful debugging capabilities. In particular the SWV data tracing capabilities, including the oscilloscope styled real-time graphs outlined in this article, are very useful and ought to be considered by any Cortex-M developer.
The SWV memory access history log, and the polled Live variable watch view, supporting complex data structures, are incredibly useful to developers. These debugger capabilities are not typically supported by Eclipse IDEs and the GNU gcc/gdb tools.
The Atollic TrueSTUDIO Pro IDE, which is based on Eclipse and the GNU tools, supports these capabilities using proprietary extensions.
You can also get a good overview of Serial Wire Viewer real-time tracing on Cortex-M cores by reading this white paper on the subject: