Changing the Bootloader on MEGA
This page serves as a guide to change the bootloader on MEGA and prepare the binary firmware files.
Last updated
This page serves as a guide to change the bootloader on MEGA and prepare the binary firmware files.
Last updated
The following page includes definitions and explanations on the bootloader. You might want to have a look:
There is a number of steps to follow before making the MEGA able to change its firmware by reading a file from an SD card. Follow this guide to set everything correctly.
First, upload ArduinoISP code found under examples within the Arduino IDE to an Uno board without changing any board settings. This means go to Tools > Board and select Arduino/Genuino UNO.
Then connect the UNO to the MEGA in the following way:
UNO (Programmer) | MEGA (Receiver) |
Pin 13 (SCK) | Pin 52 (SCK) |
Pin 12 (MISO) | Pin 50 (MISO) |
Pin 11 (MOSI) | Pin 51 (MOSI) |
Pin 10 | Reset |
5V | 5V |
GND | GND |
Now you are ready to burn the bootloader. For that, first, download the following repo:
Unrar and extract all the files to the hardware directory in your Arduino folder; for example, D:\Program Files (x86)\arduino-1.8.9\hardware
Restart the Arduino IDE.
Now you should be able to see "Arduino Mega 2560 (DUAL SD Bootloader)" option in the Board menu under the Tools. Select that. It is the bootloader we want to upload.
Go to Tools > Port and select the port UNO is connected.
Go to Tools > Programmer and select "Arduino as ISP".
Go to Tools and select "Burn Bootloader". Now if it all goes successfully, it means you have changed the bootloader on MEGA. Proceed with obtaining the binary (.bin) file that you want to upload to your MEGA. Arduino IDE does not generate bin files directly while compiling a project but there is a way of doing it using avr-objcopy which is a command that comes with both Arduino IDE and Atmel Studio (more on that later). First, find the temporary folder the IDE uses to store compiled files when compiling a project. You can find the address of the folder written at the end of the output prompt in the IDE. See the following example. It shows the output for when the Blink example in the Arduino IDE is being compiled.
As an example, on my computer, it is located here:
Find the folder and copy the .elf file to a known location. Now use the avr-objcopy command to convert the elf file to a bin file. For this:
Open a command prompt (search for "command prompt" in the start menu or open "run" and search "cmd")
Change directory to the "bin" folder under the packages in your arduino folder OR avr8-gnu-toolchain (if you have Atme Studio installed). Again, for my computer, avr-objcopy is located under two different directories:
Now use the following command to convert elf to bin:
For example:
This generates "firmware.bin" file which you can put on an SD card. The bootloader is programmed to check for the address 0x1FF at every restart and if it sees 0xF0 there, it starts checking for a file named "firmware.bin" in the SD card that is supposed to be connected to the MEGA. If there is no file or no SD card, the program starts as normal. If the file is there, you will see the onboard LED (on pin 13) flashing while the new firmware is being uploaded.
The SD card reader to be used with your Arduino should have an integrated 5 to 3.3V voltage regulator. The adaptor in the following link works as expected:
Wire the card reader as in the following table:
Card Reader | MEGA |
SCK | Pin 52 (SCK) |
MISO | Pin 50 (MISO) |
MOSI | Pin 51 (MOSI) |
CS | Pin 53 (can be changed within the bootloader) |
5V | 5V |
GND | GND |
If you include a line in your code that writes 0xF0 to address 0x1FF in the eeprom, then at every restart your MEGA will check for an update in the SD card. Congratulations! You have made your chip SD-updatable.
Download Atmel Studio 6.1 or higher: