Go Down

Topic: Possible to copy compiled code from one Arduino to another and have it function? (Read 43280 times) previous topic - next topic

zenbike

I have an Uno R3 which has a working, compiled program which run an LED array based on sensor input.

Long term, I will need to re-code the program, since the source is lost, but I need that same code on multiple, identical Uno R3 devices, in the next couple of days.

Is there a way to copy it to a second (or multiple) identical Arduinos?


I know that it is not possible to decompile, I'm looking for a short term fix, because I have a deadline which will come before I can learn enough to re-code the program.


CrossRoads

Sure, once you get it to where it will compile,  you can upload it to as many Unos as you want.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

retrolefty


Sure, once you get it to where it will compile,  you can upload it to as many Unos as you want.


Well each upload initiates a new required compilation from the source sketch which the OP said will or is not available, so your suggestion is not something he can use. What is required is a command line script to use AVRDUDE directly to read back the binary contents of the flash memory on the prior uploaded chip and then a write to each new chip again using AVRDUDE directly. At least that is my take on the OP's question. But then again we both may not have a clear picture of what he is asking and in need of?

Lefty

CrossRoads

Re-coding was mentioned, hence fresh compile would be available.
I don't know if the original can be downloaded from the existing chip (possible via avrdude if fuses allow that), if so the avrdud commands can be used to load same into additional chips. Not my cup tea tho, need someone with avrdude experience.

I suspect its easier to do (for me anyway) with Atmel's AVR Studio and an AVR ISP MKii programmer.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

zenbike

That last is correct.  i apologize if I wasn't clear.  I do not have source to compile from.  I need to read back the compiled code, and write it to the additional Arduinos.

I'm pretty much completely new to all this, so instructions which are detailed and step by step would very much be appreciated.  Thanks for taking the time to answer me.

:)

I will re-code at some point, but this is a job that got dropped on me, and the deadline is too close to be sure that I can learn what I need in time.  Copying the compiled code will hopefully let us function, while I learn what I need to know to rewrite the code.

CrossRoads

Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

zenbike

Beyond the uno itself, a Windows PC (or Linux). I do have basic electronic tools, multimeter, etc..

But I don't know what I would need.  That is part of what I'm asking. If I need something I don't have, I'll get it.

CrossRoads

Here you go - takea look at this thread and see if rabitu can get you thru uploading hex files.
http://arduino.cc/forum/index.php/topic,123837.0/topicseen.html

This is one of the most useful tools you can have
http://www.mouser.com/ProductDetail/Atmel/ATAVRISP2/?qs=%2fha2pyFadujqFzV%252bExzQOlFEGuFbE5zkYm9OzGvRqkjeoy23MLFzjw%3d%3d

Board needs to powered to use it. MKii senses voltage in use and adjusts its signals accordingly as far as I know.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Erni

Nick Gammon has made a very clever solution, to both read and write the compiled hexfile

http://www.gammon.com.au/forum/?id=11638

You could also use avrdude commandline.
For example this line

Quote
avrdude -c arduino -P com20 -p atmega328p   -Uflash:r:d:\hexfiles\test.hex:i

Will read the flash and write the content to the file test.hex

Then you could write this file to another Uno using this line
Quote
avrdude -c arduino -P com20 -p atmega328p   -Uflash:w:d:\hexfiles\test.hex:i


Output:
Code: [Select]

avrdude -c arduino -P com20 -p atmega328p   -Uflash:w:d:\hexfiles\test.hex:i

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude: Device signature = 0x1e950f
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed

        To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "d:\hexfiles\test.hex"
avrdude: writing flash (32750 bytes):

Writing | ################################################## | 100% 4.39s

avrdude: 32750 bytes of flash written
avrdude: verifying flash memory against d:\hexfiles\test.hex:
avrdude: load data flash data from input file d:\hexfiles\test.hex:
avrdude: input file d:\hexfiles\test.hex contains 32750 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 5.21s

avrdude: verifying ...
avrdude: 32750 bytes of flash verified

avrdude: safemode: Fuses OK

avrdude done.  Thank you.



zenbike

What would I use to connect AVRdude to the board? An ISP Programmer?  Or can it be done with just the USB connection? 

Erni

In the above example I have just used an Arduino Uno, connect to my PC via USB. It shows up as COM20

avrdude -c arduino -P com20 -p atmega328p   -Uflash:r:d:\hexfiles\test.hex:i

A brief explanation
-c arduino   programmer is arduino
-P com20  The com port that arduino connects to
-p atmega328p  Partnumber, The mcu on an Arduino is Atmega328p
-Uflash  memorytype is Flash as opposed to EEPROM
r  read
d:\hexfiles\test.hex:i   the path and filename on your computer (the i indicate Intel hex)


So what you could do is:
Connect the Arduino with the sketch you want to copy to your PC via USB as normal, and observe the com port

Make a command window and type the avrdude command to copy the Flash

Connect The Arduino you wish to copy to, via the USB

Make a command window and type the avrdude command to write the file to Flash

This is on a Windows machine

retrolefty


What would I use to connect AVRdude to the board? An ISP Programmer?  Or can it be done with just the USB connection? 


Yes either a ISP programmer that your AVRDUDE configuration file knows how to use or another arduino board running the arduino as ISP sketch.

Lefty

Erni

Quote
Yes either a ISP programmer that your AVRDUDE configuration file knows how to use or another arduino board running the arduino as ISP sketch.


No need for ISP programmer or Arduino as ISP.
Just connect the Arduino via USB cable as you would do if you were going to upload a sketch

WizenedEE


Quote
Yes either a ISP programmer that your AVRDUDE configuration file knows how to use or another arduino board running the arduino as ISP sketch.


No need for ISP programmer or Arduino as ISP.
Just connect the Arduino via USB cable as you would do if you were going to upload a sketch



Yes, I've read back the hex file with the bootloader (just usb cable from arduino to C)

Tom Carpenter

When I tried to use avrdude to read a chip, I found that more was needed that posted previously. For example, this is what I had to use when I wanted to read back from a tiny84 using ArduinoISP:

Quote
<arduino dir>\hardware\tools\avr\bin\avrdude -p t84 -P\\.\COM6 -b19200 -c stk500v1 -C ../etc/avrdude.conf -U flash:r:E:\flash.bin:r
~Tom~

Go Up