Skip to content

Commit

Permalink
Added Reset Cause debugging and disabling BOD
Browse files Browse the repository at this point in the history
Uncommit define statements at the beginning of code to toggle printing the reset cause (DEBUG) or to disable Brown-out Detection for 1.2 volts or Brown-out Detection for 3.3 volts.  Most glitches that result in reboot will trigger the BOD12.  Disabling that detection will allow the microcontroller to continue running; however, this may have unforeseen results (i.e. be prepared to de-brick your device).
  • Loading branch information
gglessner authored Mar 18, 2023
1 parent 19e0ccc commit aa72897
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions Adafruit-M0/target-code.ino
Original file line number Diff line number Diff line change
@@ -1,9 +1,38 @@
//#define DEBUG
//#define DISABLE_BOD12
//#define DISABLE_BOD33

void setup() {
// put your setup code here, to run once:
Serial.begin(115200); // open the serial port at 115200
Serial.print("Serial port setup\n");
digitalWrite(13, LOW);

#ifdef DISABLE_BOD12
*((volatile uint32_t *)0x40000838) = 4;
#endif

#ifdef DISABLE_BOD33
SYSCTRL->BOD33.bit.ENABLE = 0;
#endif

#ifdef DEBUG
delay(5000);
Serial.print("DEBUG - Reset Cause:");
if(PM->RCAUSE.bit.SYST)
Serial.println(" System (software) reset");
if(PM->RCAUSE.reg & PM_RCAUSE_WDT)
Serial.print(" Watchdog timer reset");
if(PM->RCAUSE.bit.EXT)
Serial.print(" External (reset button) reset");
if(PM->RCAUSE.bit.POR)
Serial.print(" Power-on reset");
if(PM->RCAUSE.bit.BOD12)
Serial.print(" Brown-out detection - 1.2v");
if(PM->RCAUSE.bit.BOD33)
Serial.print(" Brown-out detection - 3.3v");
Serial.println();
#endif
}

void loop()
Expand Down

0 comments on commit aa72897

Please sign in to comment.