Skip to content

Commit ad397a6

Browse files
authored
[bsp][stm32]修复硬件定时器bug
1 parent aa52a30 commit ad397a6

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

bsp/stm32/libraries/HAL_Drivers/drv_hwtimer.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ static rt_err_t timer_start(rt_hwtimer_t *timer, rt_uint32_t t, rt_hwtimer_mode_
228228
tim = (TIM_HandleTypeDef *)timer->parent.user_data;
229229

230230
/* set tim cnt */
231+
__HAL_TIM_SET_COUNTER(tim, 0);
232+
/* set tim arr */
231233
__HAL_TIM_SET_AUTORELOAD(tim, t - 1);
232234

233235
if (opmode == HWTIMER_MODE_ONESHOT)
@@ -260,6 +262,9 @@ static void timer_stop(rt_hwtimer_t *timer)
260262

261263
/* stop timer */
262264
HAL_TIM_Base_Stop_IT(tim);
265+
266+
/* set tim cnt */
267+
__HAL_TIM_SET_COUNTER(tim, 0);
263268
}
264269

265270
static rt_err_t timer_ctrl(rt_hwtimer_t *timer, rt_uint32_t cmd, void *arg)

0 commit comments

Comments
 (0)