cancel
Showing results for 
Search instead for 
Did you mean: 

How to count execution cycles

cosmapa2
Associate II
Posted on March 18, 2010 at 11:45

How to count execution cycles

2 REPLIES 2
cosmapa2
Associate II
Posted on May 17, 2011 at 13:43

I found a way searching the net. The ARM Cortex has a Cycle counter register. Below is C code to initialize it and read it. Using the Memory View to look at the value of the register at memory location 0xE0001004 let you see the counter updating as you step through the code.

 

int count = 0;

volatile unsigned int *DWT_CYCCNT = (int *)0xE0001004; //address of the register

volatile unsigned int *DWT_CONTROL = (int *)0xE0001000; //address of the register

volatile unsigned int *SCB_DEMCR = (int *)0xE000EDFC; //address of the register

*SCB_DEMCR = *SCB_DEMCR | 0x01000000;

*DWT_CYCCNT = 0; // reset the counter

*DWT_CONTROL = *DWT_CONTROL | 1 ; // enable the counter

.......

......

count = *DWT_CYCCNT;