How to use the Watchdog

This article illustrates how to use the watchdog on Aria G25 and Arietta G25

AT91bootstrap (boot.bin) configuration

By default the watchdog is disabled at boot time by AT91Bootstrap. To enable it you have to recompile AT91Bootstrap after have disabled this flag:

[ ] Disable Watchdog   

To know how to compile AT91Bootstrap follow the tutorials on this link.

To change the default flag value use the make menuconfig command.

Defconfig configuration (Linux Kernel)

This is the Kernel flag to enable inside the Kernel configuration.

Device Drivers  --->
  [*] Watchdog Timer Support  --->
    <*>   AT91SAM9X / AT91CAP9 watchdog

To know how to change the kernel configuration and compile it to generate the bootable zImage follow this tutorials this link.

Device tree configuration (Linux Kernel)

Add to board xxxx.dts these lines inside the apb section:

ahb {
    apb {

        ...

        watchdog@fffffe40 {
            compatible = "atmel,at91sam9260-wdt";
            reg = <0xfffffe40 0x10>;
            timeout-sec = <30>;
            status = "okay";
        };

        ...
    };
};  

Setting the parameter timeout-sec as you like.

To know how to compile the Device Tree file follow the tutorials on how to cross compile the Linux Kernel on this link.

Using the watchdog

If everything is going well you will see this message on the debug port during the bootstrap:

at91sam9_wdt: enabled (heartbeat=30 sec, nowayout=0)

or from the command line:

root@arietta:~# dmesg | grep "wdt"                                                                             
[    5.375000] at91sam9_wdt: enabled (heartbeat=30 sec, nowayout=0)

a device node called /dev/watchdog exists on the rootfs:

root@arietta:~# ls /dev/watchdog
/dev/watchdog

Now simply try the watchdog by typing and wait 30 sec doing nothing...

# echo "hello" > /dev/watchdog
watchdog watchdog0: watchdog did not stop!

After 30 secs the board will restart.

at91sam9_wdt: I will reset your machine !

Writing something on /dev/watchdog you have armed the watchdog timer and after the first write you have to write on it before 30 sec to avoid the restart.

More info about the watchdog under Linux is available on this link:

Credits

Many thanks to Sadir Mansour for his contribute to fix the errors on this article

Sergio Tanzilli
Systems designer, webmaster of www.acmesystems.it and founder of Acme Systems srl

Personal email: tanzilli@acmesystems.it
Web pages: https://www.acmesystems.it --- https://www.acmestudio.it
Github repositories: https://github.com/tanzilli --- https://github.com/acmesystems
Telegram group dedicated to the Acme Systems boards: https://t.me/acmesystemssrl