Hi, I'm trying to figure out why my basic timer interrupt on the STM32H7B3x dev board isn't working as expected. It seems to be triggering more often than I expect depending on when I clear the flag within the interrupt.
I am using the STM32H7B3LI-DK dev kit and want to use a simple timer with an interrupt. Using the most basic function, I've added a variable that simply increments within the interrupt. The timer is configured to hit the preloaded value at approx 1ms intervals so I expect the interrupt to be executed every approx 1ms.
This is my very basic IRQ handler code :
void TIM6_DAC_IRQHandler(void)
{
TIM6->SR &= ~(UINT32)0x01; // clear IRQ flag
MyTimerTick++;
}
The above works, and I get approx 1000 counts of 'MyTimerTick' in a 1sec period. However, if I change the IRQ code to the following:
void TIM6_DAC_IRQHandler(void)
{
MyTimerTick++;
TIM6->SR &= ~(UINT32)0x01; // clear IRQ flag
}
Then the above does not work as expected!. Within a 1sec period, the number of counter stored in 'MyTimerTick' is approx 1990.!? All I've done is move the clear flag instruction.
I'm setting the priority of the TIM6 irq to 10 but have also tried it at 2 and the result is the same.
I understand that the flag needs to be cleared otherwise the IRQ handler gets re-entered which makes sense, but I wouldn't have expected such a subtle difference in operation to affect the mechanism so much. I must be missing something but can't seem to find the cause in the MCU manual nor the Cortex manuals.
I can't find anything on this on the ST threads but appreciate I might have missed a search term; Any help is greatly appreciated.
