Electronic – arduino – “Faster” Arduino bootloader

arduinobootloader

The Arduino bootloader has a wait-time to facilitate "sketch" (code) uploading; this causes a delay of a couple of seconds before the start of the main code.

I would like to modify the bootloader file (specifically for the Arduino Mega) so as to reduce this time to less than 1000 milliseconds at most.

I am unsure how to get started on this — Could someone point me in the correct direction?

(Note: I am aware that I can instead directly upload only the hex file corresponding to my firmware, but in this case, I would like to maintain the bootloader.)

Best Answer

For an overview of the bootloader take a look at the Bootloader Development page.

The actual source code is available and can be browsed here. To modify the wait time (or the behaviour of the waiting) take a look at the ATmegaBOOT.c file.

In line 91 is MAX_ERROR_COUNT defined and used to determine when to start the actual application on your arduino. To decrease the waittime, I would start by setting MAX_ERROR_COUNT to a lower value.


After you posted your comment I had another look at the source code.

At line 433 the "forever loop" is startet and in line 436 the function getch() is called. In this function there is another loop, that checks for a received character. If no character is received within a given timespan the application code is getting called. The duration of the timespan is determined by MAX_TIME_COUNT.

So changing MAX_TIME_COUNT seems to be more suitable then changing MAX_ERROR_COUNT.