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.
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:
- 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 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:
💡 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:
💡 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:
Performance Counters and more
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 break points:
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.
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.
Happy Cycling 🙂
- Cycle Counter on ARM: Cycle Counting on ARM Cortex-M with DWT
- Trace on Kinetis M4: “Tutorial: Getting ETM Instruction Trace with NXP Kinetis ARM Cortex-M4F
- LPCXpresso IDE SWO Trace: http://www.nxp.com/assets/documents/data/en/quick-reference-guides/MCUXpresso_IDE_SWO_Trace.pdf
- ARM Infocenter on performance counters: http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.faqs/ka16403.html
- MCUXpresso IDE Documentation: http://www.nxp.com/mcuxpresso/ide/documentation