Skip to content

STM: Fix us_ticker timestamp after deep sleep #8136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions targets/TARGET_STM/sleep.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ void hal_sleep(void)
}

extern int serial_is_tx_ongoing(void);
extern int mbed_sdk_inited;

void hal_deepsleep(void)
{
Expand Down Expand Up @@ -200,6 +201,10 @@ void hal_deepsleep(void)
HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
#endif /* TARGET_STM32L4 */

/* Prevent HAL_GetTick() from using ticker_read_us() to read the
Copy link
Contributor

@LMESTM LMESTM Sep 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about moving restore_timer_ctx(); at this stage so that HAL_GetTick can be called in the next functions ?
Have you tried this ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following functions:

  1. ForceClockOutofDeepSleep(),
  2. SetSysClock(),
  3. restore_timer_ctx(),

have to be called in that order. If the timer context was restored earlier, it would have been reset anyway.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok good point indeed. will approve as it is

* us_ticker timestamp until the us_ticker context is restored. */
mbed_sdk_inited = 0;

// Verify Clock Out of Deep Sleep
ForceClockOutofDeepSleep();

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

restore_timer_ctx();

/* us_ticker context restored, allow HAL_GetTick() to read the us_ticker
* timestamp via ticker_read_us() again. */
mbed_sdk_inited = 1;

// Enable IRQs
core_util_critical_section_exit();
}
Expand Down