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.
pull/2033/merge
Henrik Sölver 2017-04-13 21:38:17 +02:00 zatwierdzone przez Damien George
rodzic c7c14f1634
commit 1f3887dc28
1 zmienionych plików z 1 dodań i 0 usunięć

Wyświetl plik

@ -1302,6 +1302,7 @@ STATIC mp_obj_t pyb_timer_channel_callback(mp_obj_t self_in, mp_obj_t callback)
} else if (mp_obj_is_callable(callback)) {
self->callback = callback;
uint8_t tim_id = self->timer->tim_id;
__HAL_TIM_CLEAR_IT(&self->timer->tim, TIMER_IRQ_MASK(self->channel));
if (tim_id == 1) {
HAL_NVIC_EnableIRQ(TIM1_CC_IRQn);
#if defined(TIM8) // STM32F401 doesn't have a TIM8