STM32F7 microsecond delay problem
Hi,
I am using STM32F746NG discovery board. I try to setup 60 micro second delay. With ST-Link debugger, the 60
micro second delay is fine. But when I cycle the power, the firmware does not run.
When I comment out the delay function DWT_Delay_us(), firmware runs. Anything wrong?
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;
void DWT_Delay_Init(void)
{
*DWT_LAR = 0xC5ACCE55; // unlock (CM7)
*SCB_DEMCR |= 0x01000000;
*DWT_CYCCNT = 0; // reset the counter
*DWT_CONTROL |= 1 ; // enable the counter
}
void DWT_Delay_us( uint32_t us)
{
uint32_t clk_cycle_start = *DWT_CYCCNT;
/* Go to number of cycles for system */
us *= (SystemCoreClock / 1000000);
/* Delay till end */
while ((*DWT_CYCCNT - clk_cycle_start) < us);
}
