From b2631eb7796a070ff7c7211137516e2f98b72d62 Mon Sep 17 00:00:00 2001 From: jakegoodwin Date: Sat, 18 Feb 2023 22:36:46 -0800 Subject: [PATCH] Updated makefile with newer version. Allows external crystal fuses and using directories --- Makefile | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 2dbe2f8..2676f1b 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -173,7 +178,7 @@ flash_109: flash #EFUSE=0x00 ## ## Mega 328p fuses -LFUSE = 0x62 +LFUSE = 0x62 HFUSE = 0xd9 EFUSE = 0xff @@ -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