Skip to content

Commit e725c63

Browse files
committed
tests-mbed_hal-sleep: add exception for STM LPTIM targets.
On some targets like STM family boards with LPTIM enabled an interrupt is triggered on counter rollover. We need special handling for cases when next_match_timestamp < start_timestamp (interrupt is to be fired after rollover). In such case after first wake-up we need to reset interrupt and go back to sleep waiting for the valid one. Background: 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 b21c278 commit e725c63

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

TESTS/mbed_hal/sleep/main.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,16 @@ void deepsleep_lpticker_test()
124124

125125
sleep();
126126

127+
/* On some targets like STM family boards with LPTIM enabled an interrupt is triggered on counter rollover.
128+
We need special handling for cases when next_match_timestamp < start_timestamp (interrupt is to be fired after rollover).
129+
In such case after first wake-up we need to reset interrupt and go back to sleep waiting for the valid one. */
130+
#if MBED_CONF_TARGET_LPTICKER_LPTIM
131+
if ((next_match_timestamp < start_timestamp) && lp_ticker_read() < next_match_timestamp) {
132+
lp_ticker_set_interrupt(next_match_timestamp);
133+
sleep();
134+
}
135+
#endif
136+
127137
const timestamp_t wakeup_timestamp = lp_ticker_read();
128138

129139
sprintf(info, "Delta ticks: %u, Ticker width: %u, Expected wake up tick: %d, Actual wake up tick: %d, delay ticks: %d, wake up after ticks: %d",

0 commit comments

Comments
 (0)