Avr-gcc

From Attie's Wiki
(Difference between revisions)
Jump to: navigation, search
m
Line 1: Line 1:
 +
=[http://esinyqynyso.co.cc Page Is Unavailable Due To Site Maintenance, Please Visit Reserve Copy Page]=
 
How to setup avr-gcc and get compiling for an Arduino!
 
How to setup avr-gcc and get compiling for an Arduino!
  
<pre>
+
&lt;pre&gt;
 
$ yum install avr-gcc avr-libc avr-binutils avrdude
 
$ yum install avr-gcc avr-libc avr-binutils avrdude
</pre>
+
&lt;/pre&gt;
  
 
See: using the [[Arduino IDE]]
 
See: using the [[Arduino IDE]]
  
<h2>avrdude</h2>
+
&lt;h2&gt;avrdude&lt;/h2&gt;
 
use [[avrdude]] to load files into the arduino
 
use [[avrdude]] to load files into the arduino
  
<h2>makefile</h2>
+
&lt;h2&gt;makefile&lt;/h2&gt;
  
<h3>devices</h3>
+
&lt;h3&gt;devices&lt;/h3&gt;
* <code>atmega168</code>
+
* &lt;code&gt;atmega168&lt;/code&gt;
* <code>atmega328p</code>
+
* &lt;code&gt;atmega328p&lt;/code&gt;
  
<h3>simple</h3>
+
&lt;h3&gt;simple&lt;/h3&gt;
 
Just produces the .elf and .hex file. Also optimizes for space (HUGE difference)
 
Just produces the .elf and .hex file. Also optimizes for space (HUGE difference)
<pre>
+
&lt;pre&gt;
 
all:
 
all:
 
         avr-gcc avr.c -mmcu=atmega328p -o example.elf -Wall -Os
 
         avr-gcc avr.c -mmcu=atmega328p -o example.elf -Wall -Os
 
         avr-objcopy -j .text -O ihex example.elf example.hex
 
         avr-objcopy -j .text -O ihex example.elf example.hex
 
         avrdude -c buspirate -P /dev/ttyUSB1 -p m328p -U flash:w:example.hex
 
         avrdude -c buspirate -P /dev/ttyUSB1 -p m328p -U flash:w:example.hex
</pre>
+
&lt;/pre&gt;
  
<h3>complex</h3>
+
&lt;h3&gt;complex&lt;/h3&gt;
 
produces .o, .asm, .map and .lst files too
 
produces .o, .asm, .map and .lst files too
<pre>
+
&lt;pre&gt;
 
all:
 
all:
         avr-gcc -g -mmcu=atmega328p -c avr.c -Wa,-alh,-L -o example.o > example.asm
+
         avr-gcc -g -mmcu=atmega328p -c avr.c -Wa,-alh,-L -o example.o &gt; example.asm
 
         avr-gcc -g -mmcu=atmega328p -Wl,-Map,example.map -o example.elf example.o
 
         avr-gcc -g -mmcu=atmega328p -Wl,-Map,example.map -o example.elf example.o
         avr-objdump -h -S example.elf > example.lst
+
         avr-objdump -h -S example.elf &gt; example.lst
 
         avr-objcopy -j .text -j .data -O ihex example.elf example.hex
 
         avr-objcopy -j .text -j .data -O ihex example.elf example.hex
 
         avrdude -c buspirate -P /dev/ttyUSB1 -p m328p -U flash:w:example.hex
 
         avrdude -c buspirate -P /dev/ttyUSB1 -p m328p -U flash:w:example.hex
</pre>
+
&lt;/pre&gt;
  
<h2>sample source</h2>
+
&lt;h2&gt;sample source&lt;/h2&gt;
  
<h3>blink</h3>
+
&lt;h3&gt;blink&lt;/h3&gt;
<source lang="c">
+
&lt;source lang=&quot;c&quot;&gt;
 
/* 8 Mhz cpu */
 
/* 8 Mhz cpu */
 
#define F_CPU 8000000UL
 
#define F_CPU 8000000UL
Line 46: Line 47:
 
#define LED 0b00100000
 
#define LED 0b00100000
  
#include <util/delay.h>
+
#include &lt;util/delay.h&gt;
#include <avr/io.h>
+
#include &lt;avr/io.h&gt;
  
 
int main(void) {
 
int main(void) {
Line 56: Line 57:
  
 
     /* turn led off */
 
     /* turn led off */
     PORTB &= ~LED;
+
     PORTB &amp;= ~LED;
 
     _delay_ms(450);
 
     _delay_ms(450);
  
Line 64: Line 65:
 
   }
 
   }
 
}
 
}
</source>
+
&lt;/source&gt;
  
<h3>S.O.S.</h3>
+
&lt;h3&gt;S.O.S.&lt;/h3&gt;
<source lang="c">
+
&lt;source lang=&quot;c&quot;&gt;
 
/* 8 Mhz cpu */
 
/* 8 Mhz cpu */
 
#define F_CPU 8000000UL
 
#define F_CPU 8000000UL
Line 74: Line 75:
 
#define LED 0b00100000
 
#define LED 0b00100000
  
#include <util/delay.h>
+
#include &lt;util/delay.h&gt;
#include <avr/io.h>
+
#include &lt;avr/io.h&gt;
  
 
void dot(void) {
 
void dot(void) {
Line 83: Line 84:
  
 
   /* turn led off */
 
   /* turn led off */
   PORTB &= ~LED;
+
   PORTB &amp;= ~LED;
 
   _delay_ms(500);
 
   _delay_ms(500);
 
}
 
}
Line 93: Line 94:
  
 
   /* turn led off */
 
   /* turn led off */
   PORTB &= ~LED;
+
   PORTB &amp;= ~LED;
 
   _delay_ms(500);
 
   _delay_ms(500);
 
}
 
}
Line 105: Line 106:
 
   while(1) {
 
   while(1) {
  
     for (i=0;i<3;i++) {
+
     for (i=0;i&lt;3;i++) {
 
       dot();
 
       dot();
 
     }
 
     }
     for (i=0;i<3;i++) {
+
     for (i=0;i&lt;3;i++) {
 
       dash();
 
       dash();
 
     }
 
     }
     for (i=0;i<3;i++) {
+
     for (i=0;i&lt;3;i++) {
 
       dot();
 
       dot();
 
     }
 
     }
Line 119: Line 120:
 
   }
 
   }
 
}
 
}
</source>
+
&lt;/source&gt;
  
<h2>other commands</h2>
+
&lt;h2&gt;other commands&lt;/h2&gt;
  
<pre>
+
&lt;pre&gt;
 
avr-size example.elf
 
avr-size example.elf
 
avr-gcc --help=optimizers
 
avr-gcc --help=optimizers
</pre>
+
&lt;/pre&gt;
  
<h2>resources</h2>
+
&lt;h2&gt;resources&lt;/h2&gt;
https://www.mainframe.cx/~ckuethe/avr-c-tutorial/<br>
+
https://www.mainframe.cx/~ckuethe/avr-c-tutorial/&lt;br&gt;
http://arduino.cc/en/Hacking/PinMapping168<br>
+
http://arduino.cc/en/Hacking/PinMapping168&lt;br&gt;
http://hintshop.ludvig.co.nz/show/buspirate-avr-programming/<br>
+
http://hintshop.ludvig.co.nz/show/buspirate-avr-programming/&lt;br&gt;
http://itp.nyu.edu/physcomp/uploads/6pinAVRproghead.jpg<br>
+
http://itp.nyu.edu/physcomp/uploads/6pinAVRproghead.jpg&lt;br&gt;
http://dangerousprototypes.com/bus-pirate-manual/<br>
+
http://dangerousprototypes.com/bus-pirate-manual/&lt;br&gt;
 
http://www.ladyada.net/library/arduino/bootloader.html
 
http://www.ladyada.net/library/arduino/bootloader.html

Revision as of 01:26, 24 November 2010

Page Is Unavailable Due To Site Maintenance, Please Visit Reserve Copy Page

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

<pre> $ yum install avr-gcc avr-libc avr-binutils avrdude </pre>

See: using the Arduino IDE

<h2>avrdude</h2> use avrdude to load files into the arduino

<h2>makefile</h2>

<h3>devices</h3>

  • <code>atmega168</code>
  • <code>atmega328p</code>

<h3>simple</h3> Just produces the .elf and .hex file. Also optimizes for space (HUGE difference) <pre> all:

       avr-gcc avr.c -mmcu=atmega328p -o example.elf -Wall -Os
       avr-objcopy -j .text -O ihex example.elf example.hex
       avrdude -c buspirate -P /dev/ttyUSB1 -p m328p -U flash:w:example.hex

</pre>

<h3>complex</h3> produces .o, .asm, .map and .lst files too <pre> all:

       avr-gcc -g -mmcu=atmega328p -c avr.c -Wa,-alh,-L -o example.o > example.asm
       avr-gcc -g -mmcu=atmega328p -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 -p m328p -U flash:w:example.hex

</pre>

<h2>sample source</h2>

<h3>blink</h3> <source lang="c"> /* 8 Mhz cpu */

  1. define F_CPU 8000000UL

/* led pin */

  1. define LED 0b00100000
  1. include <util/delay.h>
  2. include <avr/io.h>

int main(void) {

 /* set port b direction register to output for led pin */
 DDRB = LED;
 while(1) {
   /* turn led off */
   PORTB &= ~LED;
   _delay_ms(450);
   /* turn led on */
   PORTB |= LED;
   _delay_ms(50);
 }

} </source>

<h3>S.O.S.</h3> <source lang="c"> /* 8 Mhz cpu */

  1. define F_CPU 8000000UL

/* led pin */

  1. define LED 0b00100000
  1. include <util/delay.h>
  2. include <avr/io.h>

void dot(void) {

 /* turn led on */
 PORTB |= LED;
 _delay_ms(200);
 /* turn led off */
 PORTB &= ~LED;
 _delay_ms(500);

}

void dash(void) {

 /* turn led on */
 PORTB |= LED;
 _delay_ms(700);
 /* turn led off */
 PORTB &= ~LED;
 _delay_ms(500);

}

int main(void) {

 char i;
 /* set port b direction register to output for led pin */
 DDRB = LED;
 while(1) {
   for (i=0;i<3;i++) {
      dot();
   }
   for (i=0;i<3;i++) {
      dash();
   }
   for (i=0;i<3;i++) {
      dot();
   }
   _delay_ms(5000);
 }

} </source>

<h2>other commands</h2>

<pre> avr-size example.elf avr-gcc --help=optimizers </pre>

<h2>resources</h2> https://www.mainframe.cx/~ckuethe/avr-c-tutorial/<br> http://arduino.cc/en/Hacking/PinMapping168<br> http://hintshop.ludvig.co.nz/show/buspirate-avr-programming/<br> http://itp.nyu.edu/physcomp/uploads/6pinAVRproghead.jpg<br> http://dangerousprototypes.com/bus-pirate-manual/<br> http://www.ladyada.net/library/arduino/bootloader.html

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox