From 01ff7ba6e16c989dd7a2a7e16549063fad4ccade Mon Sep 17 00:00:00 2001 From: Julien D'Ascenzio Date: Wed, 3 Jun 2020 13:55:57 +0200 Subject: [PATCH] driver: timer: stm32_lptim: fix deadlock when waiting ARROK flag If ticks is K_TICKS_FOREVER the register autoreload isn't set. So, on the next call to the z_clock_set_timeout function the wait for the flag ARROK will be infinite. Signed-off-by: Julien D'Ascenzio --- drivers/timer/stm32_lptim_timer.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/timer/stm32_lptim_timer.c b/drivers/timer/stm32_lptim_timer.c index f0ff4a7c62e..0b4cdad4f3d 100644 --- a/drivers/timer/stm32_lptim_timer.c +++ b/drivers/timer/stm32_lptim_timer.c @@ -183,11 +183,6 @@ void z_clock_set_timeout(s32_t ticks, bool idle) return; } - /* ARROK bit validates previous write operation to ARR register */ - while (LL_LPTIM_IsActiveFlag_ARROK(LPTIM1) == 0) { - } - LL_LPTIM_ClearFlag_ARROK(LPTIM1); - if (ticks == K_TICKS_FOREVER) { /* disable LPTIM */ LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_LPTIM1); @@ -242,6 +237,12 @@ void z_clock_set_timeout(s32_t ticks, bool idle) NVIC_SetPendingIRQ(LPTIM1_IRQn); lptim_fired = 1; } + + /* ARROK bit validates previous write operation to ARR register */ + while (LL_LPTIM_IsActiveFlag_ARROK(LPTIM1) == 0) { + } + LL_LPTIM_ClearFlag_ARROK(LPTIM1); + /* run timer and wait for the reload match */ LL_LPTIM_SetAutoReload(LPTIM1, next_arr);