1 # WinAVR Sample makefile written by Eric B. Weddington, Jörg Wunsch, et al.
2 # Modified (bringing often-changed options to the top) by Elliot Williams
4 # make all = Make software and program
5 # make clean = Clean out built project files.
6 # make program = Download the hex file to the device, using avrdude. Please
7 # customize the avrdude settings below first!
12 # Target file name (without extension).
13 TARGET
= cerebrum_firmware
15 # Programming hardware: type avrdude -c ?
16 # to get a full listing.
17 AVRDUDE_PROGRAMMER
= stk500v2
19 AVRDUDE_PORT
= /dev
/ttyACM0
-b
115200
21 ############# Don't need to change below here for most purposes (Elliot)
23 # Optimization level, can be [0, 1, 2, 3, s]. 0 turns off optimization.
24 # (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
27 # Output format. (can be srec, ihex, binary)
30 # List C source files here. (C dependencies are automatically generated.)
31 SRC
= $(TARGET
).c uart.c
33 # List Assembler source files here.
34 # Make them always end in a capital .S. Files ending in a lowercase .s
35 # will not be considered source files but generated files (assembler
36 # output from the compiler), and will be deleted upon "make clean"!
37 # Even though the DOS/Win* filesystem matches both .s and .S the same,
38 # it will preserve the spelling of the filenames, and gcc itself does
39 # care about how the name is spelled on its command-line.
43 # List any extra directories to look for include files here.
44 # Each directory must be seperated by a space.
48 # Optional compiler flags.
49 # -g: generate debugging information (for GDB, or for COFF conversion)
50 # -O*: optimization level
51 # -f...: tuning, see gcc manual and avr-libc documentation
52 # -Wall...: warning level
53 # -Wa,...: tell GCC to pass this to the assembler.
54 # -ahlms: create assembler listing
55 CFLAGS
= -g
-O
$(OPT
) \
56 -funsigned-char
-funsigned-bitfields
-fpack-struct
-fshort-enums \
57 -Wall
-Wstrict-prototypes \
58 -Wa
,-adhlns
=$(<:.c
=.lst
) \
59 $(patsubst %,-I
%,$(EXTRAINCDIRS
))
62 # Set a "language standard" compiler flag.
63 # Unremark just one line below to set the language standard to use.
64 # gnu99 = C99 + GNU extensions. See GCC manual for more information.
68 CFLAGS
+= -std
=gnu99
-DF_CPU
=16000000UL
72 # Optional assembler flags.
73 # -Wa,...: tell GCC to pass this to the assembler.
74 # -ahlms: create listing
75 # -gstabs: have the assembler create line number information; note that
76 # for use in COFF files, additional information about filenames
77 # and function names needs to be present in the assembler source
78 # files -- see avr-libc docs [FIXME: not yet described there]
79 ASFLAGS
= -Wa
,-adhlns
=$(<:.S
=.lst
),-gstabs
83 # Optional linker flags.
84 # -Wl,...: tell GCC to pass this to linker.
85 # -Map: create map file
86 # --cref: add cross reference to map file
87 LDFLAGS
= -Wl
,-Map
=$(TARGET
).map
,--cref
91 # Additional libraries
93 # Minimalistic printf version
94 #LDFLAGS += -Wl,-u,vfprintf -lprintf_min
96 # Floating point printf version (requires -lm below)
97 #LDFLAGS += -Wl,-u,vfprintf -lprintf_flt
103 # Programming support using avrdude. Settings and variables.
106 AVRDUDE_WRITE_FLASH
= -U flash
:w
:$(TARGET
).hex
107 #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
109 AVRDUDE_FLAGS
= -p
$(MCU
) -P
$(AVRDUDE_PORT
) -c
$(AVRDUDE_PROGRAMMER
)
111 # Uncomment the following if you want avrdude's erase cycle counter.
112 # Note that this counter needs to be initialized first using -Yn,
113 # see avrdude manual.
116 # Uncomment the following if you do /not/ wish a verification to be
117 # performed after programming the device.
120 # Increase verbosity level. Please use this when submitting bug
121 # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
122 # to submit bug reports.
123 #AVRDUDE_FLAGS += -v -v
125 # Define programs and commands.
130 OBJCOPY
= avr-objcopy
131 OBJDUMP
= avr-objdump
135 # Programming support using avrdude.
142 HEXSIZE
= $(SIZE
) --target
=$(FORMAT
) $(TARGET
).hex
143 ELFSIZE
= $(SIZE
) -A
$(TARGET
).elf
149 MSG_ERRORS_NONE
= Errors
: none
150 MSG_BEGIN
= -------- begin
--------
151 MSG_END
= -------- end
--------
152 MSG_SIZE_BEFORE
= Size before
:
153 MSG_SIZE_AFTER
= Size after
:
154 MSG_COFF
= Converting to AVR COFF
:
155 MSG_EXTENDED_COFF
= Converting to AVR Extended COFF
:
156 MSG_FLASH
= Creating load file for Flash
:
157 MSG_EEPROM
= Creating load file for EEPROM
:
158 MSG_EXTENDED_LISTING
= Creating Extended Listing
:
159 MSG_SYMBOL_TABLE
= Creating Symbol Table
:
160 MSG_LINKING
= Linking
:
161 MSG_COMPILING
= Compiling
:
162 MSG_ASSEMBLING
= Assembling
:
163 MSG_CLEANING
= Cleaning project
:
168 # Define all object files.
169 OBJ
= $(SRC
:.c
=.o
) $(ASRC
:.S
=.o
)
171 # Define all listing files.
172 LST
= $(ASRC
:.S
=.lst
) $(SRC
:.c
=.lst
)
174 # Combine all necessary flags and optional flags.
175 # Add target processor to flags.
176 ALL_CFLAGS
= -mmcu
=$(MCU
) -I.
$(CFLAGS
)
177 ALL_ASFLAGS
= -mmcu
=$(MCU
) -I.
-x assembler-with-cpp
$(ASFLAGS
)
181 # Default target: make program!
182 all: begin gccversion sizebefore
$(TARGET
).elf
$(TARGET
).hex
$(TARGET
).eep \
183 $(TARGET
).lss
$(TARGET
).sym sizeafter finished end
184 # $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
187 # AVR Studio 3.x does not check make's exit code but relies on
188 # the following magic strings to be generated by the compile job.
194 @echo
$(MSG_ERRORS_NONE
)
201 # Display size of file.
203 @if
[ -f
$(TARGET
).elf
]; then echo
; echo
$(MSG_SIZE_BEFORE
); $(ELFSIZE
); echo
; fi
206 @if
[ -f
$(TARGET
).elf
]; then echo
; echo
$(MSG_SIZE_AFTER
); $(ELFSIZE
); echo
; fi
210 # Display compiler version information.
217 # Convert ELF to COFF for use in debugging / simulating in
218 # AVR Studio or VMLAB.
219 COFFCONVERT
=$(OBJCOPY
) --debugging \
220 --change-section-address .data-0x800000 \
221 --change-section-address .bss-0x800000 \
222 --change-section-address .noinit-0x800000 \
223 --change-section-address .eeprom-0x810000
228 @echo
$(MSG_COFF
) $(TARGET
).cof
229 $(COFFCONVERT
) -O coff-avr
$< $(TARGET
).cof
232 extcoff
: $(TARGET
).elf
234 @echo
$(MSG_EXTENDED_COFF
) $(TARGET
).cof
235 $(COFFCONVERT
) -O coff-ext-avr
$< $(TARGET
).cof
240 # Program the device.
241 program
: $(TARGET
).hex
$(TARGET
).eep
243 $(AVRDUDE
) $(AVRDUDE_FLAGS
) $(AVRDUDE_WRITE_FLASH
) $(AVRDUDE_WRITE_EEPROM
)
248 # Create final output files (.hex, .eep) from ELF output file.
251 @echo
$(MSG_FLASH
) $@
252 $(OBJCOPY
) -O
$(FORMAT
) -R .eeprom
$< $@
256 @echo
$(MSG_EEPROM
) $@
257 -$(OBJCOPY
) -j .eeprom
--set-section-flags
=.eeprom
="alloc,load" \
258 --change-section-lma .eeprom
=0 -O
$(FORMAT
) $< $@
260 # Create extended listing file from ELF output file.
263 @echo
$(MSG_EXTENDED_LISTING
) $@
264 $(OBJDUMP
) -h
-S
$< > $@
266 # Create a symbol table from ELF output file.
269 @echo
$(MSG_SYMBOL_TABLE
) $@
274 # Link: create ELF output file from object files.
275 .SECONDARY
: $(TARGET
).elf
279 @echo
$(MSG_LINKING
) $@
280 $(CC
) $(ALL_CFLAGS
) $(OBJ
) --output
$@
$(LDFLAGS
)
283 # Compile: create object files from C source files.
286 @echo
$(MSG_COMPILING
) $<
287 $(CC
) -c
$(ALL_CFLAGS
) $< -o
$@
290 # Compile: create assembler files from C source files.
292 $(CC
) -S
$(ALL_CFLAGS
) $< -o
$@
295 # Assemble: create object files from assembler source files.
298 @echo
$(MSG_ASSEMBLING
) $<
299 $(CC
) -c
$(ALL_ASFLAGS
) $< -o
$@
306 # Target: clean project.
307 clean: begin clean_list finished end
311 @echo
$(MSG_CLEANING
)
312 $(REMOVE
) $(TARGET
).hex
313 $(REMOVE
) $(TARGET
).eep
314 $(REMOVE
) $(TARGET
).obj
315 $(REMOVE
) $(TARGET
).cof
316 $(REMOVE
) $(TARGET
).elf
317 $(REMOVE
) $(TARGET
).map
318 $(REMOVE
) $(TARGET
).obj
319 $(REMOVE
) $(TARGET
).a90
320 $(REMOVE
) $(TARGET
).sym
321 $(REMOVE
) $(TARGET
).lnk
322 $(REMOVE
) $(TARGET
).lss
325 $(REMOVE
) $(SRC
:.c
=.s
)
326 $(REMOVE
) $(SRC
:.c
=.d
)
329 # Automatically generate C source code dependencies.
330 # (Code originally taken from the GNU make user manual and modified
331 # (See README.txt Credits).)
333 # Note that this will work with sh (bash) and sed that is shipped with WinAVR
334 # (see the SHELL variable defined above).
335 # This may not work with other shells or other seds.
338 set
-e
; $(CC
) -MM
$(ALL_CFLAGS
) $< \
339 | sed
's,\(.*\)\.o[ :]*,\1.o \1.d : ,g' > $@
; \
340 [ -s
$@
] ||
rm -f
$@
343 # Remove the '-' if you want to see the dependency files generated.
344 -include $(SRC
:.c
=.d
)
348 # Listing of phony targets.
349 .PHONY
: all begin finish end sizebefore sizeafter gccversion coff extcoff \
350 clean clean_list program