Right now I am tinkering on my 3D printer that has an Arduino mega as a brain. I need to update the Marlin firmware but in case of an error I want to create an backup of the firmware. And because it is assembled using a shield on top have no access to the ICSP interface. And I was curious if you can extract all the flash and EEPROM via USB (UART). If yes than what software should I use to do that.


2 Answers 2


AVRDUDE which is used by the IDE to send the content of HEX file from your computer, as a feature letting it to get back the data of the flash, in order to compare and see if data are correct.

For a UNO try:

avrdude -patmega328p -carduino -P/dev/cu.usbmodemFD121 -b115200 -U flash:r:"flash.bin":r 

I think it would not be very hard to change that for a Mega.

It works fine. I have use that a lot to debut my "Android Updater" which allow the user of my board to update the code themselves.

PS: Just for info, you'll not get back the HEX file as in the flash, you have only some "pieces" of the HEX file.

  • When this works, you will in fact get back the contents of the flash. If you have doubts about it, do the process multiple times and diff the result, then examine the actual addresses capture in the hex file. Feb 4, 2018 at 21:16
  • If you send the code via ISP using the .ino.hex from the Arduino IDE, rather than the ino.with_bootloader.hex, the result is that you will have the code but no more the bootloader. So in this case, you are not able to get back the data using AVRDUDE, of course.
    – Peter
    Feb 4, 2018 at 21:23
  • 1
    Well, yes, but that has little to do with the question. If you write with the bootloader and the board is properly configured, you won't loose the bootloader. Feb 4, 2018 at 21:26
  • Not only is readback supported, avrdude depends on it in order to perform the default verify operation. Feb 4, 2018 at 21:55

It looks like my other answer was completely wrong, so I've deleted it.

Yes, you can read back the flash using the USB interface, as Chris Stratton pointed out, and Peter mentioned in his answer.

The bootloader includes a "verify" action, which means it can be used to read the flash. If you connect up the USB cable to your Atmega2560 you can read the flash back by using a command similar to this:

/usr/local/bin/arduino-1.6.9/hardware/tools/avr/bin/avrdude  `# where avrdude is`  \
-patmega2560     `# chip type: atmega2560` \
-cstk500v2       `# protocol: stk500 v2` \
-P/dev/ttyACM2   `# what serial (hardware) port the board appears on` \
-b115200         `# baud rate` \
-U flash:r:"flash.hex":i   `# save flash as "flash.hex", in Intel format` \
-C /usr/local/bin/arduino-1.6.9/hardware/tools/avr/etc/avrdude.conf  # config file for avrdude

This was done under Linux, with the command in "bash" format, which means the comments look a little strange, as I had to do that to put a comment on each line.

I've put comments on each line to show what each parameter means.

If you happen to have avrdude in your path, or are in the directory where it is installed, the brief form of the command would be:

avrdude -patmega2560 -cstk500v2 -P/dev/ttyACM2 -b115200 -U flash:r:"flash.hex":i -C avrdude.conf

You will probably (almost certainly) have to change the path to where avrdude is, and where the configuration file for avrdude is. You will also need to find out the serial port that the board is on, which you can find out from the Arduino IDE (the Port menu will show you the possibilities).

As Chris Stratton suggests, do this a few times (change the file name of course) and compare the files (eg. using "diff"). If they are all the same then you can be reasonably confident that you have got good copies.

  • Yes, though it's not a "verify" action of the bootloader, it is explicitly a page read action. It is avrdude which uses that generic capability to accomplish a verify. Feb 5, 2018 at 1:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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