Skip to content

Commit

Permalink
stm32/timer: Fix use of timer channel callback() method on L4 MCUs.
Browse files Browse the repository at this point in the history
Since L4 HAL version 1.17.0, HAL_TIM_IC_Start_IT() checks whether specified
channel of timer is busy or not, which is the case if this function is
called more than once without first calling HAL_TIM_IC_Stop_IT().  The fix
in this commit is to call the stop function before calling start.  The PWM
and OC modes have the same issue with the same fix.

Fixes issue #8732.
  • Loading branch information
yn386 authored and dpgeorge committed Sep 6, 2022
1 parent da50827 commit 989b8c7
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ports/stm32/timer.c
Expand Up @@ -1576,6 +1576,7 @@ STATIC mp_obj_t pyb_timer_channel_callback(mp_obj_t self_in, mp_obj_t callback)
switch (self->mode) {
case CHANNEL_MODE_PWM_NORMAL:
case CHANNEL_MODE_PWM_INVERTED:
HAL_TIM_PWM_Stop_IT(&self->timer->tim, TIMER_CHANNEL(self));
HAL_TIM_PWM_Start_IT(&self->timer->tim, TIMER_CHANNEL(self));
break;
case CHANNEL_MODE_OC_TIMING:
Expand All @@ -1584,9 +1585,11 @@ STATIC mp_obj_t pyb_timer_channel_callback(mp_obj_t self_in, mp_obj_t callback)
case CHANNEL_MODE_OC_TOGGLE:
case CHANNEL_MODE_OC_FORCED_ACTIVE:
case CHANNEL_MODE_OC_FORCED_INACTIVE:
HAL_TIM_OC_Stop_IT(&self->timer->tim, TIMER_CHANNEL(self));
HAL_TIM_OC_Start_IT(&self->timer->tim, TIMER_CHANNEL(self));
break;
case CHANNEL_MODE_IC:
HAL_TIM_IC_Stop_IT(&self->timer->tim, TIMER_CHANNEL(self));
HAL_TIM_IC_Start_IT(&self->timer->tim, TIMER_CHANNEL(self));
break;
}
Expand Down

0 comments on commit 989b8c7

Please sign in to comment.