11/01/2015

Compile code with AVR LIBC for atmega328p manually

1. HOW TO

2. Command
listcomports.exe
  Tool from arduino.
  It helps you to list available COM ports in system.
  No need to open device manager to check.

avr-gcc.exe
  The entrypoint of AVR GCC.
  avr-gcc -g -Os -mmcu=atmega328p -c file.c  --> Produce file.o
  avr-gcc -g -mmcu=atmega328p -o file.elf file.o --> Product file.elf

avr-ld.exe
  Linker.
  Indirectly invoked by avr-gcc.exe.
  No recommand to use it direcly. It will crash.

avr-objcopy.exe
  Dumps sections in ELF file and combines them together.
  avr-objcopy -j .text -j .data -O ihex file.elf file.hex --> Product file.hex which contains text & data sections.

avrdude.exe
  Upload file to arduino.
  avrdude -p atmega328p -c arduino -b 115200 -P com4 -U flash:w:file.hex