Skip to content

Commit 5e20ccc

Browse files
samples: matter: Extend Matter Watchdog by new configs
Added possibility to configure watchdog CONFIG register by: - Pausing watchdog when CPU is in the sleep state. - Pausing watchdog when the CPU is halted by a debugger. Signed-off-by: Arkadiusz Balys <[email protected]>
1 parent 89e95e5 commit 5e20ccc

File tree

6 files changed

+70
-10
lines changed

6 files changed

+70
-10
lines changed

doc/nrf/protocols/matter/end_product/watchdog.rst

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,39 @@ This approach eliminates the need to directly call the ``Feed()`` method in your
2727
A time window specifies the period within which the feeding signal must be sent to each watchdog channel to reset the timer and prevent the device from rebooting.
2828
If the feeding signal is sent after the time window has elapsed, it does not prevent the device from rebooting.
2929

30-
To enable the Matter watchdog feature, set the :kconfig:option:`CONFIG_NCS_SAMPLE_MATTER_WATCHDOG` Kconfig option to ``y``.
30+
To enable the Matter watchdog feature in a matter sample, set the :kconfig:option:`CONFIG_NCS_SAMPLE_MATTER_WATCHDOG` Kconfig option to ``y``.
3131
The feature is enabled by default for the release build type in all Matter samples and applications.
3232

3333
To set the timeout for the watchdog timer, configure the :kconfig:option:`CONFIG_NCS_SAMPLE_MATTER_WATCHDOG_TIMEOUT` with a value in milliseconds.
3434
By default, the timeout is set to 10 seconds.
3535

36+
.. note::
37+
38+
The Matter watchdog implementation demonstrates how to use the Zephyr watchdog API and is specifically designed for Matter samples within the |NCS|.
39+
If you want to use it in your application, refer to the source code and Kconfig options from this implementation.
40+
41+
.. _ug_matter_device_watchdog_pause_mode:
42+
43+
Matter watchdog pause mode
44+
**************************
45+
46+
You can set the Matter watchdog to pause when the CPU is in idle (sleep) mode or when the CPU is halted by the debugger.
47+
This means the watchdog timer will stop counting down when the CPU is idle or halted.
48+
49+
If pause mode is disabled, the watchdog must be fed within a specified time window, regardless of the CPU state, otherwise the device will reboot.
50+
If pause mode is enabled, the device will only reboot if the task feeding the watchdog is blocked for longer than the set time window.
51+
Pause mode is less accurate and may cause the device to reboot later than expected, but it allows feeding the watchdog only when the CPU is active.
52+
Non-pause mode requires periodic feeding to avoid a timeout, impacting power consumption as the CPU must wake up periodically.
53+
54+
To enable pause mode while CPU is in the idle state, set the :kconfig:option:`CONFIG_NCS_SAMPLE_MATTER_WATCHDOG_PAUSE_IN_SLEEP` Kconfig option to ``y``.
55+
To enable pause mode during debugging, set the :kconfig:option:`CONFIG_NCS_SAMPLE_MATTER_WATCHDOG_PAUSE_ON_DEBUG` Kconfig option to ``y``.
56+
57+
By default, Matter samples enable the pause mode only during debugging.
58+
3659
Creating a Matter watchdog source
3760
*********************************
3861

39-
The Matter watchdog feature is based on the ``Nrf::WatchdogSource`` class, which is located in the :file:`samples/matter/common/watchdog/watchdog.h` file.
62+
The Matter watchdog feature is based on the ``Nrf::WatchdogSource`` class, which is located in the :file:`samples\matter\common\src\watchdog\watchdog.h` file.
4063
Each Matter watchdog source constructor includes two optional arguments:
4164

4265
* ``feedingInterval`` - Specifies the duration in milliseconds for automatically calling the attached feeding callback.

doc/nrf/releases_and_maturity/migration/migration_guide_2.9.rst

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,18 @@ Samples and applications
8383

8484
This section describes the changes related to samples and applications.
8585

86-
|no_changes_yet_note|
86+
Matter
87+
------
88+
89+
.. toggle::
90+
91+
* For the Matter samples and applications:
92+
93+
* The :ref:`ug_matter_device_watchdog` mode has been changed.
94+
Previously, the :ref:`ug_matter_device_watchdog_pause_mode` was enabled by default for all Matter samples.
95+
Now, this mode is disabled and all Matter watchdog sources must be fed within the specified time window.
96+
97+
To re-enable the pause mode, set the :kconfig:option:`CONFIG_NCS_SAMPLE_MATTER_WATCHDOG_PAUSE_IN_SLEEP` Kconfig option to ``y``.
8798

8899
Libraries
89100
=========

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,13 @@ Gazell
138138
Matter
139139
------
140140

141-
* Added implementation of the :cpp:class:`Spake2pVerifier` class for the PSA crypto backend.
142-
You can use this class to generate the Spake2+ verifier at runtime.
143-
To use this class, enable the :kconfig:option:`CONFIG_PSA_WANT_ALG_PBKDF2_HMAC` and :kconfig:option:`CONFIG_PSA_WANT_KEY_TYPE_SPAKE2P_KEY_PAIR_DERIVE` Kconfig options.
141+
* Added:
142+
143+
* Implementation of the :cpp:class:`Spake2pVerifier` class for the PSA crypto backend.
144+
You can use this class to generate the Spake2+ verifier at runtime.
145+
To use this class, enable the :kconfig:option:`CONFIG_PSA_WANT_ALG_PBKDF2_HMAC` and :kconfig:option:`CONFIG_PSA_WANT_KEY_TYPE_SPAKE2P_KEY_PAIR_DERIVE` Kconfig options.
146+
* The Matter watchdog pause mode to the :ref:`ug_matter_device_watchdog` feature.
147+
144148

145149
Matter fork
146150
+++++++++++
@@ -393,6 +397,9 @@ Matter samples
393397
* Updated all Matter samples that support low-power mode to enable the :ref:`lib_ram_pwrdn` feature.
394398
It is enabled by default for the release configuration of the :ref:`matter_lock_sample`, :ref:`matter_light_switch_sample`, :ref:`matter_smoke_co_alarm_sample`, and :ref:`matter_window_covering_sample` samples.
395399

400+
* Disabled pausing Matter watchdog while CPU is in idle state in all Matter samples.
401+
To enable it set the :kconfig:option:`CONFIG_NCS_SAMPLE_MATTER_WATCHDOG_PAUSE_IN_SLEEP` Kconfig option to ``y``.
402+
396403
* :ref:`matter_template_sample` sample:
397404

398405
* Updated the internal configuration for the :ref:`zephyr:nrf54l15dk_nrf54l15` target to use the DFU image compression and provide more memory space for the application.

samples/matter/common/src/watchdog/Kconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,19 @@ menuconfig NCS_SAMPLE_MATTER_WATCHDOG
1010

1111
if NCS_SAMPLE_MATTER_WATCHDOG
1212

13+
config NCS_SAMPLE_MATTER_WATCHDOG_PAUSE_IN_SLEEP
14+
bool "Pause watchdog while CPU is in sleep state"
15+
help
16+
If enabled, the watchdog will be paused while the CPU is in idle (sleep) state.
17+
18+
config NCS_SAMPLE_MATTER_WATCHDOG_PAUSE_ON_DEBUG
19+
bool "Pause watchdog while the CPU is halted by the debugger"
20+
default y
21+
help
22+
If disabled, the watchdog will not be paused while the CPU is halted by the debugger and
23+
the device reset will be triggered, if the feeding signal is not received within the
24+
specified time.
25+
1326
config NCS_SAMPLE_MATTER_WATCHDOG_DEFAULT
1427
bool "Use watchdog object dedicated for Main and Matter threads"
1528
default y

samples/matter/common/src/watchdog/watchdog.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,16 @@ bool Nrf::Watchdog::Enable()
3434
return false;
3535
}
3636

37-
if (wdt_setup(wdt, WatchdogSource::kWatchdogOptions) != 0) {
37+
/* Pause Watchdog when the CPU is in sleep state or is halted by the debugger */
38+
uint8_t watchdogOptions = 0;
39+
#ifdef CONFIG_NCS_SAMPLE_MATTER_WATCHDOG_PAUSE_IN_SLEEP
40+
watchdogOptions |= WDT_OPT_PAUSE_IN_SLEEP;
41+
#endif /* CONFIG_NCS_SAMPLE_MATTER_WATCHDOG_PAUSE_IN_SLEEP */
42+
#ifdef CONFIG_NCS_SAMPLE_MATTER_WATCHDOG_PAUSE_ON_DEBUG
43+
watchdogOptions |= WDT_OPT_PAUSE_HALTED_BY_DBG;
44+
#endif /* CONFIG_NCS_SAMPLE_MATTER_WATCHDOG_PAUSE_ON_DEBUG */
45+
46+
if (wdt_setup(wdt, watchdogOptions) != 0) {
3847
return false;
3948
}
4049

samples/matter/common/src/watchdog/watchdog.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,6 @@ namespace Watchdog
129129
private:
130130
constexpr static uint8_t kInvalidChannel = -1;
131131

132-
/* Pause Watchdog when the CPU is in sleep state or is halted by the debugger */
133-
constexpr static uint8_t kWatchdogOptions = WDT_OPT_PAUSE_HALTED_BY_DBG | WDT_OPT_PAUSE_IN_SLEEP;
134-
135132
/* Timer for feeding in the required interval */
136133
static void TimerTimeoutCallback(k_timer *timer);
137134

0 commit comments

Comments
 (0)