arduino due e watchdog

ciao a tutti,

ho un arduino due e non riesco ad usare il watchdog, oltre a controllare che il programma non si blocchi, vorrei usarlo per resettare la scheda.

ho provato varie esempi in rete ma nulla, molti non sono per arduino due.

aiuto.

grazie

La libreria standard è solo per AVR, però il ns. moderatore Leo, all'epoca (2013) aveva scritto una libreria ...
... che trovi QUI.

Guglielmo

P.S.: Se il tuo antivirus ti segnala qualche cosa sul quella pagina, è un falso positivo.

Ciao, grazie,

provo e vi faccio sapere.

grazie molte

Il watchdog è stato implementato nel DUE recentemente, senza l'utilizzo di librerie esterne.

Questo codice demo ti permette di testarlo.

// watchdog sam test 
// initialize watchdog and then hardfault
// and see averything restarting

int counter = 0;
int limit = 200;
int limit2 = 0;

void print2(void) {
  Serial.println("print2");
  limit2++;
  if (limit2 > 200) {
    counter = 0;
  }
}

void print3(void) {
  Serial.println("print3");
  limit2++;
  if (limit2 > 200) {
    counter = 0;
  }
}

void UndefinedInstruction(void) 
{
//__asm__ __volatile__ (  "DCI	0xf123" 
//                        "DCI	0x4567"
//                        "BX	LR"  );
} 

void BadAlignedLDM(void) 
{ 
__asm__ __volatile__ ( "MOVS r0, #1;" 
                       "LDM r0,{r1-r2}; "
                       "BX	LR ;");
} 

void watchdogSetup(void) {
  //do nothing, simply override weak function
  //SerialUSB.println("watchdogSetup");
}

void doHardfault() {
  Serial.println("sending hardfault");
  //division by zero will not report an error if this bit is not activated
  SCB->CCR |= 0x10;
  int a = 10;
  int b = 0;
  int c;
  c = a/b;
  Serial.println(c);
}

void setup() {
  //give time to ttyACM driver to come up
  Serial.begin(115200);
  delay(3000);
  pinMode(2, INPUT);
  pinMode(3, INPUT);
  Serial.println("Board booting up");
  //enable watchdog with 1 second timeout
  //watchdogEnable(1000);
  attachInterrupt(2, print2, RISING);
  attachInterrupt(3, print3, RISING);
  pinMode(13, OUTPUT);
}

void loop() {
  counter++;
  //watchdogReset();
  delay(20);
  Serial.println(counter);
  if (counter == limit) {
    // comment doHardfault and uncomment delay if you want
    // to test against long pause
    doHardfault();
    //BadAlignedLDM();
    //delay(5000);
  }
  if (counter > limit) {
    Serial.println("watchdog didn't work");
    noInterrupts();
    digitalWrite(13, HIGH);
    interrupts();
    delay(100);
    digitalWrite(13, LOW);
    delay(100);
  }
}

PS.

Non cross-postare (anche in lingue diverse)