Hello,
I want to measure microseconds with the Cycle Counter of the DWT-Unit on a STM32F7. After long long searching, I found a lot of examples to do this by setting the CoreDebug->DEMCR register with TRCENA and the DWT->CTRL register with CYCCNTENA.
So it seems to be a very easy code:
CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk; DWT->CYCCNT = 0; DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;
But with this code, nothing happens in the controllregisters (DEMCR and CTRL) all enable bits are 0 and the Cycle Counter doesn't run. I tested with and without a connected ULINKpro. With ULINKpro, the counter is running and my measurement works (CYCCNTENA=1). But without ULINKpro despite with "DWT->CTRL |= 1" stays the CYCCNTENA bit 0 and the counter don't run...
Have anybody an idea, whats the reason for the missing write-access to the control register is? Also tests with "DWT->LAR = 0xC5ACCE55" don't change anything.
After the study of the ARMv7-ArchitectureRM and all the other referenced manuals I'm happy about any new ideas! Maybe I miss any bits in other modules like ITM...?
Thanks a lot!
This has worked for me on F7/CM7 platforms
volatile unsigned int *DWT_CYCCNT = (volatile unsigned int *)0xE0001004; //address of the register volatile unsigned int *DWT_CONTROL = (volatile unsigned int *)0xE0001000; //address of the register volatile unsigned int *DWT_LAR = (volatile unsigned int *)0xE0001FB0; //address of the register volatile unsigned int *SCB_DEMCR = (volatile unsigned int *)0xE000EDFC; //address of the register ... *DWT_LAR = 0xC5ACCE55; // enable access *SCB_DEMCR |= 0x01000000; *DWT_CYCCNT = 0; // reset the counter *DWT_CONTROL |= 1 ; // enable the counter ...
Thank you Clive for your replay!!!
I compared my code with yours and I think it's the same. All your address defines are equal to my used defines of DWT and CoreDebug register from the CMSIS.
I found my misstake arround that code sequence. I test the access to the DWT->CTRL and the Lock-Present Bit by reading out the LSR register before I set the TRCENA in SCB_DEMCR. So all registers give back Zeros...
Thank you.