Burn new bootloader in Arduino Mega 2560 R3

Alkerion:
=> ERROR:

avrdude: can't open input file C:\Users...\Arduino\hardware\my_boards\avr/bootloaders/stk500v2/stk500boot_v2_mega2560_22Mhz.hex: No such file or directory

Something going wrong as there is no .hex file :frowning:

That's because you must create the .hex file by compiling the bootloader.

So how do you do that?:

Since you're using Windows, the process is a bit more difficult, since some of the required tools are not installed with a stock Windows installation, as they are with Linux or macOS. The easiest way to get them is via Git Bash, which you get by installing Git for Windows: Git - Downloading Package

Open the folder my_boards\avr\bootloaders\stk500v2 in Windows Explorer

Right click > Git Bash Here

In order to compile the bootloader, you need to use the avr-gcc compiler. Luckily, that comes with the Arduino IDE so you only need to add its folder to the system path. You do that by running a command from the Git Bash prompt that looks something like this:

PATH="${PATH}:/c/Program Files (x86)/Arduino/hardware/tools/avr/bin"

The above command is for an installation of the Arduino IDE at C:\Program Files (x86)\Arduino. If your Arduino IDE is installed somewhere else, you'll need to adjust it accordingly. Note that paths work a little differently in Git Bash. The drive letter is specified like /c/ instead of C:\ and you can't use \ as a path separator.

Now run this command from the Git Bash prompt to remove the previous compilation files from the folder:

make clean

Now it's time to compile the bootloader. I see you have modified the mega2560 in the makefile. So you only need to run this command from the Git Bash prompt:

make mega2560

Now wait for the compilation to finish successfully. The compiled bootloader will be my_boards\avr\bootloaders\stk500v2\stk500boot_v2_mega2560.hex. You can rename the file as you like.

If you're feeling very cocky with your bootloader compiling skills now and want to go for extra credit by upgrading to the superior Optiboot bootloader (which only requires a 1 kB boot section instead of the 8 kB boot section of the STK500V2 bootloader, freeing up 7 kB of program memory), you can find the source code here:

The same process as above applies to compiling optiboot. The only difference is that the target is named atmega2560 instead of mega2560 and you can specify the CPU frequency from the command line, rather than modifying the makefile:

make atmega2560 AVR_FREQ=22114800L