Timing issue when TIM10 interrupts HAL IWDG macro
- January 30, 2023
- 2 replies
- 2140 views
I am using a STM32F746VET6 to drive time critical signals on up to 14 pins. I am bit banging these signals in the ISR. I was surprised to find after a benign change I started to have jitter in these signals. I tracked it down to the ISR firing during the __HAL_IWDG_RELOAD_COUNTER(&hiwdg) macro.
The ISR itself isn't being delayed as my scope shows the periodicity is still correct. The strange thing is that the timing *inside* the ISR is inconsistent even though it consists of little beyond writing to ports and nops. I have included the ISR at the bottom of this post.I have also attached scope shots with lines 5, 7, and 8 both active (working correctly) and commented out (timing issue).
I have a solution and am moving my project forward, but I really don't understand the symptom. What is it about resetting the IWDG that doesn't delay the ISR, but screws up the timing inside the ISR instead?
void __attribute__((optimize("O0"))) __attribute__((section(".itcm_text"))) bobbywait(Sysmgr_Task_Struct* task_struct_ptr) {
while(1) {
// !!! Unless I ensure the ISR does not fire during this macro the ISR timing is inconsistent!!!
extern IWDG_HandleTypeDef hiwdg;
if(impulse.counter != impulse.counter_last) {
__HAL_IWDG_RELOAD_COUNTER(&hiwdg);
impulse.counter_last = impulse.counter;
}
}
TIM10->DIER &= ~(TIM_IT_UPDATE);
}
void __attribute__((optimize("O0"))) __attribute__((section(".itcm_text"))) TIM1_UP_TIM10_IRQHandler(void)
{
TIM10->SR = 0;
// Create the pulse
impulse.TxPort->ODR = impulse.Step1; // First clamp output channel
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
impulse.TxPort->ODR = impulse.Step2; // Then create pulse, postive or negative depending upon pos or neg pulse configuration
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
// nop_delay(impulse.Period2);
impulse.TxPort->ODR = impulse.Step3; // Then either clamp for unipolar or create opposite pulse for bipolar
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
impulse.TxPort->ODR = impulse.Step4; // Then clamp again.
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
asm("nop"); // 11
impulse.RxPort->ODR = impulse.Mask; // Activate LVOUT to send ultrasound signal to ADC
ADC1->CR2 |= impulse.ADCStartMask; // Activate the ADC acquisition mechanism
Capture_State = CAPTURE_SEQUENCE_STARTED;
impulse.counter++;
return;
}