From bf4636d9946189414b4cab1bec1059f7f621e3e8 Mon Sep 17 00:00:00 2001 From: jakeg00dwin Date: Sat, 9 Dec 2023 09:14:48 -0800 Subject: [PATCH] added the makefile for building the program --- makefile | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 makefile diff --git a/makefile b/makefile new file mode 100644 index 0000000..a60caca --- /dev/null +++ b/makefile @@ -0,0 +1,60 @@ +# Author: Jake Goodwin +# DATE: 2023-12-07 +# Descripion: A simple makefile for building and flashing hex files + +# Makefile for ATtiny13A + +# Compiler +CC = avr-gcc + +#Default cpu frequency is 9.8Mhz, 4.8 gives us less power consumption +#F_CPU = 4800000UL +F_CPU = 9800000UL +MCU = attiny13a + +# Flags +CFLAGS = -g -Os -mmcu=$(MCU) -DF_CPU=$(F_CPU) +LDFLAGS = -Wl,-Map,$(TARGET).map + +# Source files +SRC = main.c + +# Object files +OBJ = $(SRC:.c=.o) + +# Target HEX file +TARGET = main + +# Flashing options +AVRDUDE = avrdude +AVRDUDE_PROGRAMMER = -c usbasp +BUADRATE = -B 125kHz +AVRDUDE_PORT = -P /dev/ttyUSB0 +AVRDUDE_MCU = -p $(MCU) + + +# Compile and generate HEX file +all: $(TARGET).hex + +$(TARGET).hex: $(TARGET).elf + avr-objcopy -j .text -j .data -O ihex $< $@ + +$(TARGET).elf: $(OBJ) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ + +%.o: %.c + $(CC) $(CFLAGS) -c $< -o $@ +size: $(TARGET).o + avr-size --mcu=$(MCU) -t ./$(TARGET).o +flash_defualt_fuses: + $(AVRDUDE) $(AVRDUDE_PROGRAMMER) $(AVRDUDE_PORT) $(AVRDUDE_MCU) $(BUADRATE) -U lfuse:w:0x6A:m -U hfuse:w:0xFF:m -U lock:w:0xFF:m +flash_slow_fuse: + $(AVRDUDE) $(AVRDUDE_PROGRAMMER) $(AVRDUDE_PORT) $(AVRDUDE_MCU) $(BUADRATE) -U lfuse:w:0x69:m -U hfuse:w:0xFF:m -U lock:w:0xFF:m +flash: $(TARGET).hex + $(AVRDUDE) $(AVRDUDE_PROGRAMMER) $(AVRDUDE_PORT) $(AVRDUDE_MCU) $(BUADRATE) -U flash:w:$(TARGET).hex:i + +clean: + rm -f $(OBJ) $(TARGET).elf $(TARGET).hex $(TARGET).map + +.PHONY: all clean +