2 #######################################
7 #######################################
10 #######################################
18 include mk
/hw
/${HW}.mk
21 INCLUDES
+=-I mm
/include -I
include -I.
22 CFLAGS
+=-D__HW_CONF_HEADER__
="<config/${CONFIG}.h>"
24 CFLAGS
+= -mmcu
=$(MCU
) -DF_CPU
=$(F_CPU
)UL
26 CFLAGS
+= -funsigned-char
-funsigned-bitfields
-fpack-struct
-fshort-enums
27 CFLAGS
+= -Wall
-Wstrict-prototypes
28 CFLAGS
+= -Os
-gdwarf-2
29 CFLAGS
+= -Wa
,-adhlns
=$(<:.c
=.lst
)
30 CFLAGS
+= -MD
$(@
:.c
:.d
)
33 ASFLAGS
+= -Wa
,-adhlns
=$(<:.S
=.lst
),-gstabs
-mmcu
=$(MCU
)
34 ASFLAGS
+= -x assembler-with-cpp
36 #---------------- Library Options ----------------
37 # Minimalistic printf version
38 PRINTF_LIB_MIN
= -Wl
,-u
,vfprintf
-lprintf_min
40 # Floating point printf version (requires MATH_LIB = -lm below)
41 PRINTF_LIB_FLOAT
= -Wl
,-u
,vfprintf
-lprintf_flt
43 # If this is left blank, then it will use the Standard printf version.
45 #PRINTF_LIB = $(PRINTF_LIB_MIN)
46 #PRINTF_LIB = $(PRINTF_LIB_FLOAT)
48 # Minimalistic scanf version
49 SCANF_LIB_MIN
= -Wl
,-u
,vfscanf
-lscanf_min
51 # Floating point + %[ scanf version (requires MATH_LIB = -lm below)
52 SCANF_LIB_FLOAT
= -Wl
,-u
,vfscanf
-lscanf_flt
54 # If this is left blank, then it will use the Standard scanf version.
56 #SCANF_LIB = $(SCANF_LIB_MIN)
57 #SCANF_LIB = $(SCANF_LIB_FLOAT)
59 LDFLAGS
= -Wl
,-Map
=$(@
:.elf
=.map
),--cref
60 LIBS
+= $(PRINTF_LIB
) $(SCANF_LIB
) $(MATH_LIB
)
62 #---------------- Programming Options (avrdude) ----------------
64 # Programming hardware: alf avr910 avrisp bascom bsd
65 # dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
68 # to get a full listing.
70 AVRDUDE_PROGRAMMER ?
= avrisp2
72 # com1 = serial port. Use lpt1 to connect to parallel port.
75 AVRDUDE_WRITE_FUSES
= -U lfuse
:w
:${LFUSE}:m
-U hfuse
:w
:${HFUSE}:m \
78 # Uncomment the following if you want avrdude's erase cycle counter.
79 # Note that this counter needs to be initialized first using -Yn,
81 #AVRDUDE_ERASE_COUNTER = -y
83 # Uncomment the following if you do /not/ wish a verification to be
84 # performed after programming the device.
85 # AVRDUDE_NO_VERIFY = -V
87 # Increase verbosity level. Please use this when submitting bug
88 # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
89 # to submit bug reports.
90 #AVRDUDE_VERBOSE = -v -v
92 AVRDUDE_FLAGS
= -p
$(MCU
) -P
$(AVRDUDE_PORT
) -c
$(AVRDUDE_PROGRAMMER
)
93 AVRDUDE_FLAGS
+= $(AVRDUDE_NO_VERIFY
)
94 AVRDUDE_FLAGS
+= $(AVRDUDE_VERBOSE
)
95 AVRDUDE_FLAGS
+= $(AVRDUDE_ERASE_COUNTER
)
98 # Define programs and commands.
101 OBJCOPY
= avr-objcopy
102 OBJDUMP
= avr-objdump
108 define SELECT_DEFAULT_template
=
116 program
: $(1)_program
122 cleanall
: $(foreach prog
, $(PROGRAMS
), $(prog
)_clean
)
123 buildall
: $(foreach prog
, $(PROGRAMS
), $(prog
)_build
)
125 .PHONY
: clean build program cleanall buildall
all
127 $(eval
$(call SELECT_DEFAULT_template
, $(PROG
)))
129 # Create final output files (.hex, .eep) from ELF output file.
132 $(Q
)$(OBJCOPY
) -O ihex
-R .fuse
-R .eeprom
$< $@
136 $(Q
)$(OBJCOPY
) -j .eeprom
--set-section-flags
=.eeprom
="alloc,load" \
137 --change-section-lma .eeprom
=0 -O ihex
$< $@
139 # Create extended listing file from ELF output file.
142 $(Q
)$(OBJDUMP
) -h
-S
$< > $@
144 # Create a symbol table from ELF output file.
149 # Link: create ELF output file from object files.
152 $(Q
)$(CC
) $(CFLAGS
) $^
-o
$@
$(LDFLAGS
)
154 # Compile: create object files from C source files.
157 $(Q
)$(CC
) -c
$(CFLAGS
) $< -o
$@
159 # Compile: create assembler files from C source files.
162 $(Q
)$(CC
) -S
$(CFLAGS
) $< -o
$@
164 # Assemble: create object files from assembler source files.
167 $(Q
)$(CC
) -c
$(ASFLAGS
) $< -o
$@
169 ########################### The big template for each program ##################
170 define PROGRAM_template
=
172 # Determine program's object files
173 $(1)_OBJS
=$$($(1)_SRC
:.c
=.o
)
174 $(1)_OBJS
+=$$($(1)_ASRC
:.S
=.o
)
176 # Collect all listing files - for cleanup
177 $(1)_LST
+= $$($(1)_SRC
:.c
=.lst
) $$($(1)_ASRC
:.S
=.lst
)
180 $(1).elf
: $$($(1)_OBJS
)
182 $(1)_program
: $(1).hex
$(1).eep
184 $(Q
)$(AVRDUDE
) $(AVRDUDE_FLAGS
) -U flash
:w
:$(1).hex
-U eeprom
:w
:$(1).eep
189 $(1)_fuses.bin
: $(1).elf
191 $(Q
)$(OBJCOPY
) -j .fuse
$(1).elf
-O binary
$$@
194 $(1)_fuses
: $(1)_fuses.bin
196 $(Q
)$(AVRDUDE
) $(AVRDUDE_FLAGS
)\
197 -U lfuse
:w
:0x
$$$$(hd
$(1)_fuses.bin| awk
'{print $$$$2}'):m \
198 -U hfuse
:w
:0x
$$$$(hd
$(1)_fuses.bin| awk
'{print $$$$3}'):m \
199 -U efuse
:w
:0x
$$$$(hd
$(1)_fuses.bin| head
-n1 |awk
'{print $$$$4}'):m
203 $(Q
) $(SIZE
) -A
$(1).elf
205 # Target: clean project.
215 $(Q
)$(RM
) $$($(1)_OBJS
)
216 $(Q
)$(RM
) $$($(1)_LST
)
217 $(Q
)$(RM
) $$($(1)_SRC
:.c
=.s
)
218 $(Q
)$(RM
) $$($(1)_SRC
:.c
=.d
)
219 @
$(Q
)$(RM
) $(1)_fuses.bin
221 $(1)_build
: $(1).hex
$(1)_size
223 -include $$($(1)_OBJS
:.o
=.d
)
225 .PRECIOUS
: $$($(1)_OBJS
)
226 .PHONY
: $(1) $(1)_clean
$(1)_size
$(1)_build
230 ################################################################################
232 $(foreach prog
,$(PROGRAMS
),$(eval
$(call PROGRAM_template
,$(prog
))))