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
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: