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?
-
\$\begingroup\$ Found code for reading in the bootloader, edited question. \$\endgroup\$AndreKR– AndreKR2012年06月13日 17:32:11 +00:00Commented Jun 13, 2012 at 17:32
-
\$\begingroup\$ this dosent awnser your question, but you can export your arduino skeches as a .HEX file. \$\endgroup\$uranium Lees– uranium Lees2018年07月18日 21:05:11 +00:00Commented Jul 18, 2018 at 21:05
5 Answers 5
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.
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
-
1\$\begingroup\$ attention that the programmer applicable is probably arduino and not stk500. \$\endgroup\$Paulo Neves– Paulo Neves2016年01月13日 20:54:37 +00:00Commented Jan 13, 2016 at 20:54
-
\$\begingroup\$ Why are four
-v
s necessary? \$\endgroup\$Peter Mortensen– Peter Mortensen2017年04月17日 01:05:58 +00:00Commented Apr 17, 2017 at 1:05 -
\$\begingroup\$ From AVRDUDE documentation, "2.1 Option Descriptions": "... -v Enable verbose output. More -v options increase verbosity level." \$\endgroup\$Peter Mortensen– Peter Mortensen2017年04月17日 23:00:02 +00:00Commented Apr 17, 2017 at 23:00
-
\$\begingroup\$ This should be the accepted answer. \$\endgroup\$Caterpillaraoz– Caterpillaraoz2017年12月01日 09:51:47 +00:00Commented Dec 1, 2017 at 9:51
-
\$\begingroup\$ 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
\$\endgroup\$b_laoshi– b_laoshi2019年01月04日 07:40:36 +00:00Commented Jan 4, 2019 at 7:40
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
-
\$\begingroup\$ I need a second arduino for that, right? I don't have one. \$\endgroup\$AndreKR– AndreKR2012年06月13日 17:21:43 +00:00Commented Jun 13, 2012 at 17:21
-
1\$\begingroup\$ This is a two Arduino method, yes. \$\endgroup\$jippie– jippie2012年06月13日 19:12:41 +00:00Commented Jun 13, 2012 at 19:12
-
\$\begingroup\$ And, although it's a bit hard to see in the picture, the pins used on the target Arduino are not TX0 and RX0 either, are they? \$\endgroup\$AndreKR– AndreKR2012年06月14日 22:49:43 +00:00Commented Jun 14, 2012 at 22:49
-
\$\begingroup\$ No, TX and RX are not used for ICP. Updated the answer a bit. \$\endgroup\$jippie– jippie2012年06月15日 07:00:44 +00:00Commented Jun 15, 2012 at 7:00
-
\$\begingroup\$ Well, I think you missed the whole point of my question, probably because I gave it a bad title. I rephrased the whole question. \$\endgroup\$AndreKR– AndreKR2012年06月16日 00:52:32 +00:00Commented Jun 16, 2012 at 0:52
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.
-
\$\begingroup\$ I was referring to the section that starts in line 701 with
else if(ch=='t') {
. \$\endgroup\$AndreKR– AndreKR2012年06月16日 16:48:04 +00:00Commented Jun 16, 2012 at 16:48 -
\$\begingroup\$ Good point - hadn't seen that. \$\endgroup\$RJR– RJR2012年06月26日 10:57:58 +00:00Commented Jun 26, 2012 at 10:57
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.
-
\$\begingroup\$ I have a Dragon, but I don't know which pins on the Dragon to connect to the serial interface of the Arduino. \$\endgroup\$AndreKR– AndreKR2012年06月13日 17:23:34 +00:00Commented Jun 13, 2012 at 17:23
-
\$\begingroup\$ @AndreKR see my edited answer for more info \$\endgroup\$vicatcu– vicatcu2012年06月14日 04:28:49 +00:00Commented Jun 14, 2012 at 4:28
-
\$\begingroup\$ 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. \$\endgroup\$AndreKR– AndreKR2012年06月14日 22:47:25 +00:00Commented Jun 14, 2012 at 22:47
-
\$\begingroup\$ @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" \$\endgroup\$vicatcu– vicatcu2012年06月16日 02:05:15 +00:00Commented Jun 16, 2012 at 2:05
-
\$\begingroup\$ 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. \$\endgroup\$AndreKR– AndreKR2012年06月16日 03:07:19 +00:00Commented Jun 16, 2012 at 3:07