Avr-gcc

From Attie's Wiki
(Difference between revisions)
Jump to: navigation, search
Line 128: Line 128:
  
 
<h2>icsp pins</h2>
 
<h2>icsp pins</h2>
connecting to bus pirate
+
[[File:http://itp.nyu.edu/physcomp/uploads/6pinAVRproghead.jpg]]
 +
 
 +
<h3>connecting to bus pirate</h3>
 
{|
 
{|
 
|-
 
|-
| align="right" | brown - 1 ||bgcolor="rgb(157,98,66)" width="10px" | || width="10px" |  ||bgcolor="rgb(166,166,166)" width="10px" | || 2 - gray
+
| align="right" | brown - 1 ||bgcolor="rgb(157,98,66)" width="10px" | || width="10px" |  ||bgcolor="rgb(255,255,255)" style="border:solid 1px #000;" width="10px" | || 2 - white
 
|-
 
|-
 
| align="right" | yellow - 3 ||bgcolor="rgb(255,250,47)" | || ||bgcolor="rgb(254,156,24)" | || 4 - orange
 
| align="right" | yellow - 3 ||bgcolor="rgb(255,250,47)" | || ||bgcolor="rgb(254,156,24)" | || 4 - orange
Line 137: Line 139:
 
| align="right" | red - 5 ||bgcolor="rgb(255,13,13)" | || ||bgcolor="rgb(0,0,0)" | || 6 - black
 
| align="right" | red - 5 ||bgcolor="rgb(255,13,13)" | || ||bgcolor="rgb(0,0,0)" | || 6 - black
 
|}
 
|}
 +
pin 2 can use the gray wire for 5v
  
 
<h2>other commands</h2>
 
<h2>other commands</h2>

Revision as of 10:35, 25 March 2010

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

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

Contents

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]

makefile

simple

Just produces the .elf and .hex file. Also optimizes for space (HUGE difference)

all:
        avr-gcc avr.c -mmcu=atmega168 -o example.elf -Wall -Os
        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

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

sample source

blink

/* 8 Mhz cpu */
#define F_CPU 8000000UL
 
/* led pin */
#define LED 0b00100000
 
#include <util/delay.h>
#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);
  }
}

S.O.S.

/* 8 Mhz cpu */
#define F_CPU 8000000UL
 
/* led pin */
#define LED 0b00100000
 
#include <util/delay.h>
#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);
 
  }
}

icsp pins

File:Http://itp.nyu.edu/physcomp/uploads/6pinAVRproghead.jpg

connecting to bus pirate

brown - 1 2 - white
yellow - 3 4 - orange
red - 5 6 - black

pin 2 can use the gray wire for 5v

other commands

avr-size example.elf
avr-gcc --help=optimizers

resources

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

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox