Watchdog Timer on Giga?

Is there a way to implement a watchdog timer on Giga? It seems like the Arduino Watchdog library only supports AVR processors.

Thanks.

Hi @dccontrarian. The "Arduino Mbed OS Giga Boards" platform of the GIGA R1 WiFi board is based on the free open source Mbed OS operating system. This means you can use the "Watchdog" API provided by Mbed OS to control the watchdog timer on this board:

https://os.mbed.com/docs/mbed-os/latest/apis/watchdog.html

I'll provide a simple demonstration sketch:

/*
Demonstration of using the Mbed OS Watchdog interface:
https://os.mbed.com/docs/mbed-os/latest/apis/watchdog.html

The sketch will produce the following built-in LED blink sequence:

- Blink for 2000 ms (this is accomplished without the board resetting by calling the mbed::Watchdog::kick function frequently).
- Wait for 1000 ms (this is accomplished by the watchdog timer having been configured for a 1000 ms timeout).
- Repeat (this is accomplished by the watchdog timing out and resetting the board).
*/

#include <mbed.h>

mbed::Watchdog &watchdog = mbed::Watchdog::get_instance();

void setup() {
  watchdog.start(1000); // Enable the watchdog and configure the duration of the timeout (ms).

  pinMode(LED_BUILTIN, OUTPUT);

  for (byte blinkCounter = 0; blinkCounter < 10; blinkCounter++) {
    digitalWrite(LED_BUILTIN, HIGH);
    delay(100);
    digitalWrite(LED_BUILTIN, LOW);
    delay(100);
    watchdog.kick();  // This must be called frequently in order to prevent a watchdog timeout.
  }
}

void loop() {
  // Loop until watchdog times out and triggers a reset.
}
2 Likes

Thanks, that's exactly what I needed.

You are welcome. I'm glad if I was able to be of assistance.

Regards,
Per

1 Like

One thing to note, there is a maximum possible timeout, given by:
watchdog.get_max_timeout()

On my Giga it's about 32 seconds.

I found that if I set the timeout for longer it hangs the board and I can't even wake it up by uploading new software! So use with care.

I'm sad to report that this code doesn't work for me, the sketch seems to hang on watchdog.kick(). I will investigate more and report.

And it hangs hard, I can't upload a new sketch. I have to time the upload just right to before the loop gets to the line with kick().

That is unexpected. I tested it on my own GIGA R1 WiFi board and it works exactly as described in the comment.

In case you have trouble uploading, there is an alternative procedure:

  1. Press and release the button marked "RST" on your board quickly twice.
    You should now see the green LED next to the "BOOT0" button on the board pulsing, which means the bootloader is running.
    The double reset causes the bootloader to run until the board is reset normally, powered off, or an upload is done.
  2. Select the port of your board from the Tools > Port menu.
    :exclamation: The port may be different when the bootloader is running so don't assume you already have the correct port selected.
  3. Select Sketch > Upload from the Arduino IDE menus.

The sketch should now upload successfully.

Well I went back to it today to see if I could figure out why it was hanging on kick(), and it wouldn't hang for me. So it looks like it's working now.

I'm glad it is working now. Thanks for taking the time to post an update!

Try this: Internal or External Watchdog

bye