Implement the Sleep HAL API to enable your device to go into a low power state when you are not actively using it.
There are two power-saving modes available in Mbed OS:
The core system clock is disabled. You can use both the low- and high-frequency clocks and retain RAM.
- Wake-up sources - Any interrupt must wake up the MCU.
- Latency - The MCU must wake up within 10 us.
The core system clock is disabled. You can only enable the low-frequency clocks and retain RAM.
- Wake-up sources - RTC, low power ticker or GPIO must wake up the MCU.
- Latency - The MCU must wake up within 10 ms.
Implementing the Sleep API
You can find the API and specification for the sleep API in the following header file:
To enable sleep support in Mbed OS, you need to add the
SLEEP label in the
device_has option of the target's section in the
Targets that disable
systick in sleep mode
If your target disables
systick when entering sleep mode, the RTOS scheduler does not function correctly in the default configuration. You can fix this by either adding
device_has, which disables sleep when the RTOS is present, or by implementing tickless and adding
The Mbed OS HAL provides a set of conformance tests for Sleep. You can use these tests to validate the correctness of your implementation. To run the Sleep HAL tests, use the following command:
mbed test -t <toolchain> -m <target> -n "tests-mbed_hal-sleep*"
You can read more about the test cases: