Difference between revisions of "Command line Arduino"

From Wikiid
Jump to: navigation, search
(Upload:)
(Upload:)
Line 118: Line 118:
 
   -b 19200                    == Upload baud rate
 
   -b 19200                    == Upload baud rate
 
   -U flash:w:applet/myfile.hex == Memory operation specification.
 
   -U flash:w:applet/myfile.hex == Memory operation specification.
 +
 +
You may not have the perl 'Device::Serial' library installed - the file you need is:
 +
 +
  perl-Device-SerialPort-{xxxxx}.rpm
 +
 +
Where: {xxxxxx} is the version number, OS and other junk.
  
 
{{Arduino}}
 
{{Arduino}}

Revision as of 13:06, 10 January 2009

Here's how you build programs for Arduino from the Linux command line.

Source code considerations:

Program sources must include:

 #include "WProgram.h"

...and must call 'init()' before anything else.

Compile C & C++ file to make '.o':

 avr-gcc or avr-g++

Use all of the usual options - plus:

 -mmcu=atmega128            == Set the instruction set.
                               (use atmega8 on old arduino's)
 -DF_CPU=16000000           == Define F_CPU to be the clock rate.
                               This is 16000000 for everything except the LilyPad, set it to 8000000.
 -I ...                     == Location of WProgram.h, etc.
 -I ...                     == Location of interrupt.h, etc. (use /opt/cross/avr/include/... under OpenSuse)

Build a ".a" file from all of your library ".o" files:

 avr-ar rcs library.a *.o

Where:

   r     == replace
   c     == don't warn if has to be created
   s     == create an archive index
   *.o   == the results of compiling:
      pins_arduino.c     wiring.c
      wiring_analog.c    wiring_digital.c
      wiring_pulse.c     wiring_serial.c
      wiring_shift.c     WInterrupts.c
      HardwareSerial.cpp WMath.cpp

Link (to produce an Elf file):

 avr-gcc -mmcu=atmega128 \
         -I. \
         -gstabs \
         -DF_CPU=16000000 \
         -I ... \
         -Os \
         -Wall -Wstrict-prototypes \
         -std=gnu99 \
         -o blah.elf \
         blah.cpp \
         -L. \
         library.a \
         -lm

Where:

 -mmcu=atmega128            == Set the instruction set.
                               (use atmega8 on old arduino's)
 -I.                        == Look for header files here.
 -gstabs                    == Use STABS format for debugging.
 -DF_CPU=16000000           == Define F_CPU to be the clock rate.
                               This is 16000000 for everything except the LilyPad, set it to 8000000.
 -I ...                     == Location of WProgram.h, etc.
 -I ...                     == Location of interrupt.h, etc.
                               (use /opt/cross/avr/include/... under
                               OpenSuse)
 -Os                        == Optimize for minimum code size.
 -Wall                      == Turn on all standard warnings.
 -Wstrict-prototypes        == Demand proper function prototypes.
 -std=gnu99                 == Require C99 plus Gnu extensions.
 -o blah.elf                == Set the output file.
 blah.cpp                   == The source to compile.
 -L.                        == Look in the current directory for libraries.
 library.a                  == ...and other obj files.
 -lm                        == Grab the standard math library.

Elf to Hex:

 avr-objcopy -O ihex    \
             -R .eeprom \
             blah.elf   \
             blah.hex

Where:

 -O ihex     == Create output in ihex format.
 -R .eeprom  == Remove the .eeprom section from the output.
 blah.elf    == Input file in 'elf' format
 blah.hex    == Output file in 'ihex' format.

Upload:

First, create a file: resetArduino.pl containing

Device::SerialPort->new("/dev/ttyS0")->pulse_dtr_on(100);

...then issue a perl command to reset the Arduino by toggling the DTR bit on the USB connection - and IMMEDIATELY start the download using the 'avrdude' program (there is only a couple of seconds of time between hitting the reset and whatever program was already in the Arduino starting running - so you've gotta go fast):

perl -EDevice::SerialPort resetArduino.pl
avrdude -V \
        -F \
        -C $(INSTALL_DIR)/hardware/tools/avr/etc/avrdude.conf \
        -p $(MCU)  \
        -P $(AVRDUDE_PORT)  \
        -c $(AVRDUDE_PROGRAMMER) \
        -b $(UPLOAD_RATE) \
        -U flash:w:applet/$(TARGET).hex

Parameters:

 -V                           == Do not verify
 -F                           == Override signature check.
 -C avrdude.conf              == Set config file
 -p atmega128                 == Choose board processor type
                                 (use atmega8 on old arduino's)
 -P /dev/tty.USB0             == USB port. (/dev/ttyUSB0 in OpenSuSE)
 -c stk500v1                  == Choose programmer type
 -b 19200                     == Upload baud rate
 -U flash:w:applet/myfile.hex == Memory operation specification.

You may not have the perl 'Device::Serial' library installed - the file you need is:

 perl-Device-SerialPort-{xxxxx}.rpm

Where: {xxxxxx} is the version number, OS and other junk.


Wikiid Pages relating to Arduino (edit)
Arduino
Command line Arduino
Startup code for Arduino
Low level functions for Arduino
Putting data in flash on the Arduino
External resources for Arduino
Board schematics for Arduino
Misc notes: Circuit notes, Music notes, Stepper motors