2022-04-26 11:47 AM
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
2022-04-27 10:24 AM
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?
2022-04-27 10:48 AM
Check flags in DBGMCU
Could you use TIM2/TIM5 in maximal mode?
2022-04-27 11:20 AM
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!
2022-04-27 01:26 PM
I'd expect that to diminish the power saving from WFI to zero. Can you please comment/measure?
JW
2022-05-01 05:52 AM
> 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:
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
2022-05-01 01:54 PM
> 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.
2022-05-02 06:06 AM
SCB_SCR.SLEEPDEEP is 0, was the first thing I checked. This DWT_CYCCNT behavior is "new to me" for the F7.