I am using some SPI devices where I have to apply small delays before
continuing to use them/set up process/ soft restart etc
I call this delay loop in a bare metal instrument loop where an LED
flashes every 20mS.
I have the TMR6 set to count up from 0 to 65535 at a 1uS interval.
Somehow this gets stuck in a loop. Even adding the HAL_SysTick
to this as a back up measure does not seem to help. After say 20 mins on the bench I notice the LED is not flickering
and on pressing pause in debug it always pops out in the loop.
Is this something the C compiler has done to ‘optimise’ the code ?
Have interrupts somehow blocked the timers from updating ?
Or the debugger perhaps is stopping the timers moving on ?
void delay_micro_seconds(uint32_t period_uS, void *intf_ptr) {
int16_t dur_uS,now,then = *&htim6.Instance->CNT;
int32_t dur_mS,sys_tick = HAL_GetTick()+1;
int32_t period_mS = period_uS/1000;
asm(" nop");
do {
now = *&htim6.Instance->CNT;
dur_uS = (now - then);
dur_mS = HAL_GetTick() - sys_tick;
if ( dur_mS >= period_mS) {
asm("nop");
printf("Overflow uS delayn");
}
}
while ( dur_uS < period_uS && dur_mS < period_mS); // hows about all that then.
asm(" nop");
}