STM32F0xx : Timer interrupt occasionally processed late or early? Glitch.
I am using a STM32F072 microcontroller with a matrix keypad.
The matrix pins are essentially bit banged, using ODR mask commands.
When I set up a timer(doesn't matter which one) and I use the timers interrupt (update and a single capture compare) to toggle a pin (manually) it seems to be late processing some of the capture compare and update interrupts.
This results in a waveform that looks like this:

Even weirder it doesn't appear to have anything to-do with the speed of the interrupt, as I get the same result at 100KHz as I do 1KHz (as seen above).
The code to setup the timer is as follows:
CR1().UDIS() = true; //Disable updates
CR1().CEN() = false; //Disable counter
CR1().CMS() = 0; //Edge aligned mode
CR1().DIR() = 0; //Up-Counting
CR1().OPM() = false;
CR1().URS() = true; //Only update on overflow or underflow or DMA request
CR2().CCDS() = false;
CR2().CCPC() = false;
auto const prescales = CalculatePrescale(System::SystemClock_t::Timer(), pFrequency);
ARR() = prescales.ARR;
CCR1() = prescales.ARR / 2;
PSC() = prescales.PSC;
CR1().ARPE() = true; //Buffered auto-reload
DIER().UIE() = true;
DIER().CC1IE() = true;
SR().Clear(); //Clears interrupt flags
CR1().UDIS() = false; //Enable update
CR1().CEN() = true; //Enable counterIn the interrupt service routine I simply clear the flags that were set. The interrupt code is as follows:
static void Interrupt()
{
if (SR().UIF())
{
SR().UIF() = false;
//SET PIN LOW
}
if (SR().CC1IF())
{
SR().CC1IF() = false;
//SET PIN HIGH
}
}The glitch only happens when the keypad is enabled.
The keypad only does GPIO pin reads, sets and clears,
The keypad sampling is constantly called from the main loop, not an interrupt so I don't think priority has anything to do with this issue. It doesn't disable interrupts or anything like that.
I don't see reducing the keypad sample speed as a real solution as I suspect that would only make the problem less frequent.
I have now confirmed this, the issue is the same, just much less frequent, it needs to go away entirely.
