clock_generator/firmware/src/Makefile

55 lines
956 B
Makefile
Raw Normal View History

.SUFFIXES:
MCU := atmega328p
PROGRAMMER := usbasp
SPEED := 8000000UL
TARGET := main.hex
EEP := main.eep
BIN := main.elf
OBJ := main.o
HIGH_FUSE := 0xD6
SHELL := sh
CC := avr-gcc
OBJCOPY := avr-objcopy
SIZE := avr-size
AVRDUDE := avrdude
CFLAGS := -mmcu=$(MCU) -D F_CPU=$(SPEED) -Os -Wall -Werror -Wextra
all: $(TARGET) $(EEP)
$(TARGET): $(BIN)
${OBJCOPY} -O ihex -j .text -j .data $< $@
$(EEP): $(BIN)
${OBJCOPY} --change-section-lma .eeprom=0 -O ihex -j .eeprom $< $@
$(BIN): $(OBJ)
$(CC) $(CFLAGS) $< -o $@
%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@
.PHONY: flash eeprom fuses clean check size
flash: $(TARGET) size
$(AVRDUDE) -p $(MCU) -c $(PROGRAMMER) -U flash:w:$<:a
eeprom: $(EEP) size
$(AVRDUDE) -p $(MCU) -c $(PROGRAMMER) -U eeprom:w:$<:a
fuses:
$(AVRDUDE) -p $(MCU) -c $(PROGRAMMER) -U hfuse:w:$(HIGH_FUSE):m
clean:
$(RM) $(TARGET) $(EEP) $(BIN) $(OBJ)
check:
cppcheck main.c
size: $(BIN)
$(SIZE) --format=avr --mcu=$(MCU) $<