From a884e3b53702805d859d7578cf136e39d2bfb22f Mon Sep 17 00:00:00 2001 From: Erwan Gouriou Date: Wed, 16 Jul 2025 16:30:43 +0200 Subject: [PATCH] drivers: timer: stm32 lptim: Fix the st,timeout runtime check Existing check failed on correct settings. Add an assert to fasten the debug. Signed-off-by: Erwan Gouriou --- drivers/timer/stm32_lptim_timer.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/timer/stm32_lptim_timer.c b/drivers/timer/stm32_lptim_timer.c index fc99a14bb7d..ed57b4e5def 100644 --- a/drivers/timer/stm32_lptim_timer.c +++ b/drivers/timer/stm32_lptim_timer.c @@ -456,15 +456,13 @@ static int sys_clock_driver_init(void) #if DT_PROP(DT_NODELABEL(stm32_lp_tick_source), st_timeout) uint32_t timeout = DT_PROP(DT_NODELABEL(stm32_lp_tick_source), st_timeout); - /* - * Check if prescaler corresponding to st,timeout - * is matching the lptim_clock_presc calculated one from the lptim_clock_freq - * max lptim period is 0xFFFF/(lptim_clock_freq/lptim_clock_presc) - */ - if (timeout > (lptim_clock_presc / lptim_clock_freq) * 0xFFFF) { + if (timeout > (lptim_clock_presc * 0xFFFF) / lptim_clock_freq) { + __ASSERT(0, + "st,timeout can't be higher than range defined by LPTIM presc and freq"); return -EIO; } + /* * Define the lptim_time_base that should be set to expire at "timeout" seconds * running counter at (lptim_clock_freq divided by lptim_clock_presc) Hz