@@ -145,9 +145,6 @@ void lp_ticker_init(void)
145
145
146
146
__HAL_LPTIM_ENABLE_IT (& LptimHandle , LPTIM_IT_CMPM );
147
147
HAL_LPTIM_Counter_Start (& LptimHandle , 0xFFFF );
148
-
149
- /* Need to write a compare value in order to get LPTIM_FLAG_CMPOK in set_interrupt */
150
- __HAL_LPTIM_COMPARE_SET (& LptimHandle , 0 );
151
148
}
152
149
153
150
static void LPTIM1_IRQHandler (void )
@@ -194,21 +191,22 @@ void lp_ticker_set_interrupt(timestamp_t timestamp)
194
191
LptimHandle .Instance = LPTIM1 ;
195
192
irq_handler = (void (* )(void ))lp_ticker_irq_handler ;
196
193
194
+ __HAL_LPTIM_CLEAR_FLAG (& LptimHandle , LPTIM_FLAG_CMPOK );
195
+ __HAL_LPTIM_COMPARE_SET (& LptimHandle , timestamp );
197
196
/* CMPOK is set by hardware to inform application that the APB bus write operation to the LPTIM_CMP register has been successfully completed */
198
197
/* Any successive write before the CMPOK flag be set, will lead to unpredictable results */
199
198
while (__HAL_LPTIM_GET_FLAG (& LptimHandle , LPTIM_FLAG_CMPOK ) == RESET ) {
200
199
}
201
200
202
- __HAL_LPTIM_CLEAR_FLAG (& LptimHandle , LPTIM_FLAG_CMPOK );
203
- __HAL_LPTIM_CLEAR_FLAG (& LptimHandle , LPTIM_FLAG_CMPM );
204
- __HAL_LPTIM_COMPARE_SET (& LptimHandle , timestamp );
201
+ lp_ticker_clear_interrupt ();
205
202
206
203
NVIC_EnableIRQ (LPTIM1_IRQn );
207
204
}
208
205
209
206
void lp_ticker_fire_interrupt (void )
210
207
{
211
208
lp_Fired = 1 ;
209
+ irq_handler = (void (* )(void ))lp_ticker_irq_handler ;
212
210
NVIC_SetPendingIRQ (LPTIM1_IRQn );
213
211
NVIC_EnableIRQ (LPTIM1_IRQn );
214
212
}
@@ -217,9 +215,6 @@ void lp_ticker_disable_interrupt(void)
217
215
{
218
216
NVIC_DisableIRQ (LPTIM1_IRQn );
219
217
LptimHandle .Instance = LPTIM1 ;
220
- /* Waiting last write operation completion */
221
- while (__HAL_LPTIM_GET_FLAG (& LptimHandle , LPTIM_FLAG_CMPOK ) == RESET ) {
222
- }
223
218
}
224
219
225
220
void lp_ticker_clear_interrupt (void )
@@ -263,7 +258,6 @@ uint32_t lp_ticker_read(void)
263
258
264
259
void lp_ticker_set_interrupt (timestamp_t timestamp )
265
260
{
266
- lp_ticker_disable_interrupt ();
267
261
rtc_set_wake_up_timer (timestamp );
268
262
}
269
263
0 commit comments