Skip to content

Commit 6d5cb6c

Browse files
authored
Merge pull request #8136 from fkjagodzinski/fix-stm-us_ticker_after_deepsleep
STM: Fix us_ticker timestamp after deep sleep
2 parents 0f1075c + 6821556 commit 6d5cb6c

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

targets/TARGET_STM/sleep.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ void hal_sleep(void)
158158
}
159159

160160
extern int serial_is_tx_ongoing(void);
161+
extern int mbed_sdk_inited;
161162

162163
void hal_deepsleep(void)
163164
{
@@ -200,6 +201,10 @@ void hal_deepsleep(void)
200201
HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
201202
#endif /* TARGET_STM32L4 */
202203

204+
/* Prevent HAL_GetTick() from using ticker_read_us() to read the
205+
* us_ticker timestamp until the us_ticker context is restored. */
206+
mbed_sdk_inited = 0;
207+
203208
// Verify Clock Out of Deep Sleep
204209
ForceClockOutofDeepSleep();
205210

@@ -214,6 +219,10 @@ void hal_deepsleep(void)
214219

215220
restore_timer_ctx();
216221

222+
/* us_ticker context restored, allow HAL_GetTick() to read the us_ticker
223+
* timestamp via ticker_read_us() again. */
224+
mbed_sdk_inited = 1;
225+
217226
// Enable IRQs
218227
core_util_critical_section_exit();
219228
}

0 commit comments

Comments
 (0)