AVR32 watchdog peculiarities

A few short notes, after spending several days trying to figure this out:

I had some strange problems with the WDT (watchdog timer) on the AT32UC3C2512. I was able to set all options in the WDT.ctrl register, except for the enable bit (0).

The watchdog (WDT) on the AVR32 AT32UC3 can’t be enabled, if you issued a watchdog reset with zero timeout.

The solution:

I was using a bootloader (my own, based on the Atmel DFU bootloader). It launches the main program by resetting itself with the watchdog. The startup code checks the reset cause, and if the reset was due to WDT reset, it jumps to the main program. Otherwise it goes into bootloader mode, with a time-out.

My test program works fine if I flash it directly through JTAG/aWire without the bootloader. When launching through the bootloader, however, everything also works, except that the watchdog cannot be enabled.

The code in the bootloader that issues the WDT reset looked like this:

wdt_set_ctrl(AVR32_WDT_EN_MASK | AVR32_WDT_DAR_MASK |AVR32_WDT_CEN_MASK);

This enables the WDT clock, sets the “disable after reset” bit, and enables the watchdog with a time-out of zero. This has worked for a long time without problem (never tried to use the watchdog in my user programs until now). This code was also lifted directly from the ASF (Atmel’s library).

What finally fixed it: Apparently having a zero time-out blocks the enable of the watchdog. I changed the bootloader reset code like this:

wdt_set_ctrl(AVR32_WDT_EN_MASK | AVR32_WDT_DAR_MASK |AVR32_WDT_CEN_MASK | (1<< AVR32_WDT_CTRL_PSEL_OFFSET));

(same as before, but with a timeout PSEL value of 1). Now I can enable the watchdog in the user application.

What is strange is that the system resets after this command, and then launches the user application. In the bootloader, the watchdog can be enabled after a reset, and also in the main program if there is no bootloader. Apparently there is something special if the system comes out of a reset which was caused by the watchdog, if and only if the timeout was zero. Maybe it’s a safety feature, but I could not find anything about it in the datasheet, or elsewhere. If you have an idea, maybe leave a comment below.

Leave a Reply

Your email address will not be published. Required fields are marked *