From f809e54d1aab73d91321054481dd6990630349f4 Mon Sep 17 00:00:00 2001 From: Alexandre Bourdiol Date: Wed, 9 Sep 2020 13:40:17 +0200 Subject: [PATCH] HardwareTimer: pause() need to call HAL API to restore HAL state Due to HAL Cube update (ex: for STM32L4 sha1 f41f10e) it is now required to stop timer with HAL API otherwise HAL state is not restored to HAL_TIM_STATE_READY, and it is not possible to resume() a HardwareTimer after a pause(). Nevertheless it is not sufficient to guarantee that timer is stopped specially if some channels are still running. So it is also necessary to keep also the call to LL_TIM_DisableCounter() Signed-off-by: Alexandre Bourdiol --- cores/arduino/HardwareTimer.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cores/arduino/HardwareTimer.cpp b/cores/arduino/HardwareTimer.cpp index 69d73cfa9e..5b50c272ec 100644 --- a/cores/arduino/HardwareTimer.cpp +++ b/cores/arduino/HardwareTimer.cpp @@ -108,7 +108,11 @@ void HardwareTimer::pause() __HAL_TIM_DISABLE_IT(&(_timerObj.handle), TIM_IT_CC3); __HAL_TIM_DISABLE_IT(&(_timerObj.handle), TIM_IT_CC4); - // Disable timer unconditionally + // Stop timer. Required to restore HAL State: HAL_TIM_STATE_READY + HAL_TIM_Base_Stop(&(_timerObj.handle)); + + /* Disable timer unconditionally. Required to guarantee timer is stopped, + * even if some channels are still running */ LL_TIM_DisableCounter(_timerObj.handle.Instance); #if defined(TIM_CHANNEL_STATE_SET_ALL)