Skip to content

Commit 1f3887d

Browse files
HenrikSolverdpgeorge
authored andcommitted
stmhal/timer: Clear interrupt flag before setting callback.
Sometimes when setting a channel callback the callback fires immediately, even if the compare register is set to a value far into the future. This happens when the free running counter has previously been equal to what happens to be in the compare register. This patch make sure that there is no pending interrupt when setting a callback.
1 parent c7c14f1 commit 1f3887d

1 file changed

Lines changed: 1 addition & 0 deletions

File tree

stmhal/timer.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,6 +1302,7 @@ STATIC mp_obj_t pyb_timer_channel_callback(mp_obj_t self_in, mp_obj_t callback)
13021302
} else if (mp_obj_is_callable(callback)) {
13031303
self->callback = callback;
13041304
uint8_t tim_id = self->timer->tim_id;
1305+
__HAL_TIM_CLEAR_IT(&self->timer->tim, TIMER_IRQ_MASK(self->channel));
13051306
if (tim_id == 1) {
13061307
HAL_NVIC_EnableIRQ(TIM1_CC_IRQn);
13071308
#if defined(TIM8) // STM32F401 doesn't have a TIM8

0 commit comments

Comments
 (0)