cancel
Showing results for 
Search instead for 
Did you mean: 

how to count cpu cycles on M0+ chips?

zrs5532
Associate II

Hi everyone,

I am preparing a course for university and I plan to use G071RB NUCLEO board. I wish to show floating point calculation without FPU is pretty slow, so is there a way to show cpu cycle count feature from debug?

Thank you!

3 REPLIES 3
S.Ma
Principal

Get a timer running at core frequency as freerun, read the timer value as a timestamp. If you have 32 bit hw timer, use it. The other way to check performance is to toggle a gpio. Do know that emulated float or double sw libraries are not all equals, maybe compiler and compiler options dependent. Have a look at Segger math library to start digging this topic.

From debug?

Probably not directly.

You could use a TIM to count time.

You might be able to use the SYSTICK counter, it's a 24-bit down-counter, I think you could use that in a maximal mode, and do some 24-bit unsigned truncated math.

Typically for illustrative purposes you'd build a benchmarking frame-work that could test subroutines/sequences over N iterations, and use a timer. If you do enough iterations you could use micro-second or milli-second time counts to quantify the speed of different algorithms or operations.

STM32G071 has one 32-bit counter, could clock that at CPU frequency, or 1 MHz, and delta the value of TIMx->CNT either side of the test code.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
zrs5532
Associate II

Thank you all for your reply. I should have mention that I have a logic analyzer, and I can toggle a pin and time it. but I was hoping there is a more "elegant" way to do the same from the debugging view. I guess only SWV interface could possible to offer this feature.

Again, thank you all for your suggestions, and I will dig in more.