summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/library/machine.WDT.rst5
-rw-r--r--docs/rp2/quickref.rst1
-rw-r--r--ports/rp2/machine_wdt.c9
3 files changed, 12 insertions, 3 deletions
diff --git a/docs/library/machine.WDT.rst b/docs/library/machine.WDT.rst
index 8c81e10ea..95893cec3 100644
--- a/docs/library/machine.WDT.rst
+++ b/docs/library/machine.WDT.rst
@@ -15,7 +15,7 @@ Example usage::
wdt = WDT(timeout=2000) # enable it with a timeout of 2s
wdt.feed()
-Availability of this class: pyboard, WiPy, esp8266, esp32.
+Availability of this class: pyboard, WiPy, esp8266, esp32, rp2040, mimxrt.
Constructors
------------
@@ -26,7 +26,8 @@ Constructors
Once it is running the timeout cannot be changed and the WDT cannot be stopped either.
Notes: On the esp32 the minimum timeout is 1 second. On the esp8266 a timeout
- cannot be specified, it is determined by the underlying system.
+ cannot be specified, it is determined by the underlying system. On rp2040 devices,
+ the maximum timeout is 8388 ms.
Methods
-------
diff --git a/docs/rp2/quickref.rst b/docs/rp2/quickref.rst
index 4824f390e..430c130c6 100644
--- a/docs/rp2/quickref.rst
+++ b/docs/rp2/quickref.rst
@@ -296,6 +296,7 @@ See :ref:`machine.WDT <machine.WDT>`. ::
wdt = WDT(timeout=5000)
wdt.feed()
+The maximum value for timeout is 8388 ms.
OneWire driver
--------------
diff --git a/ports/rp2/machine_wdt.c b/ports/rp2/machine_wdt.c
index 38e059701..d6914a4f2 100644
--- a/ports/rp2/machine_wdt.c
+++ b/ports/rp2/machine_wdt.c
@@ -29,6 +29,9 @@
#include "hardware/watchdog.h"
+// The maximum timeout in milliseconds is: 0xffffff / 2 / 1000
+#define WDT_TIMEOUT_MAX 8388
+
typedef struct _machine_wdt_obj_t {
mp_obj_base_t base;
} machine_wdt_obj_t;
@@ -53,7 +56,11 @@ STATIC mp_obj_t machine_wdt_make_new(const mp_obj_type_t *type, size_t n_args, s
}
// Start the watchdog (timeout is in milliseconds).
- watchdog_enable(args[ARG_timeout].u_int, false);
+ uint32_t timeout = args[ARG_timeout].u_int;
+ if (timeout > WDT_TIMEOUT_MAX) {
+ mp_raise_ValueError(MP_ERROR_TEXT("timeout exceeds " MP_STRINGIFY(WDT_TIMEOUT_MAX)));
+ }
+ watchdog_enable(timeout, false);
return MP_OBJ_FROM_PTR(&machine_wdt);
}