#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) >> 8; // 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");
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*/
}
}
Just wanted to check if anyone had any experience or recommendations as I expect this problem has been ran into before.
Rule 1 of EV Club is don't buy a rust bucket....
Which rule does everyone forget
rstevens81 wrote: ↑Tue Feb 09, 2021 11:03 am
Just wanted to check if anyone had any experience or recommendations as I expect this problem has been ran into before.
Thank you much for the variation!
I have tested this code. However i cant measure if it is in fact working.... it doesnt seem to trip anymore.
Do you think i could set a flag for watchdog reset, save it to EEPROM and count how many times is was tripped?
Watchdog
https://forum.arduino.cc/t/watchdog-timer-arm-arduino-due-board-ide-1-8-9/663311
https://forum.arduino.cc/t/arduino-due-watchdog/486187
rstc_start_software_reset(RSTC); //DUE reset command
*/
/********************************************************************************
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 !! */
#define WDT_KEY (0xA5)
//These two lines redefine any serial calls to the native Serial port on the CANdue or EVTVDue and enables syntactic sugar to allow streaming to serial port Serial<<"Text";
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 */
//Inside Void loop restart watchdog
WDT->WDT_CR = WDT_CR_KEY(WDT_KEY)
| WDT_CR_WDRSTT;
/* If the software becomes trapped in a deadlock,
watchdog triggers a reset and software restarts with stored values
in General Purpose Back up Registers*/