Skip to content

Instantly share code, notes, and snippets.

@ndomx
Created January 30, 2021 22:16
Show Gist options
  • Save ndomx/c1a95128c35bde4e3b31f6679047029e to your computer and use it in GitHub Desktop.
Save ndomx/c1a95128c35bde4e3b31f6679047029e to your computer and use it in GitHub Desktop.
Makefile for simple ATmega C projects
MCU = atmega328p
DUDEMCU = m328p
PROG = usbasp
OPT = s
CPPFLAGS = -DF_CPU=16000000 -O$(OPT)
CFLAGS = -mmcu=$(MCU)
TARGET = main
CC = avr-gcc
DUDE = avrdude
OBJCOPY = avr-objcopy
.PHONY: build
build: $(TARGET).hex
$(TARGET).hex: $(TARGET).elf
$(OBJCOPY) -O ihex $< $@
$(TARGET).elf: $(TARGET).o
$(CC) $(CFLAGS) $< -o $@
$(TARGET).o: $(TARGET).c
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
.PHONY: upload
upload: $(TARGET).hex
$(DUDE) -c $(PROG) -p $(DUDEMCU) -v -U flash:w:$(TARGET).hex:i
.PHONY: clean
clean:
rm -f $(TARGET).o $(TARGET).elf $(TARGET).hex
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment