Updated makefile with newer version. Allows external crystal fuses and using directories

This commit is contained in:
Jake Goodwin 2023-02-18 22:36:46 -08:00
parent a7f2348ddc
commit b2631eb779
1 changed files with 22 additions and 9 deletions

View File

@ -8,7 +8,8 @@
#MCU = atmega2560
#MCU = attiny85
MCU = atmega328p
F_CPU = 1000000UL
#F_CPU = 1000000UL
F_CPU = 14745600UL
BAUD = 9600UL
## Also try BAUD = 19200 or 38400 if you're feeling lucky.
@ -19,6 +20,10 @@ BAUD = 9600UL
#LIBDIR = /usr/lib/gcc/avr/5.4.0/
LIBDIR = /lib/avr/
#OUTPUT DIRs
#This is to tell the makefile where we want to put the object and hex files etc
DEBUG_DIR = ./out
##########------------------------------------------------------##########
########## Programmer Defaults ##########
########## Set up once, then forget about it ##########
@ -52,12 +57,12 @@ AVRDUDE = avrdude
## The name of your project (without the .c)
# TARGET = blinkLED
## Or name it automatically after the enclosing directory
TARGET = $(lastword $(subst /, ,$(CURDIR)))
TARGET = $(DEBUG_DIR)/$(lastword $(subst /, ,$(CURDIR)))
# Object files: will find all .c/.h files in current directory
# and in LIBDIR. If you have any other (sub-)directories with code,
# you can add them in to SOURCES below in the wildcard statement.
SOURCES=$(wildcard *.c $(LIBDIR)/*.c)
SOURCES=$(wildcard src/*.c modules/*/*.c $(LIBDIR)/*.c)
OBJECTS=$(SOURCES:.c=.o)
HEADERS=$(SOURCES:.c=.h)
@ -80,19 +85,19 @@ TARGET_ARCH = -mmcu=$(MCU)
## Explicit pattern rules:
## To make .o files from .c files
%.o: %.c $(HEADERS) Makefile
$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<;
$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $(DEBUG_DIR)/$@ $<;
$(TARGET).elf: $(OBJECTS)
$(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $@
$(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LDLIBS) -o $(DEBUG_DIR)/$@
%.hex: %.elf
$(OBJCOPY) -j .text -j .data -O ihex $< $@
$(OBJCOPY) -j .text -j .data -O ihex $(DEBUG_DIR)/$< $(DEBUG_DIR)/$@
%.eeprom: %.elf
$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@
$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $(DEBUG_DIR)$< $(DEBUG_DIR)/$@
%.lst: %.elf
$(OBJDUMP) -S $< > $@
$(OBJDUMP) -S $(DEBUG_DIR)$< > $(DEBUG_DIR)/$@
## These targets don't have files named after them
.PHONY: all disassemble disasm eeprom size clean squeaky_clean flash fuses
@ -191,6 +196,14 @@ show_fuses:
set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m
set_default_fuses: fuses
## For external clock low-power crystal.
# The low order fuse is set for a low-power crystal. 14.7456Mhz
# cksel[3:1] 8.0-16.0 = 111 //Sets it for the range of 8Mhz - 16Mhz
# cksel[0] 1 SUT[1:0] 11 //gives 16K ck startup time aprox 65ms
set_crystal_fuses: LFUSE = 0xFF
set_crystal_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m
set_crystal_fuses: fuses
## Set the fuse byte for full-speed mode
## Note: can also be set in firmware for modern chips
set_fast_fuse: LFUSE = 0xE2