drivers: timer: stm32: Specific handling for L0 LSI

On L0 series, LSI runs at 37KHz while LPTIM driver only supports speeds
up to 32768Hz (to avoid counter overflow). Consequence is a time running
faster than reality (x1.13)
Solution to this is the implementation of the LPTIM prescaler support.

While moving driver configuration from Kconfig to DT, this case was
not taken into account and the effect was LPTIM counter overflow which
consequence is worse than the slightly faster timer.
Reproduce the initial behavior with this piece of code that will be
removed once prescaler support is available.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
This commit is contained in:
Erwan Gouriou 2022-08-23 14:15:34 +02:00 committed by Fabio Baltieri
commit 7f2cb0fd22

View file

@ -315,6 +315,19 @@ static int sys_clock_driver_init(const struct device *dev)
clock_control_get_rate(clk_ctrl, (clock_control_subsys_t *) &lptim_clk[1], clock_control_get_rate(clk_ctrl, (clock_control_subsys_t *) &lptim_clk[1],
&lptim_clock_freq); &lptim_clock_freq);
#if defined(CONFIG_SOC_SERIES_STM32L0X)
/* Driver only supports freqs up to 32768Hz. On L0, LSI freq is 37KHz,
* which will overflow the LPTIM counter.
* Previous LPTIM configuration using device tree was doing forcing this
* with a Kconfig default. Impact is that time is 1.13 faster than reality.
* Following lines reproduce this behavior in order not to change behavior.
* This issue will be fixed by implementation LPTIM prescaler support.
*/
if (lptim_clk[1].bus == STM32_SRC_LSI) {
lptim_clock_freq = KHZ(32);
}
#endif
/* Set LPTIM time base based on clck source freq /* Set LPTIM time base based on clck source freq
* Time base = (2s * freq) - 1 * Time base = (2s * freq) - 1
*/ */