An Intro to ARM SWO Performance Counters
This look at ARM SWO counters details how and why to use them, which boards you need, and how to configure them with the MCUXpresso IDE.
Join the DZone community and get the full member experience.Join For Free
In “Cycle Counting on ARM Cortex-M with DWT” I used the ARM DWT register to count the executed cycles. On that note, the MCUXpresso IDE comes with a very useful feature: It can capture ARM SWO (Single Wire Output) trace data. One special kind of trace data is the ‘cycle counter’ information, which is sent through SWO.
To use SWO trace and performance counters in the MCUXpresso IDE, I need the following:
An ARM core capable of producing SWO trace data, e.g. ARM Cortex-M3 or M4, as on the FRDM-K64F:
SWO trace pin present on the debug connector:
The SWO pin on the processor is not used/muxed for anything else.
The trace clock should be enabled, either through the debugger or via the application code. See “Tutorial: Getting ETM Instruction Trace with NXP Kinetis ARM Cortex-M4F” for more details.
A debug probe capable of capturing SWO data, e.g. the LinkServer debug connection in the MCUXpresso IDE. For example, a setup to capture an LPC-Link2:
Note: In the current v10.0.0 of the IDE, a LinkServer probe is required. A P&E or Segger won’t support the SWO trace in the MCUXpresso IDE. The NXP OpenSDA circuit on the Freedom and Tower boards do not support SWO.
Enable SWO Performance Counters
The SWO trace pin is sending the data based on the clock speed. Make sure that the speed matches the core clock speed. To change the speed, I have to be connected with the target:
In case the debug probe is not able to catch up with the clock speed, try to run the core with a lower clock speed.
I can add a new view (or open the existing one) with the ‘+’ icon for the performance view:
To start collecting messages, use the ‘play’ button:
This will configure the ARM core to send out the SWO messages.
The most useful for me is the cycle counter: I can collect it while running, or measure the number of cycles, e.g. between breakpoints:
The cycle counter gets incremented by every (core) clock cycle. This does not directly give the number of executed instructions, as cycles are spent during sleep or for load/store overhead. These overhead cycles are counted with the other SWO cycle counters shown in this view. To the number of instructions, take a look at this.
Still, the cycle counter alone is useful to measure the time between two execution points for a first estimation, without the need for a full trace solution.
The ARM Cortex M3/M4 features SWO counters. The core can send the counter information out to the debugger. The MCUXpresso IDE has a built-in and easy to use way to collect these counters and show them in the SWO Counters view.
SWO does not mean counters only. There is more:
But I reserve these for one or more follow-up articles.
Published at DZone with permission of Erich Styger, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.