2022-06-26 11:17 AM
2022-06-26 11:28 AM
It's a magic access number/register combo,as I recall it's not needed on the CM3 processors.
Becomes a thing mainly on the CM7
This should work to start the cycle counter
volatile uint32_t *DWT_CONTROL = (uint32_t *) 0xE0001000;
volatile uint32_t *DWT_CYCCNT = (uint32_t *) 0xE0001004;
volatile uint32_t *DEMCR = (uint32_t *) 0xE000EDFC;
*DEMCR = *DEMCR | 0x01000000;
*DWT_CYCCNT = 0;
*DWT_CONTROL = *DWT_CONTROL | 1;
2022-06-26 11:41 AM
Thank you for the fast response. I will give try. However my actual code is similar, but hangs in 'while'' statement:
void DWT_Delay(uint32_t us) // microseconds
{
uint32_t startTick = DWT->CYCCNT,
delayTicks = us * (SystemCoreClock/1000000);
while (DWT->CYCCNT - startTick < delayTicks);
}
2022-06-26 11:54 AM
Many thanks for your answer. It WORKS!!!
2022-06-27 02:15 AM
Using CMSIS files:
#if defined __CM7_REV
DWT->LAR = 0xC5ACCE55U ;
#endif
DWT->CYCCNT = 0 ;
DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk ;
2022-06-27 02:57 AM
Thank you for your response, but in case of Bluepill CubeIDE cannot find DWT->LAR member of DWT. The way Tesla DeLorean suggested is working at stm32f103, too.
2022-06-27 11:53 AM
This code works for all Cortex-M3/M4/M7
DWT->LAR is only compiled if M7 is used thanks to the conditional.