Avr-gcc

From Attie's Wiki
(Difference between revisions)
Jump to: navigation, search
Line 18: Line 18:
 
To upload file: <code>-U memtype:op:filename[:format]</code>
 
To upload file: <code>-U memtype:op:filename[:format]</code>
  
Simple makefile:
+
Simple makefile: (just produces the .elf and .hex file)
 
<pre>
 
<pre>
 
all:
 
all:
         avr-gcc avr.c -mmcu=atmega168 -o avr.elf -Wall
+
         avr-gcc avr.c -mmcu=atmega168 -o example.elf -Wall
         avr-objcopy -j .text -O ihex avr.elf avr.hex
+
         avr-objcopy -j .text -O ihex example.elf example.hex
         avrdude -c buspirate -P /dev/ttyUSB1 -x speed=3 -p m168 -U flash:w:avr.hex
+
         avrdude -c buspirate -P /dev/ttyUSB1 -x speed=3 -p m168 -U flash:w:example.hex
 
</pre>
 
</pre>
 +
 +
Complex makefile: (produces .o, .asm, .map and .lst files too)
 +
<pre>
 +
all:
 +
        avr-gcc -g -mmcu=atmega168 -c avr.c -Wa,-alh,-L -o avr.o > avr.asm
 +
        avr-gcc -g -mmcu=atmega168 -Wl,-Map,example.map -o example.elf example.o
 +
        avr-objdump -h -S example.elf > example.lst
 +
        avr-objcopy -j .text -j .data -O ihex example.elf example.hex
 +
        avrdude -c buspirate -P /dev/ttyUSB1 -x speed=3 -p m168 -U flash:w:example.hex
 +
</pre>
 +
 +
<code>
 +
avr-size example.elf
 +
</code>
  
 
Resources:<br>
 
Resources:<br>

Revision as of 00:51, 25 March 2010

How to setup avr-gcc and get compiling for an Arduino!

$ yum install avr-gcc avr-libc avr-binutils avrdude

For ATMega168:

$ avrdude -c buspirate -P /dev/ttyUSB1 -x speed=3 -p m168

For ATMega328p:

$ avrdude -c buspirate -P /dev/ttyUSB1 -x speed=3 -p m328p

Terminal mode: -t. Use command part to see detailed part information.
To upload file: -U memtype:op:filename[:format]

Simple makefile: (just produces the .elf and .hex file)

all:
        avr-gcc avr.c -mmcu=atmega168 -o example.elf -Wall
        avr-objcopy -j .text -O ihex example.elf example.hex
        avrdude -c buspirate -P /dev/ttyUSB1 -x speed=3 -p m168 -U flash:w:example.hex

Complex makefile: (produces .o, .asm, .map and .lst files too)

all:
        avr-gcc -g -mmcu=atmega168 -c avr.c -Wa,-alh,-L -o avr.o > avr.asm
        avr-gcc -g -mmcu=atmega168 -Wl,-Map,example.map -o example.elf example.o
        avr-objdump -h -S example.elf > example.lst
        avr-objcopy -j .text -j .data -O ihex example.elf example.hex
        avrdude -c buspirate -P /dev/ttyUSB1 -x speed=3 -p m168 -U flash:w:example.hex

avr-size example.elf

Resources:
http://arduino.cc/en/Hacking/PinMapping168
https://www.mainframe.cx/~ckuethe/avr-c-tutorial/
http://hintshop.ludvig.co.nz/show/buspirate-avr-programming/
http://itp.nyu.edu/physcomp/uploads/6pinAVRproghead.jpg
http://dangerousprototypes.com/bus-pirate-manual/

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox