Skip to content

Instantly share code, notes, and snippets.

@facchinm
Created May 8, 2015 12:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save facchinm/dff2c596f1fa23e1702f to your computer and use it in GitHub Desktop.
Save facchinm/dff2c596f1fa23e1702f to your computer and use it in GitHub Desktop.
Watchdog Due
// 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);
}
}
@q2dg
Copy link

q2dg commented Oct 22, 2015

Well...I asked the same question here (arduino/Arduino#3889 (comment)) but I haven't got response. I wouldn't like to bother you, but it's a fast answer: Is there any chance to generalize this API to other boards (328-based, 2560-based, 32U4-based, Zero...) in order to homegenize this feature?
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment