GCC-AVR

From ElectroDragon Wiki

GCC-AVR

  1. gcc-avr: complier
  2. avr-libc:library used when compling
  3. gdb-avr :gdb reverse debug tool, against complie
  4. avrdude:flash tool

Compile

  • generate o file from c file:
  • -c Compile or assemble the source files, but do not link.
  • -Os Optimize for size, -O1, Optimize.-O2 Optimize even more.
  • -g Generate debugging information that can be used by avr-gdb.

>avr-gcc -g -mmcu=atmega8 -Wall -Os -c ledtest.c
>avr-gcc -g -Os -mmcu=atmega8 -c flash.c
>avr-gcc –mmcu=at90s2313 –c demo1.c

  • output .o .elf file for further use, for elf file, use when have more then one c file:
  • -o put output into output file

>avr-gcc -g -mmcu=atmega8 -o flash.elf flash.o
>avr-gcc -g -mmcu=atmega8 -o ledtest.out -Wl,-Map,ledtest.map ledtest.o

  • combined linked file into MCU read hex file

>avr-objcopy -j .text -j .data -O ihex flash.elf flash.hex
>avr-objcopy -R .eeprom -O ihex ledtest.out ledtest.hex
Above flash.elf and ledtest.out is the input file, and the second is the output file. >avr-size ledtest.out
Complete commands:

  • avr-gcc -Os -DF_CPU=8000000 -mmcu=attiny85 -c led_flash.c
  • avr-gcc -DF_CPU=8000000 -mmcu=attiny85 -o led_flash.elf led_flash.o
  • avr-objcopy -O ihex led_flash.elf led_flash.hex
  • rm led_flash.o
  • rm led_flash.elf

Note

  • DDRC = 0xFF makes all pins on PORTC as output pins
  • PORTC = 0xFF makes all pins on PORTC Logic High (5V)
  • PORTC = 0x00 makes all pins on PORTC Logic Low (0V)
  • _delay_ms(1000) provides 1000 milliseconds delay.
  • while(1) makes an infinite loop

Flash code

  • Use avrdude, command like: sudo avrdude -p m8 -c dragon_isp -P usb -e -U flash:w:flash.hex