瀏覽代碼

Merge pull request #3260 from HubertXie/master

[bsp][stm32] fix the hardware timer issue
Bernard Xiong 5 年之前
父節點
當前提交
4b27738264
共有 1 個文件被更改,包括 5 次插入0 次删除
  1. 5 0
      bsp/stm32/libraries/HAL_Drivers/drv_hwtimer.c

+ 5 - 0
bsp/stm32/libraries/HAL_Drivers/drv_hwtimer.c

@@ -228,6 +228,8 @@ static rt_err_t timer_start(rt_hwtimer_t *timer, rt_uint32_t t, rt_hwtimer_mode_
     tim = (TIM_HandleTypeDef *)timer->parent.user_data;
 
     /* set tim cnt */
+    __HAL_TIM_SET_COUNTER(tim, 0);
+    /* set tim arr */
     __HAL_TIM_SET_AUTORELOAD(tim, t - 1);
 
     if (opmode == HWTIMER_MODE_ONESHOT)
@@ -260,6 +262,9 @@ static void timer_stop(rt_hwtimer_t *timer)
 
     /* stop timer */
     HAL_TIM_Base_Stop_IT(tim);
+
+    /* set tim cnt */
+    __HAL_TIM_SET_COUNTER(tim, 0);
 }
 
 static rt_err_t timer_ctrl(rt_hwtimer_t *timer, rt_uint32_t cmd, void *arg)