Skip to content

Commit 25bcc27

Browse files
Merge pull request #4808 from betzw/betzw_idle_github_wb
Make HAL & US tickers idle safe
2 parents 2766e56 + e2dc677 commit 25bcc27

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

targets/TARGET_STM/sleep.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,32 @@
3434
#include "sleep_api.h"
3535
#include "rtc_api_hal.h"
3636
#include "hal_tick.h"
37+
#include "mbed_critical.h"
3738

3839
extern void HAL_SuspendTick(void);
3940
extern void HAL_ResumeTick(void);
4041

4142
void hal_sleep(void)
4243
{
44+
// Disable IRQs
45+
core_util_critical_section_enter();
46+
4347
// Stop HAL tick to avoid to exit sleep in 1ms
4448
HAL_SuspendTick();
4549
// Request to enter SLEEP mode
4650
HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
47-
4851
// Restart HAL tick
4952
HAL_ResumeTick();
53+
54+
// Enable IRQs
55+
core_util_critical_section_exit();
5056
}
5157

5258
void hal_deepsleep(void)
5359
{
60+
// Disable IRQs
61+
core_util_critical_section_enter();
62+
5463
// Stop HAL tick
5564
HAL_SuspendTick();
5665
uint32_t EnterTimeUS = us_ticker_read();
@@ -82,6 +91,9 @@ void hal_deepsleep(void)
8291
// Restart HAL tick
8392
HAL_ResumeTick();
8493

94+
// Enable IRQs
95+
core_util_critical_section_exit();
96+
8597
// After wake-up from STOP reconfigure the PLL
8698
SetSysClock();
8799

0 commit comments

Comments
 (0)