Skip to content

Make HAL & US tickers idle safe #4808

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 1 commit into from
Aug 14, 2017
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
14 changes: 13 additions & 1 deletion targets/TARGET_STM/sleep.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,32 @@
#include "sleep_api.h"
#include "rtc_api_hal.h"
#include "hal_tick.h"
#include "mbed_critical.h"

extern void HAL_SuspendTick(void);
extern void HAL_ResumeTick(void);

void hal_sleep(void)
{
// Disable IRQs
core_util_critical_section_enter();

// Stop HAL tick to avoid to exit sleep in 1ms
HAL_SuspendTick();
// Request to enter SLEEP mode
HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);

// Restart HAL tick
HAL_ResumeTick();

// Enable IRQs
core_util_critical_section_exit();
}

void hal_deepsleep(void)
{
// Disable IRQs
core_util_critical_section_enter();

// Stop HAL tick
HAL_SuspendTick();
uint32_t EnterTimeUS = us_ticker_read();
Expand Down Expand Up @@ -82,6 +91,9 @@ void hal_deepsleep(void)
// Restart HAL tick
HAL_ResumeTick();

// Enable IRQs
core_util_critical_section_exit();

// After wake-up from STOP reconfigure the PLL
SetSysClock();

Expand Down