From 0856e9915500e2138772a5553ceabc2e6d78b7d0 Mon Sep 17 00:00:00 2001 From: Francois Ramu Date: Thu, 4 Jun 2020 16:57:12 +0200 Subject: [PATCH] drivers: timer: stm32 lptim stops counting on timeout FOREVER When setting a timeout K_TICKS_FOREVER,the lptimer clock is stopped (no reset of the lptim). Then is the lptim possibly re-started when another source asks for. The lptim clock must then be re-started and continue counting. This is the case when wakeup from sleep mode, for example. Signed-off-by: Francois Ramu --- drivers/timer/stm32_lptim_timer.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/timer/stm32_lptim_timer.c b/drivers/timer/stm32_lptim_timer.c index 17cb7735e71..51cf92d8b2d 100644 --- a/drivers/timer/stm32_lptim_timer.c +++ b/drivers/timer/stm32_lptim_timer.c @@ -178,12 +178,16 @@ void z_clock_set_timeout(int32_t ticks, bool idle) } if (ticks == K_TICKS_FOREVER) { - /* disable LPTIM */ - LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_LPTIM1); + /* disable LPTIM clock to avoid counting */ LL_APB1_GRP1_DisableClock(LL_APB1_GRP1_PERIPH_LPTIM1); return; } + /* if LPTIM clock was previously stopped, it must now be restored */ + if (!LL_APB1_GRP1_IsEnabledClock(LL_APB1_GRP1_PERIPH_LPTIM1)) { + LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_LPTIM1); + } + /* passing ticks==1 means "announce the next tick", * ticks value of zero (or even negative) is legal and * treated identically: it simply indicates the kernel would like the