diff --git a/examples/stm32/stm32-h103/pwm_6step/pwm_6step.c b/examples/stm32/stm32-h103/pwm_6step/pwm_6step.c index 9c04c9bd..cf53ac64 100644 --- a/examples/stm32/stm32-h103/pwm_6step/pwm_6step.c +++ b/examples/stm32/stm32-h103/pwm_6step/pwm_6step.c @@ -253,7 +253,8 @@ void tim1_trg_com_isr(void) { static int step = 0; - TIM1_SR &= ~TIM_SR_COMIF; + /* Clear the COM trigger interrupt flag. */ + timer_clear_flag(TIM1, TIM_SR_COMIF); /* A simplified and inefficient implementation of PWM On * scheme. Look at the implementation in Open-BLDC on diff --git a/include/libopencm3/stm32/timer.h b/include/libopencm3/stm32/timer.h index 5d1c2357..c3bc1957 100644 --- a/include/libopencm3/stm32/timer.h +++ b/include/libopencm3/stm32/timer.h @@ -854,6 +854,7 @@ enum tim_oc_mode { /* --- TIM functions ------------------------------------------------------- */ void timer_enable_irq(u32 timer_peripheral, u32 irq); void timer_disable_irq(u32 timer_peripheral, u32 irq); +void timer_clear_flag(u32 timer_peripheral, u32 flag); void timer_set_mode(u32 timer_peripheral, u8 clock_div, u8 alignment, u8 direction); void timer_set_clock_division(u32 timer_peripheral, u32 clock_div); diff --git a/lib/stm32/timer.c b/lib/stm32/timer.c index 15e3b148..8c612ed5 100644 --- a/lib/stm32/timer.c +++ b/lib/stm32/timer.c @@ -37,6 +37,11 @@ void timer_disable_irq(u32 timer_peripheral, u32 irq) TIM_DIER(timer_peripheral) &= ~irq; } +void timer_clear_flag(u32 timer_peripheral, u32 flag) +{ + TIM_SR(timer_peripheral) &= ~flag; +} + void timer_set_mode(u32 timer_peripheral, u8 clock_div, u8 alignment, u8 direction) {