Skip to main content
cosmapa2
Associate II
March 18, 2010
Question

How to count execution cycles

  • March 18, 2010
  • 2 replies
  • 1503 views
Posted on March 18, 2010 at 11:45

How to count execution cycles

    This topic has been closed for replies.

    2 replies

    cosmapa2
    cosmapa2Author
    Associate II
    May 17, 2011
    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;