@@ -60,18 +60,11 @@ static void (*irq_handler)(void);
60
60
61
61
void lp_ticker_init (void )
62
62
{
63
- NVIC_DisableIRQ (LPTIM1_IRQn );
64
-
65
63
/* 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
71
64
if (__HAL_RCC_LPTIM1_IS_CLK_ENABLED ()) {
65
+ lp_ticker_disable_interrupt ();
72
66
return ;
73
67
}
74
- #endif
75
68
76
69
RCC_PeriphCLKInitTypeDef RCC_PeriphCLKInitStruct = {0 };
77
70
RCC_OscInitTypeDef RCC_OscInitStruct = {0 };
@@ -153,6 +146,7 @@ void lp_ticker_init(void)
153
146
__HAL_LPTIM_ENABLE_IT (& LptimHandle , LPTIM_IT_CMPM );
154
147
HAL_LPTIM_Counter_Start (& LptimHandle , 0xFFFF );
155
148
149
+ /* Need to write a compare value in order to get LPTIM_FLAG_CMPOK in set_interrupt */
156
150
__HAL_LPTIM_COMPARE_SET (& LptimHandle , 0 );
157
151
}
158
152
@@ -201,7 +195,7 @@ void lp_ticker_set_interrupt(timestamp_t timestamp)
201
195
irq_handler = (void (* )(void ))lp_ticker_irq_handler ;
202
196
203
197
/* 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 */
205
199
while (__HAL_LPTIM_GET_FLAG (& LptimHandle , LPTIM_FLAG_CMPOK ) == RESET ) {
206
200
}
207
201
@@ -221,8 +215,11 @@ void lp_ticker_fire_interrupt(void)
221
215
222
216
void lp_ticker_disable_interrupt (void )
223
217
{
224
- LptimHandle .Instance = LPTIM1 ;
225
218
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
+ }
226
223
}
227
224
228
225
void lp_ticker_clear_interrupt (void )
0 commit comments