Unhandled interrupt occurs after switching Timer OC modes on STM32L476
Posted: Sun May 02, 2021 8:25 pm
I'm working with output compare interrupts using uPy 1.12 on an STM32L476 Nucleo to blink the user LED.
To guarantee that the pin starts low I am configuring the OC channel initially in forced inactive mode.
Then later in my code I'm re-configuring the same timer channel to use toggle mode and trigger a callback.
On the first interrupt I get the following error indicating that an unhandled interrupt occurred and was then disabled. However, I am certain that my interrupt is running normally and has not been disabled.
My program behaves exactly as I intended, but I want to understand why this error message occurs or if there is anything I can do to eliminate the error. I don't really like the idea of leaving it there without understand the reason for the error.
If I remove the line that initially configures the timer channel for forced inactive mode the error goes away but then I cannot make sure the pin starts low before the first interrupt runs.
To guarantee that the pin starts low I am configuring the OC channel initially in forced inactive mode.
Code: Select all
TIM2 = Timer(2, period=0x7FFFFFFF, prescaler=79)
T2CH1 = TIM2.channel(1, pin=Pin.cpu.A5, mode=Timer.OC_FORCED_INACTIVE, polarity=Timer.HIGH, callback=None)
Code: Select all
T2CH1 = TIM2.channel(1, pin=Pin.cpu.A5, mode=Timer.OC_TOGGLE, callback=OC_CB, polarity=Timer.HIGH, compare=(TIM2.counter() + 2000000)&0x7FFFFFFF)
Code: Select all
unhandled interrupt SR=0x04 (now disabled)
If I remove the line that initially configures the timer channel for forced inactive mode the error goes away but then I cannot make sure the pin starts low before the first interrupt runs.