Hello,
I have a data sampling project for which I am using an Adafruit Feather M0 Express (ATSAMD21G18 Chip) as the main board. Currently, my program runs a sampling cycle in about six seconds, but I would like to get that down near one second.
My code requires the M0 to reboot twice each cycle, which I achieve using a software reset via this method:
void reboot() {
Serial.println();
Serial.println("REBOOTING...");
delay(50);
__disable_irq();
NVIC_SystemReset();
delay(5000); // should never be called
// try to reboot again forever
reboot();
}
But each reboot takes about 2 seconds (from "REBOOTING" being printed to the serial port to the first println in the setup method) which as I understand it is a built-in delay to allow for reprogramming through Arduino IDE. The combined overhead from two reboots adds up to about 4 seconds, which is a huge chunk of my 5-6 second cycle time!
Is it possible to safely modify Adafruit's UF2 Bootloader a little bit to circumvent this 2-second delay, while still being able to load a program onto the M0?
in other words,
can you load a program onto the Feather M0 "directly", i.e. without Arduino IDE?
if so, can you do it while the M0 is running a "messed up" program that e.g. crashes the board on the first line of code?
can you still recover this kind of bricked board if the bootloader is modified to skip the 2-second grace period?
I'm sorry if my questions are not clear, as I have only a year of experience working with Arduino C and no experience messing with bootloaders.
Yes, but a) how do I change the bootloader that's already on the board to my modified version, and b) how can I restore the original bootloader if my modified bootloader bricks the whole thing?
Strange. Upon inspection of src/main.c, I see that lines 118-119 say:
// this will be cleared after successful USB enumeration
// this is around 1.5s
is USB enumeration then the main cause of delay? If so, I guess I can't speed up the bootloader very much. Is the clock speed of the Cortex M0 processor itself bottlenecking me at this point?