Debugging Embedded Systems Part 3: MTB Trace

Posted on July 28, 2016

This article presents a overview of the debug features in the latest releases of SOMNIUM DRT. It is the third and final part of our blog series on debugging.


Debugging is hard. We all know this and many studies have confirmed that it accounts for a significant part of the time, and therefore cost, in software development. Program flow is often determined by asynchronous events, for example interrupts and exceptions. Sometimes it would be nice to step back through the code, to see what the processor was doing before it got to its current state.

SOMNIUM DRT is is a set of development tools for ARM Cortex-M based devices such as the SMART devices from Atmel, the Kinetis and LPC devices from NXP and the STM32 devices from STMicroelectronics. It is fully compatible with industry-standard tools such as the GNU toolchain and Eclipse IDE. DRT uses our patented techniques to produce highly optimized code by exploiting information about the embedded processor, the memory system and other peripherals to deliver improved performance, lower code size and reduced energy use. It also includes a number of advanced debugging tools.


MTB Trace

SOMNIUM DRT includes several features to support debugging embedded systems. One of these is the ability to trace program flow so you can step backwards and forwards through the execution history to see how you to to a particular state.

Many Cortex M0+ based devices have a micro trace buffer (MTB) which, when enabled, records changes in program flow and stores the information in RAM. The trace data is typically stored in a circular buffer so that the oldest data is overwritten. Writing the trace data has minimal impact on program execution and so this is a non-invasive way of analysing program behavior.

DRT can extract the trace information and then create a new debug session to reconstruct the program flow from the trace data. This is known as post-mortem debugging. Using the MTB does not need any special debug hardware. It works with standard debug adapters such as SEGGER J-Link, P&E Multilink and OpenSDA. It also does not need any changes to your application code (apart from some initialization code if you are using OpenSDA).

In the post-mortem debgging session you are able to step forwards and backwards through the program flow so you can understand what the program was doing before it stopped. This is particularly useful if the program has hit a fault as the Cortex-M0+ core only records limited information about the cause of the fault. Using the trace allows you to see the code that was being executed when the fault occurred. Without the trace functionality, you would need to step forward through the code hoping to find the point where the fault occurred. In a real-time system it may not be possible to step through the code or, if you do, it may change the behavior of the program so the fault doesn't occur.

Here is a video demonstrating the use of the trace buffer.



A free trial of DRT is available. DRT provides automatic import of projects from other development tools, making it simple to evaluate and migrate your projects to. Download your free trial today and try out these powerful debug features for yourself.

x

Download a free trial of SOMNIUM DRT

   Got a question?