Skip to content

Commit 08b06a4

Browse files
committed
STM32 LPTICKER : read counter
1 parent 29c1b75 commit 08b06a4

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

targets/TARGET_STM/lp_ticker.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,12 @@ static void LPTIM1_IRQHandler(void)
179179
uint32_t lp_ticker_read(void)
180180
{
181181
uint32_t lp_time = LPTIM1->CNT;
182-
return lp_time;
182+
/* Reading the LPTIM_CNT register may return unreliable values.
183+
It is necessary to perform two consecutive read accesses and verify that the two returned values are identical */
184+
while (lp_time != LPTIM1->CNT) {
185+
lp_time = LPTIM1->CNT;
186+
}
187+
return lp_time;
183188
}
184189

185190
void lp_ticker_set_interrupt(timestamp_t timestamp)

0 commit comments

Comments
 (0)