Skip to content

Instantly share code, notes, and snippets.

@chuangzhu
Created June 19, 2019 15:56
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save chuangzhu/9a25cdfbf59a5f9abe13e41b81ef7771 to your computer and use it in GitHub Desktop.
Programming AVR on Linux

Programming AVR on Linux

Install avr-gcc, avr-libc, avr-binutils, avrdude:

$ sudo pacman -S avr-gcc avr-libc avr-binutils avrdude

Build the hex file:

$ make hex

Flash to the chip:

$ sudo make flash
MCU = atmega32
F_CPU = 16000000
PROGRAMMER = -c usbasp
AVRDUDE = avrdude $(PROGRAMMER) -p $(MCU)
CC = avr-gcc -Wall -Os -DF_CPU=$(F_CPU) -mmcu=$(MCU)
.PHONY: hex flash clean
hex: blink.hex
%.hex: %.elf
rm -f $@
avr-objcopy -j .text -j .data -O ihex $< $@
%.elf: %.o
$(CC) $< -o $@
%.o: %.c
$(CC) -c $< -o $@
flash: hex
$(AVRDUDE) -U flash:w:blink.hex:i
clean:
rm -f blink.hex blink.elf blink.o
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment