Go Down

Topic: Reset the Arduino Due board using the watchdog (Read 4010 times) previous topic - next topic

carmo

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

Leon Heller

#1
Mar 09, 2013, 08:59 am Last Edit: Mar 09, 2013, 09:03 am by Leon Heller Reason: 1
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:

Code: [Select]

  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.
Leon Heller
G1HSM

#2
Mar 09, 2013, 05:36 pm Last Edit: Mar 09, 2013, 06:03 pm by SimonCino Reason: 1
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.

paulinchen

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);
}

carmo

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.

newhobby

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

newhobby

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

* 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.

Go Up