clock_generator/firmware/c/Makefile
finga af3790be0d Rename folder of firmware written in c
To establish a better naming convention for firmwares written in other
languages.
2021-10-25 15:26:04 +02:00

55 lines
1,009 B
Makefile

.SUFFIXES:
MCU := atmega328p
PROGRAMMER := usbasp
SPEED := 8000000UL
TARGET := main.hex
EEP := main.eep
BIN := main.elf
OBJ := main.o
LOW_FUSE := 0xE2
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 -Wpedantic
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 lfuse:w:$(LOW_FUSE):m -U hfuse:w:$(HIGH_FUSE):m
clean:
$(RM) $(TARGET) $(EEP) $(BIN) $(OBJ)
check:
cppcheck main.c
size: $(BIN)
$(SIZE) --format=avr --mcu=$(MCU) $<