7
\$\begingroup\$

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.)

\$\endgroup\$
6
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ Perhaps also relevant in the same file is the line of code stating the following? Although it seems to be commented out and refers to the Makefile: #define MAX_TIME_COUNT (F_CPU>>4) \$\endgroup\$ – boardbite Oct 14 '12 at 15:54
  • \$\begingroup\$ @Inga - You are right! I updated my answer. \$\endgroup\$ – PetPaulsen Oct 14 '12 at 16:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.