Skip to content

Commit c1ebbdd

Browse files
committed
LP ticker workaround
There is an errata in LPTIM specification that explains that CMP Flag condition is not an exact match (COUNTER = MATCH) but rather a comparison (COUNTER >= MATCH). As a consequence the interrupt is firing early than expected when programing a timestamp after the 0xFFFF wrap-around. In order to work-around this issue, we implement the below work-around. In case timestamp is after the work-around, let's decide to program the CMP value to 0xFFFF, which is the wrap-around value. There would anyway be a wake-up at the time of wrap-around to let the OS update the system time. When the wrap-around interrupt happen, OS will check the current time and program again the timestamp to the proper value.
1 parent 9cc1caa commit c1ebbdd

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

targets/TARGET_STM/lp_ticker.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,15 @@ void lp_ticker_set_interrupt(timestamp_t timestamp)
226226
/* Any successive write before the CMPOK flag be set, will lead to unpredictable results */
227227
/* LPTICKER_DELAY_TICKS value prevents OS to call this set interrupt function before CMPOK */
228228
MBED_ASSERT(__HAL_LPTIM_GET_FLAG(&LptimHandle, LPTIM_FLAG_CMPOK) == SET);
229-
__HAL_LPTIM_CLEAR_FLAG(&LptimHandle, LPTIM_FLAG_CMPOK);
230-
__HAL_LPTIM_COMPARE_SET(&LptimHandle, timestamp);
229+
230+
if(timestamp < lp_ticker_read()) {
231+
/* Workaround, because limitation */
232+
__HAL_LPTIM_CLEAR_FLAG(&LptimHandle, LPTIM_FLAG_CMPOK);
233+
__HAL_LPTIM_COMPARE_SET(&LptimHandle, ~0);
234+
} else {
235+
__HAL_LPTIM_CLEAR_FLAG(&LptimHandle, LPTIM_FLAG_CMPOK);
236+
__HAL_LPTIM_COMPARE_SET(&LptimHandle, timestamp);
237+
}
231238

232239
lp_ticker_clear_interrupt();
233240

0 commit comments

Comments
 (0)