@@ -60,18 +60,11 @@ static void (*irq_handler)(void);
6060
6161void lp_ticker_init (void )
6262{
63- NVIC_DisableIRQ (LPTIM1_IRQn );
64-
6563 /* Check if LPTIM is already configured */
66- #if (TARGET_STM32L0 )
67- if (READ_BIT (RCC -> APB1ENR , RCC_APB1ENR_LPTIM1EN ) != RESET ) {
68- return ;
69- }
70- #else
7164 if (__HAL_RCC_LPTIM1_IS_CLK_ENABLED ()) {
65+ lp_ticker_disable_interrupt ();
7266 return ;
7367 }
74- #endif
7568
7669 RCC_PeriphCLKInitTypeDef RCC_PeriphCLKInitStruct = {0 };
7770 RCC_OscInitTypeDef RCC_OscInitStruct = {0 };
@@ -153,6 +146,7 @@ void lp_ticker_init(void)
153146 __HAL_LPTIM_ENABLE_IT (& LptimHandle , LPTIM_IT_CMPM );
154147 HAL_LPTIM_Counter_Start (& LptimHandle , 0xFFFF );
155148
149+ /* Need to write a compare value in order to get LPTIM_FLAG_CMPOK in set_interrupt */
156150 __HAL_LPTIM_COMPARE_SET (& LptimHandle , 0 );
157151}
158152
@@ -201,7 +195,7 @@ void lp_ticker_set_interrupt(timestamp_t timestamp)
201195 irq_handler = (void (* )(void ))lp_ticker_irq_handler ;
202196
203197 /* CMPOK is set by hardware to inform application that the APB bus write operation to the LPTIM_CMP register has been successfully completed */
204- /* Any successive write before respectively the ARROK flag or the CMPOK flag be set, will lead to unpredictable results */
198+ /* Any successive write before the CMPOK flag be set, will lead to unpredictable results */
205199 while (__HAL_LPTIM_GET_FLAG (& LptimHandle , LPTIM_FLAG_CMPOK ) == RESET ) {
206200 }
207201
@@ -221,8 +215,11 @@ void lp_ticker_fire_interrupt(void)
221215
222216void lp_ticker_disable_interrupt (void )
223217{
224- LptimHandle .Instance = LPTIM1 ;
225218 NVIC_DisableIRQ (LPTIM1_IRQn );
219+ LptimHandle .Instance = LPTIM1 ;
220+ /* Waiting last write operation completion */
221+ while (__HAL_LPTIM_GET_FLAG (& LptimHandle , LPTIM_FLAG_CMPOK ) == RESET ) {
222+ }
226223}
227224
228225void lp_ticker_clear_interrupt (void )
0 commit comments