Digistump Forums

The DigiX => DigiX Support => Topic started by: dyoungdahl on January 01, 2014, 08:54:02 am

Title: Watchdog support?
Post by: dyoungdahl on January 01, 2014, 08:54:02 am
Does the DigiX have a watchdog interrupt and bootloader support to recover from a watchdog reset?
Title: Re: Watchdog support?
Post by: digistump on January 02, 2014, 01:47:25 am
It will be supported with examples in the upcoming release
Title: Re: Watchdog support?
Post by: digistump on January 05, 2014, 02:57:11 am
The new release supports this: http://digistump.com/wiki/digix/tutorials/software
TO use it rename Arduino\hardware\digistump\sam\variants\digix\variant.cpp to variant_nowdt.cpp and variant_wdt.cpp to variant.cpp
Title: Re: Watchdog support?
Post by: dyoungdahl on January 16, 2014, 01:25:05 pm
Thank you, sure enough 'enabling' the watchdog timer is as simple as described...  I renamed the files and recompiled/uploaded my app, and about every 8 seconds the board reset.

I then added the code to 'pat the dog' once a second, and the board no longer rebooted.

Code: [Select]
    WDT_Restart( WDT );  // pat the dog, add to main loop or somewhere that executes frequently

Next question, about changing the watchdog interval.  I played with the following code and somehow painted myself into a corner where there was not enough time between resets and java would crash partway through the upload, etc... thanks for the erase button BTW   ;)

Code: [Select]
void setup()  {
  // Variable wdp_ms hold the period in 256th of seconds of watchdog
  // It must be greater than 3 or less than or equal to 4096 (4095 ???)
  // The following value set a period of 4.5 seconds (256 x 4.5 = 1152)
    uint32_t wdp_ms = 1152 ;
    WDT_Enable( WDT, 0x2000 | wdp_ms | ( wdp_ms << 16 ));

So to wrap this up, is this the right/best way to control the watchdog interval?  It seems a little sketchy in my first tests but I need to experiment a little more to know for sure it's me or the method.

I'd also like to know how to tell if the system started as a result of a watchdog reset, but I have no clue which register to read to check that.

Any advice is appreciated.
Title: Re: Watchdog support?
Post by: tastewar on March 08, 2014, 12:21:48 pm
Where is the example code for the WDT?
Title: Re: Watchdog support?
Post by: tastewar on March 08, 2014, 06:55:17 pm
I must say the current means of including a watchdog timer is quite awkward. I had been working on a project that uses the capability, but then needed to test something much simpler. I created a sketch with no references to the WDT, compiled the sketch and uploaded it, then had to listen to my computer deal with plug/unplug events every 8 seconds.

There's got to be a better way than having to rename files that are deep in the bowels of the hardware library folder...
Title: Re: Watchdog support?
Post by: tastewar on March 09, 2014, 06:48:07 am
Alright, silly me for just reading what's here rather than having a look around the UI and the files. There's another folder called digix_wdt which has the WDT-enabled version of variant.cpp named variant.cpp, and in the UI, there is a board choice labelled "Digistump DigiX (WDT enabled)"

I've also changed my setup code a bit to hopefully disable WDT so that it's only enabled after getting past a certain point in setup:

Code: [Select]
void setup ( )
{
  WDT_Disable(WDT);
  unsigned long wdp_ms = 2048;
  unsigned long    wst;
  pinMode ( WiFiResetPin, OUTPUT );
  pinMode ( LEDPin, OUTPUT );
  digitalWrite ( WiFiResetPin, HIGH );
  digitalWrite ( LEDPin, LOW );
  ResetWiFi ( );
  Serial.begin ( 9600 );
  while( !Serial.available ( ) )
  {
     Serial.println ( "Enter any key to begin" );
     delay ( 1000 );
  }
  Serial.println ( "Starting setup..." );
  Serial2.begin ( 9600 );
  WDT_Enable( WDT, 0x2000 | wdp_ms | ( wdp_ms << 16 ));
  //...etc
}

Hopefully, that will stop any silly reboot loops because I've failed to connect to USB, open the console, and enter a character. Which should make it easier to re-program!
Title: Re: Watchdog support?
Post by: fmarkos on May 01, 2015, 10:34:47 am
Can't find variant_wdt.cpp
using DigistumpIDE1.5.8C
Can somebody help me enable the watchdog timer?