Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cycle counter on ARM Cortex M4 (or M3)?

I'm trying to profile a C function (which is called from an interrupt, but I can extract it and profile it elsewhere) on a Cortex M4.

What are the possibilities to count the number of cycles typically used in this function ? Function shall run in ~4000 cycles top, so RTC isn't an option I guess, and manually counting cycles from disassembly can be painful - and only useful if averaged because I'd like to profile on a typical stream with typical flash / memory usage pattern.

I have heard about cycle counter registers and MRC instructions, but they seem to be available for A8/11. I haven't seen such instructions in cortex-Mx micros.

like image 898
makapuf Avatar asked Jul 17 '12 20:07

makapuf


People also ask

What is the difference between Cortex-M3 and Cortex-M4?

The Cortex-M3 and Cortex-M4 are very similar cores. Each offers a performance of 1.25 DMIPS/MHz with a 3-stage pipeline, multiple 32-bit busses, clock speeds up to 200 MHz and very efficient debug options. The significant difference is the Cortex-M4 core's capability for DSP.

Where is ARM Cortex-M3 used?

The Cortex-M3 processor is specifically developed for high-performance, low-cost platforms for a broad range of devices including microcontrollers, automotive body systems, industrial control systems and wireless networking and sensors.

What is ARM Cortex-M4?

The Arm Cortex-M4 processor is a highly-efficient embedded processor. The Cortex-M4 processor is developed to address digital signal control markets that demand an efficient, easy-to-use blend of control and signal processing capabilities.

What are the features of ARM Cortex-M3?

ARM Cortex-M3 system tick timer, including an external clock input option. Low power RTC with a separate power domain and dedicated oscillator. Standard JTAG test/debug interface for compatibility with existing tools. Crystal oscillator with an operating range of 1 MHz to 25 MHz.


1 Answers

Take a look at the DWT_CYCCNT register defined here. Note that this register is implementation-dependent. Who is the chip vendor? I know the STM32 implementation offers this set of registers.

This post provides instructions for using the DWT Cycle Counter Register for timing. (See the post form 11 December 2009 - 06:29 PM)

This Stack overflow post is an example on how to DWT_CYCCNT as well.

like image 119
Throwback1986 Avatar answered Oct 21 '22 17:10

Throwback1986