AT91SAM9 Linux Watchdog

June 14, 2008 – 12:32 pm
A driver for the AT91SAM9 watchdog timer was introduced in Linux v2.6.23.  Unfortunately, there are some “issues” with this driver that prevent it from working in all cases. Specifically, in my case, the AT91SAM9260 would not boot from the Dataflash when the watchdog faulted and caused a CPU reset.The issues and my proposed solutions follow. cujo-dog

1) The default at91bootstrap code disables the watchdog functionality.

In at91bootstrap, in at91sam9260ek.c, in the hw_init function, remove the line that disables the watchdog and replace it with a line that pats the dog as follows:

/* Disable watchdog */
/*writel(AT91C_WDTC_WDDIS, AT91C_BASE_WDTC + WDTC_WDMR);*/
writel(AT91C_WDTC_WDRSTT|AT91C_WDTC_KEY, AT91C_BASE_WDTC + WDTC_WDCR);  /* pat the dog early */

Recompile at91bootstrap and load it using SAM-BA or whatever tool you use to flash this to your board. 

2) The Linux driver didn’t set the watchdog up to reset the peripherals.  This means that when the watchdog faulted and reset the CPU, the peripherals (DataFlash in this case) weren’t being set to a good state.  In order to do this, the WDRPROC bit in the watchdog timer register has to be set to 1. 

3) The external reset length (ERSTL) bits in the reset controller (RSTC) mode register weren’t being set to a number that allowed the SAM9260 ROMboot to detect the presence of the DataFlash upon reboot. 

Basically, ROMboot tries 3 boot methods:

1) boot from DatafFlash on chip select 0 (CS0), timeout after “< 1 sec.”

2) boot from DataFlash on chip select 1 (CS1), timeout after “< 1 sec.”

3) boot from NAND flash, timeout “1 sec Typ.”

4) if all else fails, try USB enumeration and boot to SAM-BA

In my case, the 9260 was only booting to the ROMboot> prompt and going no further and wasn’t detected by SAM-BA.  Dialog with others who’ve used this driver with NAND flash led me to believe that this issue only occurred when booting from DataFlash. 

To keep from boring you with the ugly details, it turned out that having a long ERSTL is a Bad Thing® when booting from DataFlash, because the CPU doesn’t detect the DataFlash as long as the NRST pin is asserted.  So, if the ERSTL is set to 2 seconds (it’s maximum value), steps 1 and 2 above would both timeout since the NRST is asserted for 2 seconds and ROMboot would try to detect the NAND flash.

To resolve this, I set the ERSTL to assert for 512 milliseconds (i.e. supplied a value of 8 in the ERSTL bits since ERSTL is calculated as 2(ERSTL+1).  It could be set to a lower value, say 256 milliseconds, but 512 works just fine for me.

4) The reset controller (RSTC) mode register has to be set to perform a user reset on the detection of a low level (assertion) of the NRST pin.  This is done by setting the URSTEN (User Reset Enable) bit to 1. 

I created a patch to correct issues 2 - 4 as long as CONFIG_MTD_DATAFLASH is enabled in your kernel’s .config.

Also note that I’ve modified the kernel a bit to achieve a 14 sec. boot time since I always boot from a certain image type and it doesn’t need to check for the non-existent type.  This shaves at least 5 seconds of boot time.  So, you may need to put code in the kernel to pat the dog else you’ll never get to a prompt since the watchdog faults in 16 seconds by default. 

Edit:  The patch is available at http://www.jandasoft.biz/files/patches/AT91SAM9260/2.6/sam9_watchdog.patch

Coffee helps me clear the fog. If you've found any of the posts on this blog helpful, I could always use more coffee.

  1. 6 Responses to “AT91SAM9 Linux Watchdog”

  2. Wow, Coleman! That must’ve been some debug session! Nice to see you got things working. - Steve

    By Steve on Jul 13, 2008

  3. Hi Coleman

    I am checking this issue as you said.
    conerning path you main is for linux kernel?
    option 2 and 4, is need to modify kernel part?
    In addition to where can I find path file?

    Thanks in advance.
    Bryan Chang

    By Bryan on Feb 2, 2009

  4. The same problem. I have custom PCB based on AT91SAM9260, SPI dataflash on CS0, watchdog disabled. After powerup boot from dataflash OK, but after NSRT dataflash not detected. Different ERSTL vaules not helps…(

    By MSL on Feb 18, 2009

  5. Bryan,

    I’m not sure I understand your questions. I’ve been working on submitting a patch to the mainstream kernel, but have not had a chance to do so. I will try to make it available for the 2.6.23 kernel on this site. I’ll modify the post when it’s available.

    Please note that ALL of the things I’ve listed in the article have to occur for the watchdog to work correctly.

    By Coleman Brumley on Feb 18, 2009

  6. MSL,

    Your ERSTL is too long. What values are you trying?

    By Coleman Brumley on Feb 18, 2009

  7. Hi Coleman,

    Thanks for the post. Re:

    Also note that I’ve modified the kernel a bit to achieve a 14 sec. boot time since I always boot from a certain image type and it doesn’t need to check for the non-existent type. This shaves at least 5 seconds of boot time.

    Can you point me to the code segment to change here ? Is it some where in main.c. A faster boot up time is also important to us, give the 16 s timeout.

    Much appreciated

    Gertjan

    By Gertjan on Jun 15, 2009

Post a Comment