I use a simple delay clock code. But whenever I use this code program won't start without entering debug mode in KEIL. I plug stlink out and reconnect but it wont work if I don't enter the debug mode. Is there any solution to this. If not then what else can I use to have 100 us delay. Thank you for reading
uint32_t startTick = DWT->CYCCNT, delayTicks = 100 * (SystemCoreClock/1000000); while (DWT->CYCCNT - startTick < delayTicks);
You need to enable the functional blocks involved, the debugger does this for itself.
CoreDebug->DEMCR |= 0x01000000; // TRCENA DWT->LAR = 0xC5ACCE55; // unlock on CM7 cores DWT->CYCCNT = 0; // reset the counter DWT->CTRL |= 1 ; // enable the counter
The alternative obviously would be to create a different free-running TIM, perhaps clocking at 1 MHz (1us) and use that to mark time via TIMx->CNT, where TIMx->ARR is maximal, ie 0xFFFF or 0xFFFFFFFF for 16-bit and 32-bit respectively.
Ok thanks. I will also try this method.
View all questions in Keil forum