diff --git a/applications/nrf_desktop/configuration/nrf54h20dk_nrf54h20_cpuapp/prj_release.conf b/applications/nrf_desktop/configuration/nrf54h20dk_nrf54h20_cpuapp/prj_release.conf index 6e0102fd4683..86ea98121b15 100644 --- a/applications/nrf_desktop/configuration/nrf54h20dk_nrf54h20_cpuapp/prj_release.conf +++ b/applications/nrf_desktop/configuration/nrf54h20dk_nrf54h20_cpuapp/prj_release.conf @@ -38,6 +38,7 @@ CONFIG_DESKTOP_BLE_SECURITY_FAIL_TIMEOUT_S=10 CONFIG_DESKTOP_BLE_LOW_LATENCY_LOCK=y CONFIG_DESKTOP_WATCHDOG_ENABLE=y +CONFIG_DESKTOP_FAILSAFE_ENABLE=y CONFIG_DESKTOP_CONFIG_CHANNEL_ENABLE=y CONFIG_DESKTOP_CONFIG_CHANNEL_DFU_ENABLE=y diff --git a/applications/nrf_desktop/doc/failsafe.rst b/applications/nrf_desktop/doc/failsafe.rst index 41b8113002b6..0794bdc87b6b 100644 --- a/applications/nrf_desktop/doc/failsafe.rst +++ b/applications/nrf_desktop/doc/failsafe.rst @@ -33,3 +33,9 @@ Additionally, make sure that the following options are set as follows: This is to ensure that the device will be blocked after a fatal error and then the watchdog will trigger the reboot. After the reboot caused either by the watchdog or by the CPU lockup, the failsafe module erases the settings partition and clears the non-volatile settings data. + +Implementation details +********************** + +The failsafe module uses the Zephyr :ref:`zephyr:hwinfo_api` driver. +The module gets the reset reason information with the :c:func:`hwinfo_get_reset_cause` function and clears it with the :c:func:`hwinfo_clear_reset_cause` function. diff --git a/applications/nrf_desktop/src/modules/Kconfig.failsafe b/applications/nrf_desktop/src/modules/Kconfig.failsafe index 157e47bc024d..11da74324c2b 100644 --- a/applications/nrf_desktop/src/modules/Kconfig.failsafe +++ b/applications/nrf_desktop/src/modules/Kconfig.failsafe @@ -10,6 +10,7 @@ config DESKTOP_FAILSAFE_ENABLE bool "Enable failsafe" depends on WATCHDOG depends on !RESET_ON_FATAL_ERROR + select HWINFO help When a device is rebooted by watchdog or due to the CPU lockup, the settings partition will be erased. diff --git a/applications/nrf_desktop/src/modules/failsafe.c b/applications/nrf_desktop/src/modules/failsafe.c index fac0fd68b8c0..c0debf183e98 100644 --- a/applications/nrf_desktop/src/modules/failsafe.c +++ b/applications/nrf_desktop/src/modules/failsafe.c @@ -5,7 +5,7 @@ */ #include -#include +#include #include #define MODULE failsafe @@ -15,17 +15,27 @@ LOG_MODULE_REGISTER(MODULE, CONFIG_DESKTOP_FAILSAFE_LOG_LEVEL); -static bool failsafe_check(void) +static int failsafe_check(bool *failure_detected) { - uint32_t mask = NRFX_RESET_REASON_DOG_MASK | - NRFX_RESET_REASON_LOCKUP_MASK; + int err; + uint32_t reas = 0; + static const uint32_t mask = RESET_WATCHDOG | RESET_CPU_LOCKUP; - uint32_t reas = nrfx_reset_reason_get(); + err = hwinfo_get_reset_cause(&reas); + if (err) { + LOG_ERR("Failed to fetch reset cause: %d", err); + return err; + } + + *failure_detected = ((reas & mask) != 0); - return (reas & mask) != 0; + LOG_INF("Reset reason (0x%08X) trigger %s", reas, + *failure_detected ? "active" : "inactive"); + + return err; } -static void failsafe_erase(void) +static int failsafe_erase(void) { const struct flash_area *flash_area; int err = flash_area_open(FIXED_PARTITION_ID(storage_partition), @@ -37,15 +47,24 @@ static void failsafe_erase(void) } if (err) { - LOG_ERR("Failsafe cannot erase settings"); + LOG_ERR("Failsafe cannot erase settings: %d", err); } else { LOG_WRN("Failsafe erased settings"); } + + return err; } -static void failsafe_clear(void) +static int failsafe_clear(void) { - nrfx_reset_reason_clear(nrfx_reset_reason_get()); + int err; + + err = hwinfo_clear_reset_cause(); + if (err) { + LOG_ERR("Failed to clear reset cause: %d", err); + } + + return err; } static bool app_event_handler(const struct app_event_header *aeh) @@ -55,17 +74,27 @@ static bool app_event_handler(const struct app_event_header *aeh) cast_module_state_event(aeh); if (check_state(event, MODULE_ID(main), MODULE_STATE_READY)) { + int err; + bool failure_detected; static bool initialized; __ASSERT_NO_MSG(!initialized); initialized = true; - if (failsafe_check()) { - failsafe_erase(); + err = failsafe_check(&failure_detected); + if (!err && failure_detected) { + err = failsafe_erase(); } - failsafe_clear(); - module_set_state(MODULE_STATE_READY); + if (!err) { + err = failsafe_clear(); + } + + if (!err) { + module_set_state(MODULE_STATE_READY); + } else { + module_set_state(MODULE_STATE_ERROR); + } } return false; diff --git a/doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst b/doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst index 43c45c259939..4e1804ca74f0 100644 --- a/doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst +++ b/doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst @@ -198,7 +198,11 @@ nRF5340 Audio nRF Desktop ----------- -|no_changes_yet_note| +* Updated: + + * The :ref:`nrf_desktop_failsafe` to use the Zephyr :ref:`zephyr:hwinfo_api` driver for getting and clearing the reset reason information (see the :c:func:`hwinfo_get_reset_cause` and :c:func:`hwinfo_clear_reset_cause` functions). + The Zephyr :ref:`zephyr:hwinfo_api` driver replaces the nrfx reset reason helper dependency (see the :c:func:`nrfx_reset_reason_get` and :c:func:`nrfx_reset_reason_clear` functions). + * The release configuration for the :ref:`zephyr:nrf54h20dk_nrf54h20` board target to enable the :ref:`nrf_desktop_failsafe` (see the :ref:`CONFIG_DESKTOP_FAILSAFE_ENABLE ` Kconfig option). nRF Machine Learning (Edge Impulse) -----------------------------------