Flash Mega2560 with SD card

Hello

I want to use the instructions under GitHub - FleetProbe/MicroBridge-Arduino-ATMega2560: Modified BootLoader to load firmware from sd or flash
to flash a Mega 2560 with SD card. The firmware update will happen only once as described:
if it is set to 0xF0 bootloader will look for a bin file on the sdcard named
firmware.bin and use it to flash the firmware then reset the byte to 0xFF so it
does this only once.

  • If I want to get the Binary file with export binary file I only see HEX files in the sketch folder. So where is it or do I need to change settings anywhere in the IDE?
  • I want to allow multiple times of flashing by pressing a momentary switch connected with a digital input.
    Once pressed a marker shall be set until flashing is done and reset afterwards allowing to initiate flashing again.
    How can I set the eeprom adress 0x1FF from the byte 0xF0 to 0xFF?

My idea is to add a routine in the main loop of the sketch which checks a momentary switch and sets the eeprom value to 0xF0 and executes a software reset as

void softwareReset( uint8_t prescaller) {
  // start watchdog with the provided prescaller
  wdt_enable( prescaller);
  // wait for the prescaller time to expire
  // without sending the reset signal by using
  // the wdt_reset() method
  while (1) {}
void(* resetFunc) (void) = 0; //declare reset function @ address 0
}

I guess setting the EEPROM can be done with EEPROM.write(addr, value);

marcel00:

  • If I want to get the Binary file with export binary file I only see HEX files in the sketch folder. So where is it or do I need to change settings anywhere in the IDE?

It's theoretically possible to make the Arduino IDE generate the .bin file for Mega 2560, but it would be a lot of work to set that up and it's a very advanced project.

Easier is to just use avr-objcopy as recommended in the documentation of MicroBridge-Arduino-ATMega2560. That documentation assumes you're using the .elf file, which is a bit more difficult to find than the .hex file conveniently saved to the sketch folder by the Arduino IDE's Sketch > Export Compiled Binary feature. You can make the .bin file from the .hex file instead of the .elf file using this command:

avr-objcopy -I ihex -O binary firmware.ino.microbridge.hex firmware.bin

Note that avr-objcopy comes with the Arduino IDE in the hardware/tools/avr/bin subfolder of the Arduino IDE installation folder.

marcel00:
I guess setting the EEPROM can be done with EEPROM.write(addr, value);

Correct. You can find the documentation of the EEPROM library here:
https://www.arduino.cc/en/Reference/EEPROM

pert:
It's theoretically possible to make the Arduino IDE generate the .bin file for Mega 2560, but it would be a lot of work to set that up and it's a very advanced project.

to platform.local.txt

## Create output (bin file)
recipe.objcopy.bin.pattern="{compiler.path}{compiler.elf2hex.cmd}" -O binary {compiler.elf2hex.extra_flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.bin"

it will always create a bin file too

how to set EEPROM flag

hello juraj

in which folder can I find platform.local.txt?

marcel00:
hello juraj

in which folder can I find platform.local.txt?

create a new file named platform.local.txt next to platform.txt of arduino avr boards package. for avr there are two possiible locations. the IDE installation folder or the Arduio15 folder in user home folder
~/.arduino15/packages/ on Linux
and %userprofile%\AppData\Local\Arduino15\packages\ on Windows (AppData is a hidden folder).

hello juraj in my case it was in the folder C:\Program Files (x86)\Arduino\hardware\arduino\avr
A binary file was created now. Thank you!

I want to change the status LED for flashing to pin 43 or port pin PL6. The bootloader stk500boot.c as
shown on MicroBridge-Arduino-ATMega2560/stk500boot.c at master · FleetProbe/MicroBridge-Arduino-ATMega2560 · GitHub
has got the led setting for a MEGA 2560 in the section

#ifdef _MEGA_BOARD_
	#define PROGLED_PORT	PORTB
	#define PROGLED_DDR		DDRB
[i]#define PROGLED_PIN	PINB7[/i]

How can I compile the bootloader to a HEX file and transfer it to the Arduino MEGA2560 with the Arduino IDE?

You can't compile the bootloader using the Arduino IDE. You need to use make following the instructions in the MicroBridge-Arduino-ATMega2560 documentation.

After you've done that, you can flash the bootloader to your Mega 2560 using the Arduino IDE. You'll need an ISP programmer. If you don't have an ISP programmer, you can use a spare Arduino as an "Arduino as ISP" programmer:

  • Connect the ISP programmer to your Mega 2560.
  • Tools > Board > Arduino Mega 2560 (DUAL SD Bootloader)
  • Tools > Programmer > select the appropriate programmer
  • Tools > Burn Bootloader