ARM SWO Performance Counters

In “Cycle Counting on ARM Cortex-M with DWT” I have used the ARM DWT register to count the executed cycles. With the MCUXpresso IDE comes with a very useful feature: it can capture the 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

Preconditions

To use SWO trace and performance counters in MCUXpresso IDE, I need the following:

  • An ARM core capable to produce SWO trace data, e.g. ARM Cortex-M3 or M4, as on 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 by the application code. See “Tutorial: Getting ETM Instruction Trace with NXP Kinetis ARM Cortex-M4F” for more details.
  • A debug probe capable to capture SWO data, e.g. the LinkServer debug connection in MCUXpresso IDE, e.g. with a LPC-Link2:
    LPC-Link2 debugging FRDM-K64F

    LPC-Link2 debugging FRDM-K64F

    💡 In the current v10.0.0 of the IDE, a LinkServer probe is required, e.g. 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 is matching 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

Performance Counters and more

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 break points:

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, see http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.faqs/ka16403.html

Still, the cycle counter alone is useful to measure 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 🙂

Links

Advertisements

What do you think?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s