ARM M4 Instructions per Cycle (IPC) counters

半腔热情 提交于 2019-12-03 01:11:46

The code sample you provided has a problem in clearing the enable bit. You should clear the bit sing 'AND' not 'OR':

*DWT_CONTROL = *DWT_CONTROL & 0xFFFFFFFE ; // disable the counter by clearing the enable bit

I have no idea how to use the registers the way you want to use them. But, here is how I deal with measuring cycles.

Make sure you enable the counter at the SysTick Control and Status Register. With the appropriate headers, you should have access to the SysTick registers as a structure.

Measure the number of cycles taken by the counter function. This is later subtracted from any measurements.

  SysTick->VAL = 0; // set 0
  // Measure delay on measurement  
  __disable_irq();
  a = (uint32_t) SysTick->VAL;
  //... measuring zero instructions
  b = (uint32_t) SysTick->VAL;
  __enable_irq();
  measure_delay = a - b;

Now measure a function.

SysTick->VAL = 0;
__disable_irq();
a = (uint32_t) SysTick->VAL;

//Assuming this function doesn't require interruptions

// INSERT CODE TO BE PROFILED
function_to_be_examined();

b = (uint32_t) SysTick->VAL;
__enable_irq();
cycles_profiled_code = a - b - measure_delay;

I hope it helps.

I think if you want to measure accuracy cycles, using debugger is a good choice. the Keil-MDK could accumulate the state register and will not overflow. the result in debugger is the same as the result using DWT.

if you want to measure the other values ie FOLDCNT, using trace in Keil-MDK -> Debug -> Setting -> Trace -> Trace Enable.

With that, while debugging, in the Trace Windows choose trace event, the value of those 8 bits register could be collected and added together by Keil.

It seems a little stupid but I don't know how to collect the event of overflow, I think this event could only be send to ITM, because either the DWT or the ITM is individual component out of the program. if we want to collect the event in customer program, the collect action will must effect the accuracy of the result.

ITM? ETM? CoreSight? DWT?AHB?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!