Pages: [1]   Go Down
Author Topic: Reset the Arduino Due board using the watchdog  (Read 3052 times)
0 Members and 1 Guest are viewing this topic.
Bologna, Italy
Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

St. Leonards-on-Sea, E. Sussex, UK.
Offline Offline
Sr. Member
****
Karma: 2
Posts: 301
Ancient developer
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
  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.
« Last Edit: March 09, 2013, 03:03:36 am by Leon Heller » Logged

Leon Heller
G1HSM

Italy
Offline Offline
Newbie
*
Karma: 1
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: March 09, 2013, 12:03:46 pm by SimonCino » Logged

Offline Offline
Full Member
***
Karma: 3
Posts: 112
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Bologna, Italy
Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Full Member
***
Karma: 0
Posts: 144
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Full Member
***
Karma: 0
Posts: 144
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: