Cycle counter on ARM Cortex M4 (or M3)?

前端 未结 5 1762
陌清茗
陌清茗 2020-12-03 00:13

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

5条回答
  •  离开以前
    2020-12-03 00:39

    This is just easier:

    [code]

    #define start_timer()    *((volatile uint32_t*)0xE0001000) = 0x40000001  // Enable CYCCNT register
    #define stop_timer()   *((volatile uint32_t*)0xE0001000) = 0x40000000  // Disable CYCCNT register
    #define get_timer()   *((volatile uint32_t*)0xE0001004)               // Get value from CYCCNT register
    
    /***********
    * How to use:
    *       uint32_t it1, it2;      // start and stop flag                                             
    
            start_timer();          // start the timer.
            it1 = get_timer();      // store current cycle-count in a local
    
            // do something
    
            it2 = get_timer() - it1;    // Derive the cycle-count difference
            stop_timer();               // If timer is not needed any more, stop
    
    print_int(it2);                 // Display the difference
    ****/
    

    [/code]

    Works on Cortex M4: STM32F407VGT on a CJMCU Board and just counts the required cycles.

提交回复
热议问题