STM32F769 DWT CYCCNT
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎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
- Labels:
-
DEBUG
-
STM32F7 Series
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-04-27 10:48 AM
Check flags in DBGMCU
Could you use TIM2/TIM5 in maximal mode?
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-04-27 1:26 PM
I'd expect that to diminish the power saving from WFI to zero. Can you please comment/measure?
JW
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-05-01 5: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:
- 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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-05-01 1: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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-05-02 6:06 AM
SCB_SCR.SLEEPDEEP is 0, was the first thing I checked. This DWT_CYCCNT behavior is "new to me" for the F7.

- « Previous
-
- 1
- 2
- Next »