Go Down

Topic: DUE watchdog timer not working (Read 225 times) previous topic - next topic

vvcogo

Hello,
I am trying to use the Arduino DUE watchdog timer to some program deadlocks on an application I am doing. So I testing the watchdog with the presented code:


void setup() {
  WDT->WDT_MR = WDT_MR_WDRSTEN
                | WDT_MR_WDRPROC
                | WDT_MR_WDV(0x5F)
                | WDT_MR_WDD(0x0);
  WDT->WDT_CR = WDT_CR_KEY(0xA5);
  NVIC_EnableIRQ(WDT_IRQn);

  Serial.begin(115200);
  pinMode(36, INPUT);

}

void loop() {
  Serial.println("C");
  WDT->WDT_CR =  WDT_CR_WDRSTT;
  if (digitalRead(36) == 1) {
      delay(17000);
      Serial.println("Not reset");
  }
}


So if the watchdog is not reseted during the delay function an timer underflow would occur and the processor would be reseted (as I could understand). I have already checked the variant.cpp file as other posts suggested but there is no watchdog disable there for the version that I have.

If someone could help me with some advice or just tell me if I am doing something stupid, it would be great.

Thank you in advance.

ard_newbie

Here is an example sketch to make the watchdog work, plus see the watchdog section of Sam3x datasheet :

Code: [Select]

#define WDT_KEY (0xA5)
/********************************************************************************
  extern "C" void _watchdogDefaultSetup (void) { WDT_Disable (WDT); }

  void watchdogSetup (void) __attribute__ ((weak, alias("_watchdogDefaultSetup")));
*********************************************************************************/

/*This function is called from init(). If the user does not provide
  this function, then the default action is to disable watchdog.
  This function has to be overriden, otherwise watchdog won't work !! */

void watchdogSetup(void) {
  /*** watchdogDisable (); ***/
}

//void watchdogDefaultSetup (void) { }

//void watchdogSetup(void) { watchdogDefaultSetup ();}

void setup()
{
  // Enable watchdog.
  WDT->WDT_MR = WDT_MR_WDD(0xFFF)
                | WDT_MR_WDRPROC
                | WDT_MR_WDRSTEN
                | WDT_MR_WDV(256 * 2); // Watchdog triggers a reset after 2 seconds if underflow
  // 2 seconds equal 84000000 * 2 = 168000000 clock cycles
  /* Slow clock is running at 32.768 kHz
    watchdog frequency is therefore 32768 / 128 = 256 Hz
    WDV holds the periode in 256 th of seconds  */

  Serial.begin(250000);
  uint32_t status = (RSTC->RSTC_SR & RSTC_SR_RSTTYP_Msk) >> RSTC_SR_RSTTYP_Pos; // Get status from the last Reset
  Serial.print("RSTTYP = 0b"); Serial.println(status, BIN);  // Should be 0b010 after first watchdog reset
}

void loop()
{

  //Restart watchdog
  WDT->WDT_CR = WDT_CR_KEY(WDT_KEY)
                | WDT_CR_WDRSTT;

  Serial.println("Enter the main loop : Restart watchdog");
  GPBR->SYS_GPBR[0] += 1; 
  Serial.print("GPBR = "); Serial.println(GPBR->SYS_GPBR[0]);
  delay(500);

  while (true)
  {
    Serial.println("the software becomes trapped in a deadlock !");
    delay(500);
    /* If the software becomes trapped in a deadlock,
       watchdog triggers a reset and software restarts with stored values
       in General Purpose Back up Registers*/
  }
}




Go Up