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