cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F769 DWT CYCCNT

VMiki.1
Associate II

I'm using the STM32F769-DISC0 development board and am utilizing the DWT->CYCCNT to calculate cpu load as well as using it as a high speed timer that runs at the clock frequency. When the debugger is plugged in, it functions fine. However, with the debugger unplugged, it iterates at a much lower rate and does not match the clock frequency.

I'm using the following code to enable DWT_CNT, and the LSR and CTR registers indicate it is on, but the problem continues with the debugger unplugged. I *must* be missing something, however I cannot find anything in the user manual that indicates what register (if any) I'm missing?

  CoreDebug->DEMCR &= ~0x01000000;

  CoreDebug->DEMCR |=  0x01000000; // TRCENA

 

  DWT->LAR = 0xC5ACCE55; // unlock

  DWT->CYCCNT = 0; // reset the counter

  DWT->CTRL &= ~0x00000001;

  DWT->CTRL |=  0x00000001; // enable the counter

16 REPLIES 16

So this behavior is different on the F7 vs the F4. The same instruction on the F4 causes the core to "sleep" while the CYCCNT continues as it waits for the instruction. This holds true regardless of debugger status. On the F7 it behaves like the F4... but only while the debugger is running. Are you familiar with what options the STLink debugger will set to avoid this "deep sleep" mode that pauses the core completely?

Check flags in DBGMCU

Could you use TIM2/TIM5 in maximal mode?

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

That helped --> SLEEP bit in CR needed to be set and then it works as I've grown used to on the F4. Noted as a difference between the F7/F4. TIM2/TIM5 could be used in max mode to achieve similar results, but my project is going down the path where those two timers may need to be used for various input captures. Thanks!

I'd expect that to diminish the power saving from WFI to zero. Can you please comment/measure?

JW

> The same WFI instruction is used on my F4 projects to calculate cpu load by keeping track of CYCCNT in WFI

I've just tried on an 'F429:

  • WFE (I am lazy to write even a minimal ISR) with SCB_SCR.SLEEPDEEP=0 results in DWT_CYCCNT running continuously from system clock
  • WFE with SCB_SCR.SLEEPDEEP=1 (I did not bother with setting the bits in PWR which would switch off the regulators) results in DWT_CYCCNT stopping during the sleep period, while it keeps running at cca 16MHz (presumably HSI) if the DBG bits in DBGMCU_CR (I was lazy to found out which one particularly, I presume DBG_STOP)

So, the behaviour mainly depends on state of SLEEPDEEP bit in processor. I don't think this is much different in Cortex-M7.

@VMiki.1​ , how do you set SLEEPDEEP?

JW

Piranha
Chief II

> with the debugger unplugged

When on F7 I disconnect a J-Link with a GUI from the IDE (not the hardware), it stops the DWT->CYCCNT. Most likely disables some bits in CoreDebug->DEMCR and DWT->CTRL. Of course, after resetting the MCU manually, the code configures the necessary bits and the CPU load measuring works again.

SCB_SCR.SLEEPDEEP is 0, was the first thing I checked. This DWT_CYCCNT behavior is "new to me" for the F7.