drivers: timer: stm32: Adapt SYS_CLOCK_TICKS_PER_SEC

When using LPTIM as tick source, tick freq (SYS_CLOCK_TICKS_PER_SEC)
needs to be adapted to get a precise tick to LPTIM freq ratio.

This adaptation was done easily using Kconfig up to now (under
soc/st_stm32/common/Kconfig.defconfig.series).
Since driver is configured using device tree, this method should
be adapted. For the LSI case (default Kconfig case), rely on the
existing mecanism, which is also still used by OOT users.
For the LSE case, force the value manually in boards forlder.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
This commit is contained in:
Erwan Gouriou 2022-08-23 14:00:49 +02:00 committed by Fabio Baltieri
commit 16c11138d5
6 changed files with 28 additions and 0 deletions

View file

@ -298,6 +298,15 @@ static int sys_clock_driver_init(const struct device *dev)
LL_SRDAMR_GRP1_EnableAutonomousClock(LL_SRDAMR_GRP1_PERIPH_LPTIM1AMEN);
#endif
/* For tick accuracy, a specific tick to freq ratio is expected */
/* This check assumes LSI@32KHz or LSE@32768Hz */
if (((lptim_clk[1].bus == STM32_SRC_LSI) &&
(CONFIG_SYS_CLOCK_TICKS_PER_SEC == 4000)) ||
((lptim_clk[1].bus == STM32_SRC_LSE) &&
(CONFIG_SYS_CLOCK_TICKS_PER_SEC == 4096))) {
return -ENOTSUP;
}
/* Enable LPTIM clock source */
clock_control_configure(clk_ctrl, (clock_control_subsys_t *) &lptim_clk[1],
NULL);