diff options
| author | yn386 <wf.yn386@gmail.com> | 2022-09-01 18:08:18 +0900 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2022-09-06 16:35:46 +1000 |
| commit | 989b8c728b296969e6489908b8e94ed23625a1e8 (patch) | |
| tree | e2e29862003b7fa405c4affa5c5e59f799fd2212 | |
| parent | da50827657d6bc3024dd6acea76cb315d1cbbae1 (diff) | |
stm32/timer: Fix use of timer channel callback() method on L4 MCUs.
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.
| -rw-r--r-- | ports/stm32/timer.c | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/ports/stm32/timer.c b/ports/stm32/timer.c index 0cef60cb6..518a2e23b 100644 --- a/ports/stm32/timer.c +++ b/ports/stm32/timer.c @@ -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: @@ -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; } |
