I am programming on an Arm M4 microcontroller, and using a timer module and DMA to generate 6 pulses with different periods (between 0.5 and 1 second). The DMA reloads the timer every time it overflows, and raises an interrupt when there is no more data to transfer. In the DMA interrupt, I clear the timer's overflow interrupt flag, enable the NVIC timer interrupt, and expect to get an interrupt the next time it overflows. Instead, I get an interrupt immediately upon exiting the DMA interrupt. Does anyone know why this is happening?
This situation only occurs if the timer's overflow interrupt flag is enabled during setup. If the overflow interrupt flag and NVIC timer interrupt are both enabled within the DMA interrupt, there is no immediate timer interrupt. But in both situations I clear the overflow interrupt flag immediately before enabling the NVIC interrupt, so I don't understand the difference.
I am happy to provide my code and more technical information, but I wanted to start with a simple version of my question in case I'm just not understanding something about interrupts on this microcontroller.