[feature-hal-spec-sleep] Improvements to HAL Sleep API

24 Mar 2018


Low power consumption is one of the most important features of an embedded system. One way of improving power usage is to enter a low power mode. Implementing HAL Sleep API will enable your board to save power by sleeping when the system is idle. It's also one of the building blocks of tickless mode which will reduce the power usage further. By default, Mbed OS 5 tries to put the device into the lowest sleep state. Applications can also control the sleep state by using the sleep manager and deep sleep lock.

What we've done

  • Updated specification for the sleep API including defined behaviours
  • Revised porting guide in the reference book
  • Created a validation test suite

What has changed?

While the API remains the same we've changed the specification and validation test suite for this peripheral. The feature branch passes all testing which means that targets supporting low power mode but failing the test suite have had SLEEP removed from the device_has field in targets.json. If you are interested in contributing platform support, you can check out the feature-hal-spec-sleep branch, add SLEEP to the device_has list in targets.json and run

mbed-os> git checkout –b feature-hal-spec-sleep origin/feature-hal-spec-sleep
mbed-os> mbed test -t <toolchain> -m <target> -n "tests-mbed_hal-sleep*"

Who is affected?

All targets will need to be updated to conform to the new specification and pass the validation tests to claim Sleep support. One of the major changes is the specification of how long a device must take to resume operation from sleep and deep sleep modes. This will ensure consistency across most devices.

When will it happen?

The development branch is available now for contributions. We are planning to bring the changes to master in Mbed OS 5.9 release. The expectation for completion is that 80% or more of the targets capable of the Sleep specification support the new API. Contributions are welcome!

24 Jun 2018

According to my understanding for mbed, HAL Sleep API is invoked from Idle task with unprivileged mode, and then how to implement low power via Hal Sleep API which normally operates to register with privilege mode??

24 Jul 2018

Hi @VineYuan, at the time of this post (mbed-os 5.9) all threads created on Cortex-M devices run in privileged mode. Because of this the HAL sleep implementation can access privileged resources from the idle thread.

25 Jul 2018

Hi @Russ, as you told, if all threads run in privileged mode, it's not necessary to accesss critical resource via svc routine, which will cause performance issue.

25 Jul 2018

Hi @VienYuan, In theory you wouldn't need to make an SVC call, however, RTX is written so and it expects that the critical resource is used that way. Hope that helps.