Skip to content

Commit aeac638

Browse files
kapi-nonordicjm
authored andcommitted
applications: nrf_desktop: failsafe: migrate to Zephyr hwinfo driver
Updated the nRF Desktop Failsafe module to use the Zephyr HWinfo driver as its dependency instead of relying on the nrfx reset reason helper. Ref: NCSDK-25090 Signed-off-by: Kamil Piszczek <[email protected]>
1 parent 2122132 commit aeac638

File tree

4 files changed

+54
-15
lines changed

4 files changed

+54
-15
lines changed

applications/nrf_desktop/doc/failsafe.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,9 @@ Additionally, make sure that the following options are set as follows:
3333
This is to ensure that the device will be blocked after a fatal error and then the watchdog will trigger the reboot.
3434

3535
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.
36+
37+
Implementation details
38+
**********************
39+
40+
The failsafe module uses the Zephyr :ref:`zephyr:hwinfo_api` driver.
41+
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.

applications/nrf_desktop/src/modules/Kconfig.failsafe

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ config DESKTOP_FAILSAFE_ENABLE
1010
bool "Enable failsafe"
1111
depends on WATCHDOG
1212
depends on !RESET_ON_FATAL_ERROR
13+
select HWINFO
1314
help
1415
When a device is rebooted by watchdog or due to the CPU lockup,
1516
the settings partition will be erased.

applications/nrf_desktop/src/modules/failsafe.c

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
#include <zephyr/kernel.h>
8-
#include <helpers/nrfx_reset_reason.h>
8+
#include <zephyr/drivers/hwinfo.h>
99
#include <zephyr/storage/flash_map.h>
1010

1111
#define MODULE failsafe
@@ -15,17 +15,27 @@
1515
LOG_MODULE_REGISTER(MODULE, CONFIG_DESKTOP_FAILSAFE_LOG_LEVEL);
1616

1717

18-
static bool failsafe_check(void)
18+
static int failsafe_check(bool *failure_detected)
1919
{
20-
uint32_t mask = NRFX_RESET_REASON_DOG_MASK |
21-
NRFX_RESET_REASON_LOCKUP_MASK;
20+
int err;
21+
uint32_t reas = 0;
22+
static const uint32_t mask = RESET_WATCHDOG | RESET_CPU_LOCKUP;
2223

23-
uint32_t reas = nrfx_reset_reason_get();
24+
err = hwinfo_get_reset_cause(&reas);
25+
if (err) {
26+
LOG_ERR("Failed to fetch reset cause: %d", err);
27+
return err;
28+
}
29+
30+
*failure_detected = ((reas & mask) != 0);
2431

25-
return (reas & mask) != 0;
32+
LOG_INF("Reset reason (0x%08X) trigger %s", reas,
33+
*failure_detected ? "active" : "inactive");
34+
35+
return err;
2636
}
2737

28-
static void failsafe_erase(void)
38+
static int failsafe_erase(void)
2939
{
3040
const struct flash_area *flash_area;
3141
int err = flash_area_open(FIXED_PARTITION_ID(storage_partition),
@@ -37,15 +47,24 @@ static void failsafe_erase(void)
3747
}
3848

3949
if (err) {
40-
LOG_ERR("Failsafe cannot erase settings");
50+
LOG_ERR("Failsafe cannot erase settings: %d", err);
4151
} else {
4252
LOG_WRN("Failsafe erased settings");
4353
}
54+
55+
return err;
4456
}
4557

46-
static void failsafe_clear(void)
58+
static int failsafe_clear(void)
4759
{
48-
nrfx_reset_reason_clear(nrfx_reset_reason_get());
60+
int err;
61+
62+
err = hwinfo_clear_reset_cause();
63+
if (err) {
64+
LOG_ERR("Failed to clear reset cause: %d", err);
65+
}
66+
67+
return err;
4968
}
5069

5170
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)
5574
cast_module_state_event(aeh);
5675

5776
if (check_state(event, MODULE_ID(main), MODULE_STATE_READY)) {
77+
int err;
78+
bool failure_detected;
5879
static bool initialized;
5980

6081
__ASSERT_NO_MSG(!initialized);
6182
initialized = true;
6283

63-
if (failsafe_check()) {
64-
failsafe_erase();
84+
err = failsafe_check(&failure_detected);
85+
if (!err && failure_detected) {
86+
err = failsafe_erase();
6587
}
66-
failsafe_clear();
6788

68-
module_set_state(MODULE_STATE_READY);
89+
if (!err) {
90+
err = failsafe_clear();
91+
}
92+
93+
if (!err) {
94+
module_set_state(MODULE_STATE_READY);
95+
} else {
96+
module_set_state(MODULE_STATE_ERROR);
97+
}
6998
}
7099

71100
return false;

doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,10 @@ nRF5340 Audio
198198
nRF Desktop
199199
-----------
200200

201-
|no_changes_yet_note|
201+
* Updated:
202+
203+
* 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).
204+
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).
202205

203206
nRF Machine Learning (Edge Impulse)
204207
-----------------------------------

0 commit comments

Comments
 (0)