1
#==== Main Options =============================================================
16
#==== Compile Options ==========================================================
20
CFLAGS += -DF_CPU=$(F_CPU)UL
23
#CFLAGS += -mshort-calls
24
CFLAGS += -funsigned-char
25
CFLAGS += -funsigned-bitfields
26
CFLAGS += -fpack-struct
27
CFLAGS += -fshort-enums
28
#CFLAGS += -fno-unit-at-a-time
30
CFLAGS += -Wstrict-prototypes
32
#CFLAGS += -Wunreachable-code
33
#CFLAGS += -Wsign-compare
35
#CFLAGS += -Wa,-adhlns=$(<:%.c=$(OBJDIR)/%.lst)
37
CFLAGS += -Wno-int-to-pointer-cast
38
#CFLAGS += -save-temps
44
#==== Programming Options (avrdude) ============================================
46
AVRDUDE_PROGRAMMER = stk500v1
47
AVRDUDE_PORT = /dev/ttyUSB0
50
#AVRDUDE_NO_VERIFY = -V
52
AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -b $(AVRDUDE_BAUD) -c $(AVRDUDE_PROGRAMMER) $(AVRDUDE_NO_VERIFY)
56
#==== Targets ==================================================================
68
OBJ = $(SRC:%.c=$(OBJDIR)/%.o)
70
AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
71
AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
73
MEMORYTYPES = flash eeprom fuse lfuse hfuse efuse boot calibration lock signature application apptable prodsig usersig
80
@echo 'Basic targets:'
81
@echo ' build Create all files.'
82
@echo ' clean Remove files created by make.'
83
@echo ' size Show the size of each section in the .elf file.'
86
@echo ' elf Create binary .elf file.'
87
@echo ' hex Create .hex file containing .text and .data sections.'
88
@echo ' eep Create .eep file with the EEPROM content.'
89
@echo ' lss Create .lss file with a listing of the program.'
92
@echo ' program Write flash and EEPROM.'
93
@echo ' flash Write only flash.'
94
@echo ' eeprom Write only EEPROM.'
95
@echo ' backup Backup MCU content to "$(BACKUPDIR)". Available memory types:'
96
@echo ' $(MEMORYTYPES)'
99
@echo ' readfuses Read fuses from MCU.'
100
@echo ' writefuses Write fuses to MCU using .fuse section.'
101
@echo ' printfuses Print fuses from .fuse section.'
104
build: elf hex eep lss size
113
program: flash eeprom
117
$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH)
120
eeprom: $(TARGET).eep
121
$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_EEPROM)
125
$(AVRDUDE) $(AVRDUDE_FLAGS) -U lfuse:r:-:h -U hfuse:r:-:h
129
# $(AVRDUDE) $(AVRDUDE_FLAGS) -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m
132
writefuses: FUSES = $(shell $(OBJDUMP) -s --section=.fuse $(TARGET).elf | tail -1 | awk '{print substr($$2,1,2),substr($$2,3,2),substr($$2,5,2)}')
133
writefuses: $(TARGET).elf
134
$(AVRDUDE) $(AVRDUDE_FLAGS) \
135
$(if $(word 1,$(FUSES)),-U lfuse:w:0x$(word 1,$(FUSES)):m) \
136
$(if $(word 2,$(FUSES)),-U hfuse:w:0x$(word 2,$(FUSES)):m) \
137
$(if $(word 3,$(FUSES)),-U efuse:w:0x$(word 3,$(FUSES)):m)
140
printfuses: FUSES = $(shell $(OBJDUMP) -s --section=.fuse $(TARGET).elf | tail -1 | awk '{printf "l:0x%s h:0x%s e:0x%s",substr($$2,1,2),substr($$2,3,2),substr($$2,5,2)}')
141
printfuses: $(TARGET).elf
146
$(OBJCOPY) -O ihex -j .text -j .data $< $@
150
-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 -O ihex $< $@
154
$(OBJDUMP) -h -S $< > $@
157
.SECONDARY: $(TARGET).elf
160
$(CC) $(CFLAGS) $^ --output $@ $(LDFLAGS)
164
$(shell mkdir -p $(OBJDIR) 2>/dev/null)
165
$(CC) -c $(CFLAGS) $< -o $@
169
$(AVRSIZE) -A $(TARGET).elf
170
$(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf
174
$(REMOVE) "$(TARGET).hex"
175
$(REMOVE) "$(TARGET).eep"
176
$(REMOVE) "$(TARGET).elf"
177
$(REMOVE) "$(TARGET).lss"
178
$(REMOVE) "$(TARGET).i"
179
$(REMOVE) "$(TARGET).s"
180
$(REMOVEDIR) "$(OBJDIR)"
184
$(shell mkdir -p $(BACKUPDIR) 2>/dev/null)
185
@for memory in $(MEMORYTYPES); do \
186
$(AVRDUDE) $(AVRDUDE_FLAGS) -U $$memory:r:$(BACKUPDIR)/$(MCU).$$memory.hex:i; \
190
.PHONY: all size build elf hex eep lss clean program flash eeprom readfuses writefuses printfuses backup help