# Makefile to build and flash avrrfm # # Simplified version from: https://github.com/hexagon5un/AVR-Programming MCU = atmega328p F_CPU = 8000000 BAUD = 9600 PROGRAMMER_TYPE = avrispmkII PROGRAMMER_ARGS = MAIN = avrrfm.c SRC = rfm69.c spi.c usart.c CC = avr-gcc OBJCOPY = avr-objcopy OBJDUMP = avr-objdump AVRSIZE = avr-size AVRDUDE = avrdude CFLAGS = -mmcu=$(MCU) -DF_CPU=$(F_CPU)UL -DBAUD=$(BAUD) CFLAGS += -O2 -I. CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums CFLAGS += -Wall -Wstrict-prototypes CFLAGS += -g -ggdb CFLAGS += -ffunction-sections -fdata-sections -Wl,--gc-sections -mrelax CFLAGS += -std=gnu99 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105523 # CFLAGS += --param=min-pagesize=0 TARGET = $(strip $(basename $(MAIN))) SRC += $(TARGET).c OBJ = $(SRC:.c=.o) OBJ = $(SRC:.S=.o) $(TARGET).elf: pins.h rfm69.h spi.h usart.h utils.h Makefile all: $(TARGET).hex %.hex: %.elf $(OBJCOPY) -R .eeprom -O ihex $< $@ %.elf: $(SRC) $(CC) $(CFLAGS) $(SRC) --output $@ disasm: $(TARGET).lst eeprom: $(TARGET).eeprom %.lst: %.elf $(OBJDUMP) -S $< > $@ size: $(TARGET).elf $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf clean: rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \ $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \ $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \ $(TARGET).eeprom flash: $(TARGET).hex $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$<