Skip to content

Commit b1d23e5

Browse files
committed
STM32 LPTICKER with LPTIM : Fix tickless and lp wrapper
This fixes issue with mbed_hal/lp_ticker/lp_ticker_early_match_race_test
1 parent 45f59f8 commit b1d23e5

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

targets/TARGET_STM/lp_ticker.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,6 @@ void lp_ticker_init(void)
145145

146146
__HAL_LPTIM_ENABLE_IT(&LptimHandle, LPTIM_IT_CMPM);
147147
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);
151148
}
152149

153150
static void LPTIM1_IRQHandler(void)
@@ -194,21 +191,22 @@ void lp_ticker_set_interrupt(timestamp_t timestamp)
194191
LptimHandle.Instance = LPTIM1;
195192
irq_handler = (void (*)(void))lp_ticker_irq_handler;
196193

194+
__HAL_LPTIM_CLEAR_FLAG(&LptimHandle, LPTIM_FLAG_CMPOK);
195+
__HAL_LPTIM_COMPARE_SET(&LptimHandle, timestamp);
197196
/* CMPOK is set by hardware to inform application that the APB bus write operation to the LPTIM_CMP register has been successfully completed */
198197
/* Any successive write before the CMPOK flag be set, will lead to unpredictable results */
199198
while (__HAL_LPTIM_GET_FLAG(&LptimHandle, LPTIM_FLAG_CMPOK) == RESET) {
200199
}
201200

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();
205202

206203
NVIC_EnableIRQ(LPTIM1_IRQn);
207204
}
208205

209206
void lp_ticker_fire_interrupt(void)
210207
{
211208
lp_Fired = 1;
209+
irq_handler = (void (*)(void))lp_ticker_irq_handler;
212210
NVIC_SetPendingIRQ(LPTIM1_IRQn);
213211
NVIC_EnableIRQ(LPTIM1_IRQn);
214212
}
@@ -217,9 +215,6 @@ void lp_ticker_disable_interrupt(void)
217215
{
218216
NVIC_DisableIRQ(LPTIM1_IRQn);
219217
LptimHandle.Instance = LPTIM1;
220-
/* Waiting last write operation completion */
221-
while (__HAL_LPTIM_GET_FLAG(&LptimHandle, LPTIM_FLAG_CMPOK) == RESET) {
222-
}
223218
}
224219

225220
void lp_ticker_clear_interrupt(void)

0 commit comments

Comments
 (0)