diff --git a/Makefile b/Makefile index 5cb18a9..68eda08 100644 --- a/Makefile +++ b/Makefile @@ -1,62 +1,53 @@ -TARGET = rc5switch -TARGET_MCU = attiny24 +CC := avr-gcc +LD := avr-ld +OBJCOPY := avr-objcopy +OBJDUMP := avr-objdump +SIZE := avr-size -# --------------------------------------------------------- +TARGET = rc5switch +SOURCE = $(wildcard *.c) +BUILD_DIR = build -BUILD = build +AVRDUDE_PROG := -c avr910 -b 115200 -P /dev/ispprog +#AVRDUDE_PROG := -c dragon_isp -P usb -CC = avr-gcc -NM = avr-nm -SIZE = avr-size -OBJCOPY = avr-objcopy -OBJDUMP = avr-objdump +MCU = attiny24 +AVRDUDE_MCU=t24 +# no self programming, 2.7V BOD, 8MHz internal RC Osz. +AVRDUDE_FUSES=lfuse:w:0xc2:m hfuse:w:0xdd:m efuse:w:0xff:m -override CFLAGS = -g -Wall -Os -mmcu=$(TARGET_MCU) -Wa,-gstabs,-adhlns=$(BUILD)/$(*D)/$(*F).lst -MMD -MP -MF $(BUILD)/$(*D)/$(*F).d -pipe -override LDFLAGS = -Wl,-Map=$(BUILD)/$(TARGET).map,--cref +# --------------------------------------------------------------------------- -# --------------------------------------------------------- +CFLAGS = -pipe -g -Os -mmcu=$(MCU) -Wall -fdata-sections -ffunction-sections +CFLAGS += -Wa,-adhlns=$(BUILD_DIR)/$(*D)/$(*F).lst -MMD -MP -MF $(BUILD_DIR)/$(*D)/$(*F).d +LDFLAGS = -Wl,-Map,$(@:.elf=.map),--cref,--relax,--gc-sections -SRC := $(wildcard *.c) +# --------------------------------------------------------------------------- -all: $(addprefix $(BUILD)/$(TARGET), .elf .lss .sym .bin .hex _eeprom.bin _eeprom.hex) -# @$(SIZE) -x -C --mcu=$(TARGET_MCU) $< +$(TARGET): $(BUILD_DIR)/$(TARGET).elf + @$(SIZE) -B -x --mcu=$(MCU) $< -%.lss: %.elf - @$(OBJDUMP) -h -S -C $< > $@ - -%.sym: %.elf - @$(NM) -n $< > $@ - -%.bin: %.elf - @$(OBJCOPY) -j .text -j .data -O binary $< $@ - -%.hex: %.elf - @$(OBJCOPY) -j .text -j .data -O ihex $< $@ - -%_eeprom.bin: %.elf - @$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O binary $< $@ 2> /dev/null - -%_eeprom.hex: %.elf - @$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@ 2> /dev/null - -$(BUILD)/$(TARGET).elf: $(patsubst %,$(BUILD)/%,$(SRC:.c=.o)) +$(BUILD_DIR)/$(TARGET).elf: $(patsubst %,$(BUILD_DIR)/%,$(SOURCE:.c=.o)) @echo " Linking file: $@" - @$(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS) > /dev/null - @$(SIZE) -x -B $^ $@ + @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ + @$(OBJDUMP) -h -S $@ > $(@:.elf=.lss) + @$(OBJCOPY) -j .text -j .data -O ihex $@ $(@:.elf=.hex) + @$(OBJCOPY) -j .text -j .data -O binary $@ $(@:.elf=.bin) + @$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $@ $(@:.elf=_eeprom.hex) + @$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O binary $@ $(@:.elf=_eeprom.bin) -$(BUILD)/%.o: %.c $(MAKEFILE_LIST) +$(BUILD_DIR)/%.o: %.c $(MAKEFILE_LIST) @echo " Building file: $<" - @$(shell mkdir -p $(BUILD)/$(*D)) - @$(CC) -c $(CFLAGS) $< -o $@ + @$(shell test -d $(BUILD_DIR)/$(*D) || mkdir -p $(BUILD_DIR)/$(*D)) + @$(CC) $(CFLAGS) -o $@ -c $< + +include $(shell find $(BUILD_DIR) -name \*.d 2> /dev/null) clean: - rm -rf $(BUILD) + rm -rf $(BUILD_DIR) -install: $(BUILD)/$(TARGET).hex $(BUILD)/$(TARGET)_eeprom.hex - avrdude -c dragon_isp -P usb -p t24 -U flash:w:$(BUILD)/$(TARGET).hex -U eeprom:w:$(BUILD)/$(TARGET)_eeprom.hex +install: $(BUILD_DIR)/$(TARGET).elf + avrdude $(AVRDUDE_PROG) -p $(AVRDUDE_MCU) -U flash:w:$(<:.elf=.hex) -U eeprom:w:$(<:.elf=_eeprom.hex) -# no self programming, 2.7V BOD, 8MHz internal RC Osz. fuses: - avrdude -c dragon_isp -P usb -p t24 -U lfuse:w:0xc2:m -U hfuse:w:0xdd:m -U efuse:w:0xff:m - --include $(shell find $(BUILD) -name *.d 2> /dev/null) + avrdude $(AVRDUDE_PROG) -p $(AVRDUDE_MCU) $(patsubst %,-U %, $(AVRDUDE_FUSES)) diff --git a/main.c b/main.c index a2829dc..305e048 100644 --- a/main.c +++ b/main.c @@ -41,7 +41,6 @@ #define RC5_CMD_MASK 0x37FF #define RC5_COMPLETE 0x8000 -#define PROGMODE_CHECK() (!(PINB & (1<