From e81926e350e969b4450728975d5856e8cfc5d497 Mon Sep 17 00:00:00 2001 From: Marian Buschsieweke Date: Thu, 24 Nov 2022 15:03:10 +0100 Subject: [PATCH] cpu/nrf5x_common/periph_timer: fix spurious IRQs (cherry picked from commit fbd7b77331caf24b04aab5be7104d3bc81c3ec3d) --- cpu/nrf5x_common/periph/timer.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cpu/nrf5x_common/periph/timer.c b/cpu/nrf5x_common/periph/timer.c index 2ad3559d88873..e7d9cdb79c504 100644 --- a/cpu/nrf5x_common/periph/timer.c +++ b/cpu/nrf5x_common/periph/timer.c @@ -102,6 +102,12 @@ int timer_set_absolute(tim_t tim, int chan, unsigned int value) ctx[tim].flags |= (1 << chan); dev(tim)->CC[chan] = value; + + /* clear spurious IRQs */ + dev(tim)->EVENTS_COMPARE[chan] = 0; + (void)dev(tim)->EVENTS_COMPARE[chan]; + + /* enable IRQ */ dev(tim)->INTENSET = (TIMER_INTENSET_COMPARE0_Msk << chan); return 0; @@ -126,6 +132,12 @@ int timer_set_periodic(tim_t tim, int chan, unsigned int value, uint8_t flags) if (flags & TIM_FLAG_RESET_ON_SET) { dev(tim)->TASKS_CLEAR = 1; } + + /* clear spurious IRQs */ + dev(tim)->EVENTS_COMPARE[chan] = 0; + (void)dev(tim)->EVENTS_COMPARE[chan]; + + /* enable IRQ */ dev(tim)->INTENSET = (TIMER_INTENSET_COMPARE0_Msk << chan); /* re-start timer */