Wdt about Arduino nano 33 ble

Hello everyone:

When I use Arduino nano 33 ble for projects, I want to use the watchdog (WDT) and find that #include < AVR / WDT. H > cannot be used. I checked the board chip information, which contains a watchdog timer, but I can't find the corresponding interface to use it. I'd like to ask you to help me refer to what you should do.

Since the "Arduino Mbed OS Nano Boards" platform of the Nano 33 BLE is based on the Mbed OS framework, you can try using Mbed OS's watchdog API:
https://os.mbed.com/docs/mbed-os/v6.12/apis/watchdog.html
Just use the mbed namespace by prefixing the Mbed API references with mbed::

Thank you very much. I've been bothering this problem for more than a month and haven't been able to find the required content

You're welcome. I'm glad if I was able to be of assistance. Enjoy!
Per


I don't know why the header file can be used, but the code can't be used normally

Hi @pengdaliu. I did some investigation and it seems that the watchdog has not been implemented for the Nano 33 BLE. I apologize for having gotten your hopes up for a solution from Mbed OS.

Even though the Mbed OS API turned out to not be useful in this particular case, there are many parts of the API which are implemented for the Nano 33 BLE, so I'll go ahead and share a minimal demo of the Watchdog API as it could be used in an Arduino sketch for one of the boards that it does support:

#include <mbed.h>
mbed::Watchdog &watchdog = mbed::Watchdog::get_instance();
void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, HIGH);
  delay(1000);
  digitalWrite(LED_BUILTIN, LOW);
  watchdog.start(1000);
}
void loop() {}

When uploaded to one of the boards with Watchdog API implementation, such as the Nano RP2040 Connect, this will blink the onboard LED at 0.5 Hz. In this contrived example, the watchdog timer is simply being used as a 1000 ms delay . Since watchdog.kick() is never called, the timer times out after 1000 ms and the processor resets, which starts the next iteration of the blink.

There are two essential things you were missing from your sketch:

  • The #include directive for mbed.h
  • The mbed:: namespace scope on all references to Mbed OS API elements

@pengdaliu, your topic has been moved to the dedicated Nano 33 BLE section of the forum.


Hello, I missed #include... in my screenshots, I actually do. The following is the result of compiling with your code, and there will still be errors. Is it because I am missing any library? I can't seem to find the mbed.h file or Watchdog.h file on the computer. I don't know if this is causing the problem.

Hi @pengdaliu. As I said above, you can't use the code I shared with the Nano 33 BLE. This error is normal and expected. So please forget all about Mbed OS. I'm sorry to have caused this confusion.

Hello, I can't understand how to use this part of your code. Do you copy it directly, or do you need some other header files?

Thank you very much for your help. I have a question. Since I cannot use it, why include <mbed.h>or include<Watchdog.h>, this will not cause an error. Is my board not supported because this part of the function has not been developed yet?

I'm not sure what you are asking, but you can check the code here:
https://github.com/arduino/ArduinoCore-mbed/blob/2.3.1/cores/arduino/mbed/drivers/include/drivers/Watchdog.h

Notice that the declarations of the Watchdog API are wrapped in a preprocessor conditional:

#ifdef DEVICE_WATCHDOG

You can see the compiler flag that provides a global definition of the DEVICE_WATCHDOG macro when compiling for the Nano RP2040 Connect:
https://github.com/arduino/ArduinoCore-mbed/blob/2.3.1/variants/NANO_RP2040_CONNECT/defines.txt#L20

-DDEVICE_WATCHDOG=1

No such macro is defined when compiling for Nano 33 BLE:
https://github.com/arduino/ArduinoCore-mbed/blob/2.3.1/variants/ARDUINO_NANO33BLE/defines.txt

Hello, so Arduino nano 33 ble cannot use watchdog, right?

No. The watchdog timer can be implemented, its just not using the commands of the arduino core. You need to use the underlying mbed and nrf52840 syntax.

https://forum.arduino.cc/t/sketch-hangs-after-long-time-how-to-implement-watchdog/618280/4

Thank you so much for helping me solve this problem