Do you know if it is possible to read a program already uploaded on arduino? I suppose that the code will not be c++ but something near assembly but it doesn't matter.
Thanks
You may be able to retrieve the databytes that are there in hex format, if the Lock bits weren't set to preclude that.
Then you would need to "dissamble" the data and try to make sense of it as program.
Not an easy task.
retrieving the binary can be done with avrdude.exe
The documentation is in the Arduino distribution, but be aware that you will get a dump of the Flash (32 K) which is only partial the program (most of the times)
The rest is residu from larger programs and maybe just plain zero's
As said not trivial.
If you hold the shift key while uploading you will see the AVRDUDE command to upload, the download has 90% the same parameters.
Depending on the exact device and programmer you have, something like:
avrdude -c usbtiny -p m328p -U flash:r:myfile.hex:i # <---- read from device into myfile.hex
avr-objdump -j .sec1 -d -m avr3 myfile.hex # <-- disassemble myfile.hex
You probably need to replace "usbtiny" with your own programmer and add the comm port number. What robtillaart said, basically.
For download of an stk500 compile on a Arduino Mini Pro (atmega328p) I used the latest install of AVRDude 1.0:
avrdude -C "G:\Devices\CT6A RC kit\arduino-1.0\hardware\tools\avr\etc\avrdude.conf" -v -v -v -v -p atmega328p -c stk500 -U flash:r:"c:/arduino.bin":r -P\.\COM4 -b57600
This should have produced an arduino.bin file but all I got was a repeat output of
avrdude: Recv: & [26]
and finally:
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_getsync(): timeout communicating with programmer
avrdude: stk500v2_command(): failed miserably to execute command 0x11
avrdude: stk500v2_disable(): failed to leave programming mode
Not sure what it means but there's no dump
Have heard it might be due to the 1.0 version AVRdude and should try .22. Haven't had a chance yet but will try it out asap if I can find that version to download from somewhere.
One thing that bothers me tho is that using the serial monitor I only get a line of jibberish instead of something readable. What's supposed to be shown?
Update:
Downloaded Arduino software v0022 and repeated avrdude instruction: works, resulted in an arduino.bin to be used as a backup in case I screw the sketch up! Thanks to all (but especially Rob of course!)
"in case I screw the sketch up!"
So you want a method to back up your sketches? You could always save the .hex file that is created by the IDE directly. It ends up in a directory.
If you select File:Preferences and turn on Verbose Output (in 1.0 anyway) you can scroll thru and find the directory & filename that is created.
tizzy:
Downloaded Arduino software v0022 and repeated avrdude instruction: works, resulted in an arduino.bin to be used as a backup in case I screw the sketch up!
Wouldn't it be better to save the sketch source?
thanks for your suggestion
Sorry for the 2012 bump but i've a problem with my arduino mega 2560, i'm doing the following command:
avrdude.exe -c arduino -p m2560 -P \\.\COM8 -U flash:r:dump.hex:i
And avr dude answer me after sending the command:
avrdude.exe: stk500_getsync(): not in sync: resp=0x00
But my arduino seem to get the signal because the L/RX leds blink before i got the getsync() message.
Any idea on what's wrong with my command, i'm using avrdude v5.10.
If you set verbose output in the IDE (file-> config) you can see what avrDude.exe expects for commands when uploading.
oh okay, i fixed the problem it was a conflict on my avrdude.conf
i was using avrdude of the arduino package but he was using the config file of my other avrdude installation of WinAVR.