Skip to content

Commit 418ec8b

Browse files
committed
stmhal: Properly deinit timer object.
Addresses issue adafruit#1113.
1 parent 192d536 commit 418ec8b

1 file changed

Lines changed: 4 additions & 7 deletions

File tree

stmhal/timer.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -668,12 +668,7 @@ STATIC mp_obj_t pyb_timer_init(mp_uint_t n_args, const mp_obj_t *args, mp_map_t
668668
}
669669
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_timer_init_obj, 1, pyb_timer_init);
670670

671-
/// \method deinit()
672-
/// Deinitialises the timer.
673-
///
674-
/// Disables the callback (and the associated irq).
675-
/// Disables any channel callbacks (and the associated irq).
676-
/// Stops the timer, and disables the timer peripheral.
671+
// timer.deinit()
677672
STATIC mp_obj_t pyb_timer_deinit(mp_obj_t self_in) {
678673
pyb_timer_obj_t *self = self_in;
679674

@@ -691,7 +686,9 @@ STATIC mp_obj_t pyb_timer_deinit(mp_obj_t self_in) {
691686
prev_chan->next = NULL;
692687
}
693688

694-
HAL_TIM_Base_DeInit(&self->tim);
689+
self->tim.Instance->CCER = 0x0000; // disable all capture/compare outputs
690+
self->tim.Instance->CR1 = 0x0000; // disable the timer and reset its state
691+
695692
return mp_const_none;
696693
}
697694
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_timer_deinit_obj, pyb_timer_deinit);

0 commit comments

Comments
 (0)