Skip to content

Commit

Permalink
cpu/stm32/periph/timer: prevnt spurious IRQs
Browse files Browse the repository at this point in the history
This patch hardens the STM32 timer driver against some possible causes
of spurious IRQs.
  • Loading branch information
Enoch247 committed Oct 18, 2024
1 parent 5b23bfb commit 4e357d4
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions cpu/stm32/periph/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,13 @@ int timer_set(tim_t tim, int channel, unsigned int timeout)
}
#endif

/* clear spurious IRQs */
dev(tim)->SR &= ~(TIM_SR_CC1IF << channel);

TIM_CHAN(tim, channel) = value;

/* clear spurious IRQs
* note: This might also clear the IRQ just set, but that is handled below
* anyway. */
dev(tim)->SR &= ~(TIM_SR_CC1IF << channel);

/* enable IRQ */
dev(tim)->DIER |= (TIM_DIER_CC1IE << channel);

Expand Down Expand Up @@ -264,7 +266,13 @@ int timer_clear(tim_t tim, int channel)
}

unsigned irqstate = irq_disable();

/* disable IRQ */
dev(tim)->DIER &= ~(TIM_DIER_CC1IE << channel);

/* clear spurious IRQs */
dev(tim)->SR &= ~(TIM_SR_CC1IF << channel);

irq_restore(irqstate);

#ifdef MODULE_PERIPH_TIMER_PERIODIC
Expand Down

0 comments on commit 4e357d4

Please sign in to comment.