5 # Output format. (can be srec, ihex, binary)
8 # Target file name (without extension).
11 # Optimization level, can be [0, 1, 2, 3, s]. 0 turns off optimization.
12 # (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
15 # List C source files here. (C dependencies are automatically generated.)
16 SRC
= main.c NAcodes.c
#util.c
18 # List Assembler source files here.
19 # Make them always end in a capital .S. Files ending in a lowercase .s
20 # will not be considered source files but generated files (assembler
21 # output from the compiler), and will be deleted upon "make clean"!
22 # Even though the DOS/Win filesystem matches both .s and .S the same,
23 # it will preserve the spelling of the filenames, and gcc itself does
24 # care about how the name is spelled on its command-line.
25 # Optional compiler flags.
26 # -g: generate debugging information (for GDB, or for COFF conversion)
27 # -O*: optimization level
28 # -f...: tuning, see gcc manual and avr-libc documentation
29 # -Wall...: warning level
30 # -Wa,...: tell GCC to pass this to the assembler.
31 # -ahlms: create assembler listing
32 CFLAGS
= -g
-O
$(OPT
) \
33 -funsigned-char
-funsigned-bitfields
-fpack-struct
-fshort-enums \
34 -Wall
-Wstrict-prototypes \
36 -Wa
,-adhlns
=$(<:.c
=.lst
) \
37 $(patsubst %,-I
%,$(EXTRAINCDIRS
))
40 # Set a "language standard" compiler flag.
41 # Unremark just one line below to set the language standard to use.
42 # gnu99 = C99 + GNU extensions. See GCC manual for more information.
50 # Optional assembler flags.
51 # -Wa,...: tell GCC to pass this to the assembler.
52 # -ahlms: create listing
53 # -gstabs: have the assembler create line number information; note that
54 # for use in COFF files, additional information about filenames
55 # and function names needs to be present in the assembler source
56 # files -- see avr-libc docs [FIXME: not yet described there]
57 ASFLAGS
= -Wa
,-adhlns
=$(<:.S
=.lst
),-gstabs
61 # Optional linker flags.
62 # -Wl,...: tell GCC to pass this to linker.
63 # -Map: create map file
64 # --cref: add cross reference to map file
65 LDFLAGS
= -Wl
,-Map
=$(TARGET
).map
,--cref
69 # Additional libraries
71 # Minimalistic printf version
72 #LDFLAGS += -Wl,-u,vfprintf -lprintf_min
74 # Floating point printf version (requires -lm below)
75 #LDFLAGS += -Wl,-u,vfprintf -lprintf_flt
82 # Programming support using avrdude. Settings and variables.
84 # Programming hardware: alf avr910 avrisp bascom bsd
85 # dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
88 # to get a full listing.
92 AVRDUDE_PROGRAMMER
= usbtiny
93 AVRDUDE_PROGRAMMER
= dt006
95 #AVRDUDE_PORT = usb # programmer connected to serial device
98 AVRDUDE_WRITE_FLASH
= -B
1 -U flash
:w
:$(TARGET
).hex
99 #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
101 AVRDUDE_FLAGS
= -p
$(MCU
) -P
$(AVRDUDE_PORT
) -c
$(AVRDUDE_PROGRAMMER
)
103 # Uncomment the following if you want avrdude's erase cycle counter.
104 # Note that this counter needs to be initialized first using -Yn,
105 # see avrdude manual.
108 # Uncomment the following if you do /not/ wish a verification to be
109 # performed after programming the device.
112 # Increase verbosity level. Please use this when submitting bug
113 # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
114 # to submit bug reports.
115 #AVRDUDE_FLAGS += -v -v
120 # ---------------------------------------------------------------------------
122 # Define directories, if needed.
124 DIRAVRBIN
= $(DIRAVR
)/bin
125 DIRAVRUTILS
= $(DIRAVR
)/utils
/bin
127 DIRLIB
= $(DIRAVR
)/avr
/lib
130 # Define programs and commands.
135 OBJCOPY
= avr-objcopy
136 OBJDUMP
= avr-objdump
140 # Programming support using avrdude.
147 HEXSIZE
= $(SIZE
) --target
=$(FORMAT
) $(TARGET
).hex
148 ELFSIZE
= $(SIZE
) -A
$(TARGET
).elf
154 MSG_ERRORS_NONE
= Errors
: none
155 MSG_BEGIN
= -------- begin
--------
156 MSG_END
= -------- end
--------
157 MSG_SIZE_BEFORE
= Size before
:
158 MSG_SIZE_AFTER
= Size after
:
159 MSG_COFF
= Converting to AVR COFF
:
160 MSG_EXTENDED_COFF
= Converting to AVR Extended COFF
:
161 MSG_FLASH
= Creating load file for Flash
:
162 MSG_EEPROM
= Creating load file for EEPROM
:
163 MSG_EXTENDED_LISTING
= Creating Extended Listing
:
164 MSG_SYMBOL_TABLE
= Creating Symbol Table
:
165 MSG_LINKING
= Linking
:
166 MSG_COMPILING
= Compiling
:
167 MSG_ASSEMBLING
= Assembling
:
168 MSG_CLEANING
= Cleaning project
:
173 # Define all object files.
174 OBJ
= $(SRC
:.c
=.o
) $(ASRC
:.S
=.o
)
176 # Define all listing files.
177 LST
= $(ASRC
:.S
=.lst
) $(SRC
:.c
=.lst
)
179 # Combine all necessary flags and optional flags.
180 # Add target processor to flags.
181 ALL_CFLAGS
= -mmcu
=$(MCU
) -I.
$(CFLAGS
)
182 ALL_ASFLAGS
= -mmcu
=$(MCU
) -I.
-x assembler-with-cpp
$(ASFLAGS
)
187 all: begin gccversion sizebefore
$(TARGET
).elf
$(TARGET
).hex
$(TARGET
).eep \
188 $(TARGET
).lss
$(TARGET
).sym sizeafter finished end
192 # AVR Studio 3.x does not check make's exit code but relies on
193 # the following magic strings to be generated by the compile job.
199 @echo
$(MSG_ERRORS_NONE
)
206 # Display size of file.
208 @if
[ -f
$(TARGET
).elf
]; then echo
; echo
$(MSG_SIZE_BEFORE
); $(ELFSIZE
); echo
; fi
211 @if
[ -f
$(TARGET
).elf
]; then echo
; echo
$(MSG_SIZE_AFTER
); $(ELFSIZE
); echo
; fi
215 # Display compiler version information.
222 # Convert ELF to COFF for use in debugging / simulating in
223 # AVR Studio or VMLAB.
224 COFFCONVERT
=$(OBJCOPY
) --debugging \
225 --change-section-address .data-0x800000 \
226 --change-section-address .bss-0x800000 \
227 --change-section-address .noinit-0x800000 \
228 --change-section-address .eeprom-0x810000
233 @echo
$(MSG_COFF
) $(TARGET
).cof
234 $(COFFCONVERT
) -O coff-avr
$< $(TARGET
).cof
237 extcoff
: $(TARGET
).elf
239 @echo
$(MSG_EXTENDED_COFF
) $(TARGET
).cof
240 $(COFFCONVERT
) -O coff-ext-avr
$< $(TARGET
).cof
245 $(AVRDUDE
) $(AVRDUDE_FLAGS
)
247 # Program the device.
248 program
: $(TARGET
).hex
$(TARGET
).eep
249 $(AVRDUDE
) $(AVRDUDE_FLAGS
) $(AVRDUDE_WRITE_FLASH
) $(AVRDUDE_WRITE_EEPROM
)
256 $(AVRDUDE
) $(AVRDUDE_FLAGS
) -B
250 -u
-U lfuse
:w
:0xfd:m
-U hfuse
:w
:0xde:m
259 $(AVRDUDE
) $(AVRDUDE_FLAGS
) -u
-U lfuse
:r
:l.txt
:r
260 $(AVRDUDE
) $(AVRDUDE_FLAGS
) -u
-U hfuse
:r
:h.txt
:r
261 $(AVRDUDE
) $(AVRDUDE_FLAGS
) -u
-U efuse
:r
:e.txt
:r
262 # Create final output files (.hex, .eep) from ELF output file.
265 @echo
$(MSG_FLASH
) $@
266 $(OBJCOPY
) -O
$(FORMAT
) -R .eeprom
$< $@
270 @echo
$(MSG_EEPROM
) $@
271 -$(OBJCOPY
) -j .eeprom
--set-section-flags
=.eeprom
="alloc,load" \
272 --change-section-lma .eeprom
=0 -O
$(FORMAT
) $< $@
274 # Create extended listing file from ELF output file.
277 @echo
$(MSG_EXTENDED_LISTING
) $@
278 $(OBJDUMP
) -h
-S
$< > $@
280 # Create a symbol table from ELF output file.
283 @echo
$(MSG_SYMBOL_TABLE
) $@
288 # Link: create ELF output file from object files.
289 .SECONDARY
: $(TARGET
).elf
293 @echo
$(MSG_LINKING
) $@
294 $(CC
) $(ALL_CFLAGS
) $(OBJ
) --output
$@
$(LDFLAGS
)
297 # Compile: create object files from C source files.
300 @echo
$(MSG_COMPILING
) $<
301 $(CC
) -c
$(ALL_CFLAGS
) $< -o
$@
304 # Compile: create assembler files from C source files.
306 $(CC
) -S
$(ALL_CFLAGS
) $< -o
$@
309 # Assemble: create object files from assembler source files.
312 @echo
$(MSG_ASSEMBLING
) $<
313 $(CC
) -c
$(ALL_ASFLAGS
) $< -o
$@
320 # Target: clean project.
321 clean: begin clean_list finished end
325 @echo
$(MSG_CLEANING
)
326 $(REMOVE
) $(TARGET
).hex
327 $(REMOVE
) $(TARGET
).eep
328 $(REMOVE
) $(TARGET
).obj
329 $(REMOVE
) $(TARGET
).cof
330 $(REMOVE
) $(TARGET
).elf
331 $(REMOVE
) $(TARGET
).map
332 $(REMOVE
) $(TARGET
).obj
333 $(REMOVE
) $(TARGET
).a90
334 $(REMOVE
) $(TARGET
).sym
335 $(REMOVE
) $(TARGET
).lnk
336 $(REMOVE
) $(TARGET
).lss
339 $(REMOVE
) $(SRC
:.c
=.s
)
340 $(REMOVE
) $(SRC
:.c
=.d
)
343 # Automatically generate C source code dependencies.
344 # (Code originally taken from the GNU make user manual and modified
345 # (See README.txt Credits).)
347 # Note that this will work with sh (bash) and sed that is shipped with WinAVR
348 # (see the SHELL variable defined above).
349 # This may not work with other shells or other seds.
352 set
-e
; $(CC
) -MM
$(ALL_CFLAGS
) $< \
353 | sed
's,\(.*\)\.o[ :]*,\1.o \1.d : ,g' > $@
; \
354 [ -s
$@
] ||
rm -f
$@
357 # Remove the '-' if you want to see the dependency files generated.
358 -include $(SRC
:.c
=.d
)
362 # Listing of phony targets.
363 .PHONY
: all begin finish end sizebefore sizeafter gccversion coff extcoff \
364 clean clean_list program