From 1ec222f26828ce92e8e85c3434219f23459ea647 Mon Sep 17 00:00:00 2001 From: jeromecoutant Date: Fri, 16 Nov 2018 13:20:12 +0100 Subject: [PATCH] STM32 LPTICKER with LPTIM : reduce clock feature --- targets/TARGET_STM/lp_ticker.c | 14 ++++++++++++-- targets/targets.json | 4 ++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/targets/TARGET_STM/lp_ticker.c b/targets/TARGET_STM/lp_ticker.c index 0d0caa97935..aee7229eb01 100644 --- a/targets/TARGET_STM/lp_ticker.c +++ b/targets/TARGET_STM/lp_ticker.c @@ -44,9 +44,9 @@ const ticker_info_t *lp_ticker_get_info() { static const ticker_info_t info = { #if MBED_CONF_TARGET_LSE_AVAILABLE - LSE_VALUE, + LSE_VALUE / MBED_CONF_TARGET_LPTICKER_LPTIM_CLOCK, #else - LSI_VALUE, + LSI_VALUE / MBED_CONF_TARGET_LPTICKER_LPTIM_CLOCK, #endif 16 }; @@ -119,7 +119,17 @@ void lp_ticker_init(void) LptimHandle.Instance = LPTIM1; LptimHandle.State = HAL_LPTIM_STATE_RESET; LptimHandle.Init.Clock.Source = LPTIM_CLOCKSOURCE_APBCLOCK_LPOSC; +#if defined(MBED_CONF_TARGET_LPTICKER_LPTIM_CLOCK) +#if (MBED_CONF_TARGET_LPTICKER_LPTIM_CLOCK == 4) + LptimHandle.Init.Clock.Prescaler = LPTIM_PRESCALER_DIV4; +#elif (MBED_CONF_TARGET_LPTICKER_LPTIM_CLOCK == 2) + LptimHandle.Init.Clock.Prescaler = LPTIM_PRESCALER_DIV2; +#else + LptimHandle.Init.Clock.Prescaler = LPTIM_PRESCALER_DIV1; +#endif +#else LptimHandle.Init.Clock.Prescaler = LPTIM_PRESCALER_DIV1; +#endif /* MBED_CONF_TARGET_LPTICKER_LPTIM_CLOCK */ LptimHandle.Init.Trigger.Source = LPTIM_TRIGSOURCE_SOFTWARE; LptimHandle.Init.OutputPolarity = LPTIM_OUTPUTPOLARITY_HIGH; diff --git a/targets/targets.json b/targets/targets.json index 59ca71778fe..cf1624f9cbb 100644 --- a/targets/targets.json +++ b/targets/targets.json @@ -1712,6 +1712,10 @@ "help": "https://os.mbed.com/docs/latest/porting/low-power-ticker.html", "value": 1, "macro_name": "LPTICKER_DELAY_TICKS" + }, + "lpticker_lptim_clock": { + "help": "Default value for LPTIM clock (lpticker_lptim == 1). Value is the dividing factor. Choose 1, 2 or 4", + "value": 1 } }, "device_has": [