Using nPM1300 Watchdog
1. Overview
This application note describes how to configure nPM1300 Watchdog in Zephyr BSP and use it in the user application.
2. Configuring nPM1300 Watchdog in Zephyr BSP
The nPM1300 Watchdog device is declared in nrf9151som_nrf9151_ns.dts
as a child node of the npm1300_pmic device:
npm1300_pmic: pmic@6b {
compatible = "nordic,npm1300";
...
npm1300_wdt: npm1300_wdt {
compatible = "nordic,npm1300-wdt";
};
...
};
The devicetree node configures the following parameters:
Parameter | Value | Description |
---|---|---|
|
| Enables the |
3. Controlling nPM1300 Watchdog in User Application
3.1. nPM1300 Watchdog C-binding API
The Customized Asset Tracker v2 application implements the following C-binding helper API for nPM1300 watchdog, defined in watchdog_app.*
files:
Function | Description | Comments |
| Initialize and start application watchdog module. | Returns zero on success, otherwise a negative error code is returned. |
| Register handler to receive watchdog callback events. |
The library only allows for one event handler to be registered at a time. A passed in event handler in this function will overwrite the previously set event handler. |
| Stop watchdog feed. |
Calling this function will cause power cycle when the nPM1300 WDT timeout expires. |
3.2. nPM1300 Watchdog Static Functions
The Customized Asset Tracker v2 application implements several static functions, which are used by the watchdog workqueue thread:
Function | Description | Comments |
| This function is being called by SYS_INIT at Zephyr boot to initialize the watchdog thread. | Returns zero on success, otherwise a negative error code is returned. |
| System workqueue handler, used to disable the nPM1300 watchdog. |
|
| System workqueue handler, used to enable the nPM1300 watchdog. |
|
| System workqueue handler, used to feed the nPM1300 watchdog. |
Calls |
| Configure and start nPM1300 watchdog. | Calls |
| Disable the watchdog. | Calls |
| Start the watchdog. | Calls |
| Configure the watchdog timeout. | Calls |
The static functions are defined in watchdog_app.c
file and make use of the Zephyr watchdog driver API.
3.3. nPM1300 Watchdog Threads and Tasks
The Customized Asset Tracker v2 application implements a separate workqueue thread for nPM1300 operations, which prevents other threads from interfering with the watchdog initialization sequence and feed cycle. The watchdog workqueue thread operates in the following sequence:
SYS_INIT()
initializes the watchdog workqueue thread by callingwatchdog_init_and_start()
at Zephyr boot.The watchdog workqueue thread calls
watchdog_enable_worker()
, which calls configures and starts the watchdog by callingwatchdog_timeout_install()
andwatchdog_start()
. Watchdog timeout is specified by theCONFIG_WATCHDOG_APPLICATION_TIMEOUT_MS
configuration parameter.After initializing the watchdog, the workqueue thread periodically calls
watchdog_feed_worker()
.When
watchdog_stop_feed()
is called, the watchdog thread stops callingwatchdog_feed_worker()
, which in turn causes board reset performed by the nPM1300 PMIC.
3.4. nPM1300 Watchdog Shell Commands
The Customized Asset Tracker v2 application provides a set of Zephyr shell commands for nPM1300 watchdog, defined in the watchdog_app.c
file:
Command | Comments |
| Enable the watchdog. |
| Disable the watchdog. |
| Prints watchdog status in the following format: uart:~$ watchdog status
Watchdog status: <enabled|disabled>
Watchdog stop requested: <yes|no>
Watchdog feed period: <feed period> ms
Watchdog timeout: <timeout> ms
|
| Stop feeding the watchdog. Calling this command will cause watchdog reset when the watchdog timeout expires. |
4. Validating nPM1300 Watchdog Operations
From the SOM-NRF9151 serial console, issue the
watchdog reset
command and verify that the system has been reset by the PMIC WDT.Issue the
watchdog disable
command to disable the PMIC WDT:uart:~$ watchdog disable [00:00:46.817,230] <inf> watchdog: Disabling watchdog [00:00:46.817,749] <inf> watchdog: Watchdog disabled
Issue the
watchdog status
command to read PMIC WDT status:uart:~$ watchdog status Watchdog status: disabled Watchdog stop requested: no Watchdog feed period: 2500 ms Watchdog timeout: 5000 ms
Issue the
watchdog reset
command and verify that the board is not being reset:uart:~$ watchdog reset [00:01:28.096,984] <inf> watchdog: Reset command received, stopping watchdog feed [00:01:28.097,015] <err> watchdog: Watchdog disabled, stopping feed has no effect
Issue the
watchdog enable
command to enable the PMIC WDT:uart:~$ watchdog enable [00:01:49.899,200] <inf> watchdog: Enabling watchdog [00:01:49.901,458] <inf> watchdog: Watchdog enabled
Issue the
watchdog reset
command and verify that the system has been reset by the PMIC WDT.