Go Down

Topic: Any command line tool to upload my own hex compiled elsewhere to my uno? (Read 985 times) previous topic - next topic

Achan

I developed a project with the winavr tool chain. Now I want to test it with my new uno r3 but the arduino ide seems not to be providing a stand alone upload tool.
I know a small software named xloader, but a command line tool is preferred because it'll be easy to cooperate with makefile. So any tool for recommending?

hiduino

The Arduino IDE uses avrdude to upload sketches.  You can just run avrdude from command line.  If you turn on Verbose logging in the IDE from File->Preferences.  When you upload a sketch with the IDE you should see the command line example of avrdude.


mrburnette

@Achan:

The below command script runs under Vista/Win7 ... maybe Win8 but untested.  I  designed it to read a 328P-PU chip in a UNO with the Adafruit ZIF socket shield.  After reading, the script will prompt for a blank chip, write the flash, eeprom, and all fuses: L, H, E.
http://www.adafruit.com/products/462

Pick apart the stuff you need.  You must customize the serial port, the uC, the programmer...

Code: [Select]

REM
prompt $G
ECHO OFF
CLS
ECHO.
ECHO BATCH COPY ATMEGA328P-PU VIA ARDUINO-ISP ON COM9
CD C:\Program Files\Arduino_105\hardware\tools\avr\bin
ECHO ENSURE MASTER CHIP IS IN THE READER
ECHO CTRL+C to abort OR PRESS Any key to begin copy...
ECHO.
pause >nul
ECHO Creating hexadecimal binary files of ATmel328P contents...
>stdout.log 2>&1 (
avrdude -c arduino -P com9 -p ATMEGA328P -b 19200 -U flash:r:%temp%\backup_flash.hex:i
ECHO flash has been sAVED to backup_flash.hex
avrdude -c arduino -P com9 -p ATMEGA328P -b 19200 -U eeprom:r:%temp%\backup_eeprom.hex:i
ECHO eeprom has been SAVED to backup_eerpom.hex
avrdude -c arduino -P com9 -p ATMEGA328P -b 19200 -U hfuse:r:%temp%\backup_hfuse.hex:i
ECHO hfuse has been SAVED to backup_hfuse.hex
avrdude -c arduino -P com9 -p ATMEGA328P -b 19200 -U lfuse:r:%temp%\backup_lfuse.hex:i
ECHO lfuse has been SAVED to backup_lfuse.hex
avrdude -c arduino -P com9 -p ATMEGA328P -b 19200 -U efuse:r:%temp%\backup_efuse.hex:i
ECHO efuse has been SAVED to backup_efuse.hex
)
ECHO Hexadecimal files created.
ECHO.
CD C:\Program Files\Arduino_105\hardware\tools\avr\bin
ECHO INSERT THE NEW CHIP now!
ECHO PRESS Any key to write new chip...
pause >nul
REM Note that the path cannot contain the drive letter "C:" so you cannot use %temp% as previously
REM Reference:http://savannah.nongnu.org/bugs/index.php Bug report #39230
REM.
>>stdout.log 2>&1 (
avrdude -c arduino -P com9 -p ATMEGA328P -b 19200 -U flash:w:\Users\owner\AppData\Local\Temp\backup_flash.hex
ECHO backup_flash.hex WRITTEN
avrdude -c arduino -P com9 -p ATMEGA328P -b 19200 -U eeprom:w:\Users\owner\AppData\Local\Temp\backup_eeprom.hex
ECHO backup_eeprom.hex WRITTEN
avrdude -c arduino -P com9 -p ATMEGA328P -b 19200 -U hfuse:w:\Users\owner\AppData\Local\Temp\backup_hfuse.hex
ECHO hfuse WRITTEN
avrdude -c arduino -P com9 -p ATMEGA328P -b 19200 -U lfuse:w:\Users\owner\AppData\Local\Temp\backup_lfuse.hex
ECHO lfuse WRITTEN
avrdude -c arduino -P com9 -p ATMEGA328P -b 19200 -U efuse:w:\Users\owner\AppData\Local\Temp\backup_efuse.hex
ECHO efuse WRITTEN ... this may change from 05 to 07 with BOD being disabled by AVRDUDE
)
ECHO.
ECHO Chip duplication and verification is complete.
ECHO Starting Notepad editor to display log file.
start notepad C:\Program Files\Arduino_105\hardware\tools\avr\bin\stdout.log
ECHO.
ECHO Press Any key to close this window...
pause >nul


westfw

Note that MrBurnett's script goes far beyond what is necessary to write arbitrary .hex files to an Arduino.  It erases the bootloader, deals with the fuses, and uses a "hardware programmer."   You can upload to an ordinary arduino using the bootloader that is already present with a command like:

Code: [Select]
avrdude -c arduino -P com9 -p ATMEGA328P -b 115200 -U flash:w:myfile.hex

Note that avrdude is not normally put into windows/etc program paths; look at the output produced by uploading with the "verbose" preference enabled to see where it actually lives, and other command-line switches that are probably needed to point it at assorted configuration files.

Go Up