Added guard against starting a hal_timer multiple times.
@@ -525,10 +525,15 @@ hal_timer_set_cb(int num, struct hal_timer *timer, hal_timer_cb cb_func,
if (num >= STM32F3_HAL_TIMER_MAX || !(tmr = stm32f3_tmr_devs[num])) {
return -1;
}
+
+ /* make sure user doesn't use timer already in use */
+ if (timer->link.tqe_prev != NULL) {
+ return -1;
+ }
+
timer->cb_func = cb_func;
timer->cb_arg = arg;
timer->bsp_timer = tmr;
- timer->link.tqe_prev = NULL;
return 0;
}
@@ -571,7 +576,9 @@ hal_timer_start_at(struct hal_timer *timer, uint32_t tick)
struct stm32f3_hal_tmr *tmr;
struct hal_timer *ht;
int sr;
+ int rc;
+ if (timer->link.tqe_prev == NULL) {
tmr = (struct stm32f3_hal_tmr *)timer->bsp_timer;
timer->expiry = tick;
@@ -606,8 +613,12 @@ hal_timer_start_at(struct hal_timer *timer, uint32_t tick)
}
}
__HAL_ENABLE_INTERRUPTS(sr);
+ rc = 0;
+ } else {
+ rc = -1;
+ }
- return 0;
+ return rc;
}
/**
