Implementing RTC enables Mbed OS to keep track of the current time. The standard library time keeping functions, such as
time, use it.
- The function
rtc_initis safe to call repeatedly.
- RTC accuracy is at least 10%.
freedoesn't stop RTC from counting.
- Software reset doesn't stop RTC from counting.
- Sleep modes don't stop RTC from counting.
- Shutdown mode doesn't stop RTC from counting.
- Calling any function other than
rtc_initbefore the initialization of the RTC.
Watch out for these common trouble areas when implementing this API:
- Incorrect overflow handling.
- Glitches due to ripple counter.
Hardware RTC capabilities.
Implementing the RTC API
You can find the API and specification for the RTC API in the following header file:
To enable RTC support in Mbed OS, add the
RTC label in the
device_has option of the target's section in the
The Mbed OS HAL provides a set of conformance tests for RTC. You can use these tests to validate the correctness of your implementation. To run the RTC HAL tests, use the following command:
mbed test -t <toolchain> -m <target> -n "tests-mbed_hal-rtc*"
You can read more about the test cases: