diff options
| author | Dave Hylands | 2015-02-22 19:58:51 -0800 |
|---|---|---|
| committer | Dave Hylands | 2015-02-22 19:58:51 -0800 |
| commit | caf5c40c1932ff5f0dfd6a6b3cef870ffba13180 (patch) | |
| tree | 5f41360533ca37f006ab9a7311f98cc4afb8e486 | |
| parent | 44bb616b538ee8359fa128bec0c474b888709604 (diff) | |
stmhal: Fix problem when passing callback= to timer init function.
In particular, make sure that the globals are all initialized
before enabling the interrupt, and also make sure that the timer
interrupt has been initialied before enabling the NVIC.
| -rw-r--r-- | stmhal/timer.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/stmhal/timer.c b/stmhal/timer.c index e8ea33e68..ffc931e9d 100644 --- a/stmhal/timer.c +++ b/stmhal/timer.c @@ -648,6 +648,11 @@ STATIC mp_obj_t pyb_timer_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t default: nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Timer %d does not exist", tim->tim_id)); } + // set the global variable for interrupt callbacks + if (tim->tim_id - 1 < PYB_TIMER_OBJ_ALL_NUM) { + MP_STATE_PORT(pyb_timer_obj_all)[tim->tim_id - 1] = tim; + } + if (n_args > 1 || n_kw > 0) { // start the peripheral mp_map_t kw_args; @@ -655,11 +660,6 @@ STATIC mp_obj_t pyb_timer_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t pyb_timer_init_helper(tim, n_args - 1, args + 1, &kw_args); } - // set the global variable for interrupt callbacks - if (tim->tim_id - 1 < PYB_TIMER_OBJ_ALL_NUM) { - MP_STATE_PORT(pyb_timer_obj_all)[tim->tim_id - 1] = tim; - } - return (mp_obj_t)tim; } @@ -1043,9 +1043,9 @@ STATIC mp_obj_t pyb_timer_callback(mp_obj_t self_in, mp_obj_t callback) { self->callback = mp_const_none; } else if (mp_obj_is_callable(callback)) { self->callback = callback; - HAL_NVIC_EnableIRQ(self->irqn); // start timer, so that it interrupts on overflow HAL_TIM_Base_Start_IT(&self->tim); + HAL_NVIC_EnableIRQ(self->irqn); } else { nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "callback must be None or a callable object")); } |
