-
Notifications
You must be signed in to change notification settings - Fork 325
Description
I've been experiencing an issue where poor power rails cause the bootloader to be entered spontaneously. You can simulate this by applying power to a Feather M0 by holding the ends of two wires together to complete the path to the positive power supply, and then rub them to make a series of interrupted power spikes.1
I think this is triggering the brown-out detection circuitry, and setting the RESET_CONTROLLER->RCAUSE.bit.BODxx bit(s), rather than RESET_CONTROLLER->RCAUSE.bit.POR. The code, as written in main.c interprets this as the user pressing the reset button, and it enters the boot loader.
Ignoring SINGLE_RESET, I think more robust code might look like this. I have not tested this as I currently have no way to load the boot loader:
if (RESET_CONTROLLER->RCAUSE.bit.POR // If power-on reset
|| RESET_CONTROLLER->RCAUSE.bit.BOD12 // or either brown-out
|| RESET_CONTROLLER->RCAUSE.bit.BOD33 ) { // reset, clear *DBL_TAP_PTR
*DBL_TAP_PTR = 0;
} else if (RESET_CONTROLLER->RCAUSE.bit.EXT // If user pressed reset button
&& *DBL_TAP_PTR == DBL_TAP_MAGIC) { // AND it’s the second time through
*DBL_TAP_PTR = 0;
return; // stay in bootloader
} else { // This should probably check RESET_CONTROLLER->RCAUSE.bit.EXT, too
if (*DBL_TAP_PTR != DBL_TAP_MAGIC_QUICK_BOOT) {
*DBL_TAP_PTR = DBL_TAP_MAGIC;
delay(500);
}
*DBL_TAP_PTR = 0;
}This change should do a couple of things: treat power-on and brown-out-detect resets the same, and only count a /RESET assertion as the second press.
I’m not sure if the SAM51 has different BOD bits.
Footnotes
-
In my case, I have an Adafruit solar lipo charger. When the battery is depleted and the sun is just beginning to shine on the panel, the power provided to the load can be spotty. ↩