drivers: timer: stm32_lptim: Change clock source config check sanction

A specific check is implemented lptim driver in order to ensure global
platform clock/tick configuration is in line with recommendations.
To respect portability principles, don't error out when a config
conflict is detected but generates a warning instead.
Also, since these are only recommendations, provide an option to override
the check. Besides automatically override when ZTEST is enabled, as some
kernel tests specifically configure tick freq to 100.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
This commit is contained in:
Erwan Gouriou 2022-09-13 10:45:28 +02:00 committed by Fabio Baltieri
parent bafc258025
commit 2d740d42e0
2 changed files with 23 additions and 9 deletions

View file

@ -44,4 +44,16 @@ config STM32_LPTIM_TIMEBASE
default 0xFFFF if STM32_LPTIM_CLOCK_LSE
default 0xF9FF if STM32_LPTIM_CLOCK_LSI
config STM32_LPTIM_TICK_FREQ_RATIO_OVERRIDE
bool "Override tick to freq ratio check"
default y if ZTEST
help
For LPTIM configuration, a specific tick freq is advised
depending on LPTIM input clock:
- LSI(32KHz): 4000 ticks/sec
- LSE(32678): 4096 ticks/sec
To prevent misconfigurations, a dedicated check is implemented
in the driver.
This options allows to override this check
endif # STM32_LPTIM_TIMER

View file

@ -74,6 +74,17 @@ static bool autoreload_ready = true;
static struct k_spinlock lock;
/* For tick accuracy, a specific tick to freq ratio is expected */
/* This check assumes LSI@32KHz or LSE@32768Hz */
#if !defined(CONFIG_STM32_LPTIM_TICK_FREQ_RATIO_OVERRIDE)
#if (((DT_CLOCKS_CELL_BY_IDX(DT_DRV_INST(0), 1, bus) == STM32_SRC_LSI) && \
(CONFIG_SYS_CLOCK_TICKS_PER_SEC != 4000)) || \
((DT_CLOCKS_CELL_BY_IDX(DT_DRV_INST(0), 1, bus) == STM32_SRC_LSE) && \
(CONFIG_SYS_CLOCK_TICKS_PER_SEC != 4096)))
#warning Advised tick freq is 4096 for LSE / 4000 for LSI
#endif
#endif /* !CONFIG_STM32_LPTIM_TICK_FREQ_RATIO_OVERRIDE */
static void lptim_irq_handler(const struct device *unused)
{
@ -303,15 +314,6 @@ 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 */
err = clock_control_configure(clk_ctrl,
(clock_control_subsys_t *) &lptim_clk[1],