From 3d0acbc866ea8de353b12a49aff5f1870a9de30a Mon Sep 17 00:00:00 2001 From: jeromecoutant Date: Wed, 19 Sep 2018 14:17:30 +0200 Subject: [PATCH] STM32 LPTICKER with LPTIM : Fix tickless and lp wrapper This fixes issue with mbed_hal/lp_ticker/lp_ticker_early_match_race_test --- targets/TARGET_STM/lp_ticker.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/targets/TARGET_STM/lp_ticker.c b/targets/TARGET_STM/lp_ticker.c index f4df8b776f..517ed924fe 100644 --- a/targets/TARGET_STM/lp_ticker.c +++ b/targets/TARGET_STM/lp_ticker.c @@ -145,9 +145,6 @@ void lp_ticker_init(void) __HAL_LPTIM_ENABLE_IT(&LptimHandle, LPTIM_IT_CMPM); HAL_LPTIM_Counter_Start(&LptimHandle, 0xFFFF); - - /* Need to write a compare value in order to get LPTIM_FLAG_CMPOK in set_interrupt */ - __HAL_LPTIM_COMPARE_SET(&LptimHandle, 0); } static void LPTIM1_IRQHandler(void) @@ -194,14 +191,14 @@ void lp_ticker_set_interrupt(timestamp_t timestamp) LptimHandle.Instance = LPTIM1; irq_handler = (void (*)(void))lp_ticker_irq_handler; + __HAL_LPTIM_CLEAR_FLAG(&LptimHandle, LPTIM_FLAG_CMPOK); + __HAL_LPTIM_COMPARE_SET(&LptimHandle, timestamp); /* CMPOK is set by hardware to inform application that the APB bus write operation to the LPTIM_CMP register has been successfully completed */ /* Any successive write before the CMPOK flag be set, will lead to unpredictable results */ while (__HAL_LPTIM_GET_FLAG(&LptimHandle, LPTIM_FLAG_CMPOK) == RESET) { } - __HAL_LPTIM_CLEAR_FLAG(&LptimHandle, LPTIM_FLAG_CMPOK); - __HAL_LPTIM_CLEAR_FLAG(&LptimHandle, LPTIM_FLAG_CMPM); - __HAL_LPTIM_COMPARE_SET(&LptimHandle, timestamp); + lp_ticker_clear_interrupt(); NVIC_EnableIRQ(LPTIM1_IRQn); } @@ -209,6 +206,7 @@ void lp_ticker_set_interrupt(timestamp_t timestamp) void lp_ticker_fire_interrupt(void) { lp_Fired = 1; + irq_handler = (void (*)(void))lp_ticker_irq_handler; NVIC_SetPendingIRQ(LPTIM1_IRQn); NVIC_EnableIRQ(LPTIM1_IRQn); } @@ -217,9 +215,6 @@ void lp_ticker_disable_interrupt(void) { NVIC_DisableIRQ(LPTIM1_IRQn); LptimHandle.Instance = LPTIM1; - /* Waiting last write operation completion */ - while (__HAL_LPTIM_GET_FLAG(&LptimHandle, LPTIM_FLAG_CMPOK) == RESET) { - } } void lp_ticker_clear_interrupt(void)