Using Watchdog on Stamp9G20 or PortuxG20


The AT91SAM9G20 features a watchdog timer. This watchdog timer is enabled on boot per default and is set to 16 seconds. The mode register of the watchdog is write once, that means once disabled or configured it cannot be changed again, thus protecting it against accidental changes.

In the default images delivered by taskit, the watchdog is disabled by the primary bootloader bootstrap and cannot be used anymore. Just enabling the the watchdog in the primary bootloader causes some problems. First, if you want to work with the bootloader, after 16 seconds (which is the default timeout) the watchdog will reset the board. Second, while booting Linux the time slice of 16 seconds may also expire before starting an application which cares about resetting the watchdog.

Further measures are required: u-boot needs to reset the watchdog and Linux needs to care as well.

The watchdog driver contained in the Linux sources configures the watchdog and resets it via a timer. Until an application opens the watchdog device: Then the reset is up to the user who has to write to the watchdog device to reset it. After closing the device there are two ways: writing a magic character ("V") to the watchdog device lets Linux care again, otherwise the user still has to care by himself.

Having u-boot care about watchdog resets is convenient. In a production system this may have a drawback: If a script in u-boot fails, the device doesn't work anymore but as well does not reboot anymore. In most cases this is not as bad as it seems, as the error will not heal itself. But there are cases, for example when network-files are used, where a watchdog may ensure further attempts until a network or server is reachable again.

In these cases it maybe advisable not to let u-boot care about the watchdog and stay with the default version. The arising problems can be cared manually:

setenv disable-wd mw fffffd44 8000
setenv reset-wd mw fffffd40 A5000001

With run disable-wd the watchdog can be disabled, if you want to work under u-boot. Execute a run reset-wd to reset the watchdog. This can be inserted in any boot-script.


  • Attached Software Package watchdog-9g20
  • Linux Sources
  • Cross Compiler



For Linux create a new image with the watchdog driver configured in. Choose Device Drivers -> Watchdog Timer Support -> AT91SAM9X / AT91CAP9 watchdog in menuconfig. Save the configuration and create a new uImage and store it at offset a0000 in NAND (or /dev/mtd4 in Linux).

Bootstrap and u-boot

Note: Current default AT91Bootstrap and U-Boot image leave the watchdog running, so updating is not needed anymore.

Interrupt the boot to get to the u-boot prompt. Now you can update the system by following these steps (You find the images in the software package):

tftpboot 20000000 bootstrap-wd
nand erase 0 20000
nand write 20000000 0 20000
tftpboot 20000000 u-boot-wd
nand erase 20000 40000
nand write 20000000 20000 40000

Now a reset should boot the new images. If your board does not boot at all, because one of the steps failed and the primary bootloader or u-boot have not been programed to flash, use the tool SAM-BA to reflash the board. A description can be found here.

Example Program

Now you can use the example program watchdog to test the installation. Have a look at the code to integrate the watchdog in your own applications.

watchdog-9g20.zip98.43 KB
Syndicate content