16

I acquired an Arduino PCB with an ATmega2560, already programmed with the Arduino bootloader and some program. I do have the sketch, but before fiddling with it, I'd like to backup the current binary that is in the controller. As most Arduinos, it's connected to the PC using an USB-to-serial converter connected to TX0 and RX0 and there is no ISP interface.

Apparently there is code for reading in the Arduino bootloader, but I have no idea which tool to use to access it as there is no menu item in the Arduino IDE.

What software do I need to read the program from the Arduino?

Peter Mortensen
  • 1,676
  • 3
  • 17
  • 23
AndreKR
  • 2,999
  • 3
  • 22
  • 28

5 Answers5

11

I've dumped a memory from Duemillenova with ATMega328P with the following command:

avrdude -C avrdude.conf -v -v -v -v -p atmega328p -c stk500 -U flash:r:"c:/arduino.hex":r -P\\.\COM2 -b57600
user17555
  • 111
  • 1
  • 2
  • 1
    attention that the programmer applicable is probably arduino and not stk500. – Paulo Neves Jan 13 '16 at 20:54
  • Why are four `-v`s necessary? – Peter Mortensen Apr 17 '17 at 01:05
  • From [AVRDUDE documentation, *"2.1 Option Descriptions"*](http://www.nongnu.org/avrdude/user-manual/avrdude_4.html#Option-Descriptions): *"... -v Enable verbose output.* ***More -v options increase verbosity level.***" – Peter Mortensen Apr 17 '17 at 23:00
  • This should be the accepted answer. – Caterpillaraoz Dec 01 '17 at 09:51
  • YES! The pro micro bootloader didn't work on my pro micro clone. I dumped the flash from a working pro micro clone and saved to the one that needed a bootloader. Using an Arduino as ISP (linux) -- dump: `./avrdude -C ../etc/avrdude.conf -v -v -v -v -p ATmega32u4 -c arduino -b 19200 -U flash:r:"/tmp/dump.bin":r -P /dev/ttyUSB0`; write: `./avrdude -C ../etc/avrdude.conf -v -v -v -v -p ATmega32u4 -c arduino -b 19200 -U flash:w:"/tmp/dump.bin":r -P /dev/ttyUSB0`; verify: `./avrdude -C ../etc/avrdude.conf -v -v -v -v -p ATmega32u4 -c arduino -b 19200 -U flash:v:"/tmp/dump.bin":r -P /dev/ttyUSB0` – b_laoshi Jan 04 '19 at 07:40
7

Does the Backup AVR with avrdude thread answer your question? Basically you can read all memory from an AVR as long as the protection fuse isn't set.

This is the setup I use for ATtiny's and ATmega's.

On the board shown:

  • 11 = MOSI
  • 12 = MISO
  • 13 = SCLK

Refer to the datasheet of the controller which exact pin to use. There are quite a few websites on Internet writing about programming AVR's using an Arduino, eg.: http://hlt.media.mit.edu/?p=1229

jippie
  • 33,033
  • 16
  • 93
  • 160
3

As far as I can see form the Arduino bootloader source code, there's no way to 'dump' all memory from it. The bootloader does support a 'monitor' mode which allows you to dump one memory byte at a time. However, as per the source code comments "/* monitor functions will only be compiled when using ATmega128, due to bootblock size constraints */"

As such, I guess you're out of luck if you don't want to use ISP, change the bootloader or upload a sketch to do it.

RJR
  • 1,617
  • 11
  • 14
2

I thought there was a menu option for that but I'm not finding it right now. If you have an ISP programmer, you can use AVR Studio to Read the memory image off the chip and save it off in a HEX file, that would allow you to restore it through the same means.

Edit

In response to your comment - that's easy! You need to assimilate two diagrams worth of information to pull it off. The first is the Arduino / ATMega2560 Pin Mapping.

enter image description here

The second is the ISP Header / AVR Pin Mapping:

enter image description here

Armed with these two pictures, you should be able to see how to wire it up.

  • Run a wire from DIG50 to Dragon ISP header pin 1
  • Run a wire from VCC to Dragon ISP header pin 2
  • Run a wire from DIG52 to Dragon ISP header pin 3
  • Run a wire from DIG51 to Dragon ISP header pin 4
  • Run a wire from RESET to Dragon ISP header pin 5
  • Run a wire from GND to Dragon ISP header pin 6

With those in place, you should be able to use AVR Studio to read the Hex file off the chip - let me know if you need more guidance.

vicatcu
  • 22,499
  • 13
  • 79
  • 155
  • I have a Dragon, but I don't know which pins on the Dragon to connect to the serial interface of the Arduino. – AndreKR Jun 13 '12 at 17:23
  • @AndreKR see my edited answer for more info – vicatcu Jun 14 '12 at 04:28
  • As stated in my question, I know how to read the program using ISP, of course. What I want to know is how to do it using the serial interface (TX0 and RX0) - the same way the programs are uploaded to the controller in the Arduino world. – AndreKR Jun 14 '12 at 22:47
  • @AndreKR I'm confused... you have a dragon, why would you not want to read the program in the normal way - I misunderstood your comment about not knowing which pins to connect to the "serial interface" – vicatcu Jun 16 '12 at 02:05
  • The PCB I have doesn't have an ISP header. However, it has a serial interface and an Arduino bootloader. That way the programs are uploaded in the Arduino world, and apparently they can be downloaded the same way. – AndreKR Jun 16 '12 at 03:07
  • @AndreKR, have you not read what the bootloader does? or why we use ISP and not serial to do this? The bootloader provides the means to upload sketches to flash (through serial), and if none received, run the last one on there. http://arduino.cc/en/Main/Bootloader You will have to devise your own means to have the flash memory read through ISP. Serial is read by the software (already onboard), and in this case is just a convenience for USB programming. – Kenny Robinson Jun 16 '12 at 09:04
  • Please see in the source I linked to the section that starts in line 701 with `else if(ch=='t') {`. – AndreKR Jun 16 '12 at 16:50
  • @AndreKR the Arduino bootloader is a variant of the original STK500 protocol (1.x): http://www.atmel.com/Images/doc2525.pdf. 't' = 0x74 which is the "Read Page" command. So perhaps its possible to pull the program out through the serial port via the bootloader... but at best I reckon it will take some fancy timing to pull it off. – vicatcu Jun 18 '12 at 03:58
  • Now that is a useful reference. Maybe you could make an answer out of it, that we can improve when we find more information? – AndreKR Jun 19 '12 at 21:41
1

The Arduino bootloader is a variant of the original STK500 protocol (1.x). The character 't' (ASCII 0x74) is the "Read Page" command. So perhaps it is possible to pull the program out through the serial port via the bootloader using AVRDUDE... But at best I reckon it will take some fancy timing to pull it off.

Peter Mortensen
  • 1,676
  • 3
  • 17
  • 23
vicatcu
  • 22,499
  • 13
  • 79
  • 155