[SOLVED] How to do MCU utilization measurements

Thank you @antisvin, worked like a charm! Very helpful!

(I understood the calculations, but not the technique, as I haven’t dived this deep into the MCU before.)

This is what I did in case anyone else need this.

Include

#include "core_cm7.h"

In main(), before starting the audio callback:

// setup measurement
CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
DWT->LAR = 0xC5ACCE55;
DWT->CYCCNT = 0;
DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;

// Start calling the audio callback
hardware.StartAudio(AudioCallback);

Then at the very top of my audio callback:

void AudioCallback(float* in, float* out, size_t size)
{
	// variable declarations here -- removed

	// measure - start
	DWT->CYCCNT = 0;

And right before exiting the audio callback I check the value and turn on the LED if I’m near the limit:

// measure - stop
if (DWT->CYCCNT > 390000)
	hardware.SetLed(true);

This corresponded with me getting audio artefacts (noise). The value (390 000) should be computed according to @antisvin’s clear listing. Right now I only wanted to know if I was maxing out the processor.

Once again, thanks!

4 Likes