8000 stm32/timer: Fix use of timer channel callback() method on L4 MCUs. · lowfatcode/micropython@989b8c7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 989b8c7

Browse files
yn386dpgeorge
authored andcommitted
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 micropython#8732.
1 parent da50827 commit 989b8c7

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

ports/stm32/timer.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,6 +1576,7 @@ STATIC mp_obj_t pyb_timer_channel_callback(mp_obj_t self_in, mp_obj_t callback)
15761576
switch (self->mode) {
15771577
case CHANNEL_MODE_PWM_NORMAL:
15781578
case CHANNEL_MODE_PWM_INVERTED:
1579+
HAL_TIM_PWM_Stop_IT(&self->timer->tim, TIMER_CHANNEL(self));
15791580
HAL_TIM_PWM_Start_IT(&self->timer->tim, TIMER_CHANNEL(self));
15801581
break;
15811582
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)
15841585
case CHANNEL_MODE_OC_TOGGLE:
15851586
case CHANNEL_MODE_OC_FORCED_ACTIVE:
15861587
case CHANNEL_MODE_OC_FORCED_INACTIVE:
1588+
HAL_TIM_OC_Stop_IT(&self->timer->tim, TIMER_CHANNEL(self));
15871589
HAL_TIM_OC_Start_IT(&self->timer->tim, TIMER_CHANNEL(self));
15881590
break;
15891591
case CHANNEL_MODE_IC:
1592+
HAL_TIM_IC_Stop_IT(&self->timer->tim, TIMER_CHANNEL(self));
15901593
HAL_TIM_IC_Start_IT(&self->timer->tim, TIMER_CHANNEL(self));
15911594
break;
15921595
}

0 commit comments

Comments
 (0)
0