Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

An Intro to ARM SWO Performance Counters

DZone's Guide to

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.

· IoT Zone ·
Free Resource

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.

SWO Counters

SWO counters

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:

Freescale FRDM-K64F Board

Freescale FRDM-K64F Board

  • SWO trace pin present on the debug connector:

SWO Trace Connected to Debug Header

SWO Trace Connected to Debug Header

  • 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:

LPC-Link2 debugging FRDM-K64F

LPC-Link2 debugging FRDM-K64F

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:

SWO Clock Speed

SWO clock speed

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:

New Performance Counter View

New performance counter view

To start collecting messages, use the ‘play’ button:

Start Performance Couter Processing

Start Performance Counter Processing

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:

Cycle Counter

Cycle Counter

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.

Summary

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:

SWO Trace Views

SWO Trace Views

But I reserve these for one or more follow-up articles.

Happy Cycling!

Topics:
mcuxpresso ,iot ,arm swo counters ,tracing ,tutorial

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}