Reset the Arduino Due board using the watchdog

Hi everyone,
I would like to find a way to reset the board by software instructions. I think this should be possibile configuring the watchdog, but I didn't find nothing related to the Arduino Due.
The goal I want to achieve is to restart the board when some condition happens. Any way to do that will be fine for me, but I have not to touch any hardware or to trigger the reset by an external divece.

Thank you in advance
carmo

A software reset on the ARM7 chips, such as the LPC2148, was performed by setting the WDT to a very short period and enabling it:

  WDTC = 0x00000FFF;  // very short timeout
  WDMOD = 0x03;       // watchdog resets CPU
  WDFEED = 0xAA;      // start watchdog
  WDFEED = 0x55;

Something similar might be possible on the Cortex-M3.

Hi,

I'm new with Arduino due and your question is very interesting. I had a look of the mcu data sheet at chapter 17 (watchdog) and I tried to make it working. The first step is to avoid that the function init() inside the file variant.cpp (....\hardware\arduino\sam\variants\arduino_due_x) disable the watchdog by commenting the function WDT_disable(WDT) otherwise you'll not able to enable the watchdog later (the register REG_WDT_MR can be written only once) then in the setup() function inside the sketch I inserted the following instruction:
REG_WDT_MR = 0x0fff2fff;

In order to have the WDT activated.
Now you can use the instruction to reset the WDT:
REG_WDT_CR = 0xa5000001

If you want to reset just avoid to execute the last instruction in the main() function and after 16seconds from the last call the WDT shall reset the mcu and the sketch start again.
I hope my suggestion can be a good starting point.
Kind Regards.

P.s.: remember to remove the comments that you inserted in the variant.cpp file when you don't need the WDT inside your sketch.

void Software_Reset() {
//============================================================================================
// führt ein Reset des Arduino DUE aus...
//
// Parameter: keine
// Rueckgabe: keine
//============================================================================================
const int RSTC_KEY = 0xA5;
RSTC->RSTC_CR = RSTC_CR_KEY(RSTC_KEY) | RSTC_CR_PROCRST | RSTC_CR_PERRST;
while (true);
}

Thank you very much to everyone!

I tried the paulinchen's solution and it works. SimonCino, I will try also the one you suggested it can be very useful in several contests.

Does anyone know why the watchdog is disabled inside init() if it can only be written once?

Sorry for the premature question.
I found the answer inside the wdt.c:

  • The WDT is running at reset with 16 seconds watchdog period (slow clock at 32.768 kHz)
  • and external reset generation enabled. The user must either disable it or
  • reprogram it to meet the application requires.

SimonCino:
Hi,

I'm new with Arduino due and your question is very interesting. I had a look of the mcu data sheet at chapter 17 (watchdog) and I tried to make it working. The first step is to avoid that the function init() inside the file variant.cpp (....\hardware\arduino\sam\variants\arduino_due_x) disable the watchdog by commenting the function WDT_disable(WDT) otherwise you'll not able to enable the watchdog later (the register REG_WDT_MR can be written only once) then in the setup() function inside the sketch I inserted the following instruction:
REG_WDT_MR = 0x0fff2fff;

In order to have the WDT activated.
Now you can use the instruction to reset the WDT:
REG_WDT_CR = 0xa5000001

If you want to reset just avoid to execute the last instruction in the main() function and after 16seconds from the last call the WDT shall reset the mcu and the sketch start again.
I hope my suggestion can be a good starting point.
Kind Regards.

P.s.: remember to remove the comments that you inserted in the variant.cpp file when you don't need the WDT inside your sketch.

That works very good in Arduino Due! Thank you xD
But can i change the watchdog from 16seconds, to 3 seconds or 2 seconds???

Take a look at this newer thread:
DUE Watchdog usage

In particular, how they shift the __WDP_MS definition by 16 bits.

In this older thread, they use "REG_WDT_MR = 0x0fff2fff", which sets the highest 16 bits to 0x0fff (4095), which I believe is the highest timer length possible (4095 / 256 = 15.996, almost 16 seconds).