The ResetReason API provides a platform-independent method of checking the cause of the last system reset. Implementing the ResetReason API is not mandatory, but by implementing it, you can check for erroneous system resets at boot time.
- The function
hal_reset_reason_clearclears the ResetReason registers for the next system boot.
- By the time the user calls
hal_reset_reason_getto read the value, some other part of the application may have cleared the value. Therefore, though there may have been a reset reason in the registers when the system started, the reason may not be available when the user comes to check it.
- There is no guarantee that the function
hal_reset_reason_getwill return the same value when you call it repeatedly. Store the value for later use instead of calling the function repeatedly.
- The function
hal_reset_reason_clearmay not clear the ResetReason register in time for the next system boot.
- The contents of the targets ResetReason register may be cleared by some subsystem before it first gets called. This returns a
RESET_REASON_UNKNOWNvalue to the user. To avoid this, the user should call the ResetReason API as early as possible at boot time.
- If the target doesn't support clearing reset registers,
hal_reset_reason_getseems to erroneously return a reset reason even after clearing.
Hardware ResetReason registers.
To enable ResetReason support in Mbed OS, add the
RESET_REASON label in the
device_has option of the target's section in the
The Mbed OS HAL provides a set of conformance tests for ResetReason. You can use these tests to validate the correctness of your implementation. To run the ResetReason HAL tests use the following command:
mbed test -t <toolchain> -m <target> -n "tests-mbed_hal-reset_reason"