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!
14 >>>>>>> feeeea7... Converted to plain c. Added a makefile.
16 # Target file name (without extension).
17 TARGET
= cerebrum_firmware
19 # Programming hardware: type avrdude -c ?
20 # to get a full listing.
22 AVRDUDE_PROGRAMMER
= stk500v1
24 AVRDUDE_PORT
= /dev
/arduino0
-b
57600
26 # AVRDUDE_PROGRAMMER = dapa
27 AVRDUDE_PROGRAMMER
= stk500v2
28 # AVRDUDE_PROGRAMMER = dt006
30 AVRDUDE_PORT
= /dev
/ttyUSB0
# not really needed for usb
31 >>>>>>> feeeea7... Converted to plain c. Added a makefile.
33 ############# Don't need to change below here for most purposes (Elliot)
35 # Optimization level, can be [0, 1, 2, 3, s]. 0 turns off optimization.
36 # (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
39 # Output format. (can be srec, ihex, binary)
42 # List C source files here. (C dependencies are automatically generated.)
44 SRC
= $(TARGET
).c uart.c
48 # If there is more than one source file, append them above, or modify and
49 # uncomment the following:
52 # You can also wrap lines by appending a backslash to the end of the line:
57 >>>>>>> feeeea7... Converted to plain c. Added a makefile.
59 # List Assembler source files here.
60 # Make them always end in a capital .S. Files ending in a lowercase .s
61 # will not be considered source files but generated files (assembler
62 # output from the compiler), and will be deleted upon "make clean"!
63 # Even though the DOS/Win* filesystem matches both .s and .S the same,
64 # it will preserve the spelling of the filenames, and gcc itself does
65 # care about how the name is spelled on its command-line.
69 # List any extra directories to look for include files here.
70 # Each directory must be seperated by a space.
74 # Optional compiler flags.
75 # -g: generate debugging information (for GDB, or for COFF conversion)
76 # -O*: optimization level
77 # -f...: tuning, see gcc manual and avr-libc documentation
78 # -Wall...: warning level
79 # -Wa,...: tell GCC to pass this to the assembler.
80 # -ahlms: create assembler listing
81 CFLAGS
= -g
-O
$(OPT
) \
82 -funsigned-char
-funsigned-bitfields
-fpack-struct
-fshort-enums \
83 -Wall
-Wstrict-prototypes \
84 -Wa
,-adhlns
=$(<:.c
=.lst
) \
85 $(patsubst %,-I
%,$(EXTRAINCDIRS
))
88 # Set a "language standard" compiler flag.
89 # Unremark just one line below to set the language standard to use.
90 # gnu99 = C99 + GNU extensions. See GCC manual for more information.
95 CFLAGS
+= -std
=gnu99
-DF_CPU
=16000000
98 >>>>>>> feeeea7... Converted to plain c. Added a makefile.
102 # Optional assembler flags.
103 # -Wa,...: tell GCC to pass this to the assembler.
104 # -ahlms: create listing
105 # -gstabs: have the assembler create line number information; note that
106 # for use in COFF files, additional information about filenames
107 # and function names needs to be present in the assembler source
108 # files -- see avr-libc docs [FIXME: not yet described there]
109 ASFLAGS
= -Wa
,-adhlns
=$(<:.S
=.lst
),-gstabs
113 # Optional linker flags.
114 # -Wl,...: tell GCC to pass this to linker.
115 # -Map: create map file
116 # --cref: add cross reference to map file
117 LDFLAGS
= -Wl
,-Map
=$(TARGET
).map
,--cref
121 # Additional libraries
123 # Minimalistic printf version
124 #LDFLAGS += -Wl,-u,vfprintf -lprintf_min
126 # Floating point printf version (requires -lm below)
127 #LDFLAGS += -Wl,-u,vfprintf -lprintf_flt
133 # Programming support using avrdude. Settings and variables.
136 AVRDUDE_WRITE_FLASH
= -U flash
:w
:$(TARGET
).hex
137 #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
139 AVRDUDE_FLAGS
= -p
$(MCU
) -P
$(AVRDUDE_PORT
) -c
$(AVRDUDE_PROGRAMMER
)
141 # Uncomment the following if you want avrdude's erase cycle counter.
142 # Note that this counter needs to be initialized first using -Yn,
143 # see avrdude manual.
146 # Uncomment the following if you do /not/ wish a verification to be
147 # performed after programming the device.
150 # Increase verbosity level. Please use this when submitting bug
151 # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
152 # to submit bug reports.
153 #AVRDUDE_FLAGS += -v -v
157 #Run while cable attached or don't
158 AVRDUDE_FLAGS
+= -E reset
#keep chip disabled while cable attached
159 #AVRDUDE_FLAGS += -E noreset
161 #AVRDUDE_WRITE_FLASH = -U lfuse:w:0x04:m #run with 8 Mhz clock
163 #AVRDUDE_WRITE_FLASH = -U lfuse:w:0x21:m #run with 1 Mhz clock #default clock mode
165 #AVRDUDE_WRITE_FLASH = -U lfuse:w:0x01:m #run with 1 Mhz clock no start up time
167 # ---------------------------------------------------------------------------
169 # Define directories, if needed.
171 DIRAVRBIN
= $(DIRAVR
)/bin
172 DIRAVRUTILS
= $(DIRAVR
)/utils
/bin
174 DIRLIB
= $(DIRAVR
)/avr
/lib
177 >>>>>>> feeeea7... Converted to plain c. Added a makefile.
178 # Define programs and commands.
183 OBJCOPY
= avr-objcopy
184 OBJDUMP
= avr-objdump
188 # Programming support using avrdude.
195 HEXSIZE
= $(SIZE
) --target
=$(FORMAT
) $(TARGET
).hex
196 ELFSIZE
= $(SIZE
) -A
$(TARGET
).elf
202 MSG_ERRORS_NONE
= Errors
: none
203 MSG_BEGIN
= -------- begin
--------
204 MSG_END
= -------- end
--------
205 MSG_SIZE_BEFORE
= Size before
:
206 MSG_SIZE_AFTER
= Size after
:
207 MSG_COFF
= Converting to AVR COFF
:
208 MSG_EXTENDED_COFF
= Converting to AVR Extended COFF
:
209 MSG_FLASH
= Creating load file for Flash
:
210 MSG_EEPROM
= Creating load file for EEPROM
:
211 MSG_EXTENDED_LISTING
= Creating Extended Listing
:
212 MSG_SYMBOL_TABLE
= Creating Symbol Table
:
213 MSG_LINKING
= Linking
:
214 MSG_COMPILING
= Compiling
:
215 MSG_ASSEMBLING
= Assembling
:
216 MSG_CLEANING
= Cleaning project
:
221 # Define all object files.
222 OBJ
= $(SRC
:.c
=.o
) $(ASRC
:.S
=.o
)
224 # Define all listing files.
225 LST
= $(ASRC
:.S
=.lst
) $(SRC
:.c
=.lst
)
227 # Combine all necessary flags and optional flags.
228 # Add target processor to flags.
229 ALL_CFLAGS
= -mmcu
=$(MCU
) -I.
$(CFLAGS
)
230 ALL_ASFLAGS
= -mmcu
=$(MCU
) -I.
-x assembler-with-cpp
$(ASFLAGS
)
234 # Default target: make program!
235 all: begin gccversion sizebefore
$(TARGET
).elf
$(TARGET
).hex
$(TARGET
).eep \
236 $(TARGET
).lss
$(TARGET
).sym sizeafter finished end
237 # $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
240 # AVR Studio 3.x does not check make's exit code but relies on
241 # the following magic strings to be generated by the compile job.
247 @echo
$(MSG_ERRORS_NONE
)
254 # Display size of file.
256 @if
[ -f
$(TARGET
).elf
]; then echo
; echo
$(MSG_SIZE_BEFORE
); $(ELFSIZE
); echo
; fi
259 @if
[ -f
$(TARGET
).elf
]; then echo
; echo
$(MSG_SIZE_AFTER
); $(ELFSIZE
); echo
; fi
263 # Display compiler version information.
270 # Convert ELF to COFF for use in debugging / simulating in
271 # AVR Studio or VMLAB.
272 COFFCONVERT
=$(OBJCOPY
) --debugging \
273 --change-section-address .data-0x800000 \
274 --change-section-address .bss-0x800000 \
275 --change-section-address .noinit-0x800000 \
276 --change-section-address .eeprom-0x810000
281 @echo
$(MSG_COFF
) $(TARGET
).cof
282 $(COFFCONVERT
) -O coff-avr
$< $(TARGET
).cof
285 extcoff
: $(TARGET
).elf
287 @echo
$(MSG_EXTENDED_COFF
) $(TARGET
).cof
288 $(COFFCONVERT
) -O coff-ext-avr
$< $(TARGET
).cof
293 # Program the device.
294 program
: $(TARGET
).hex
$(TARGET
).eep
298 >>>>>>> feeeea7... Converted to plain c. Added a makefile.
299 $(AVRDUDE
) $(AVRDUDE_FLAGS
) $(AVRDUDE_WRITE_FLASH
) $(AVRDUDE_WRITE_EEPROM
)
304 # Create final output files (.hex, .eep) from ELF output file.
307 @echo
$(MSG_FLASH
) $@
308 $(OBJCOPY
) -O
$(FORMAT
) -R .eeprom
$< $@
312 @echo
$(MSG_EEPROM
) $@
313 -$(OBJCOPY
) -j .eeprom
--set-section-flags
=.eeprom
="alloc,load" \
314 --change-section-lma .eeprom
=0 -O
$(FORMAT
) $< $@
316 # Create extended listing file from ELF output file.
319 @echo
$(MSG_EXTENDED_LISTING
) $@
320 $(OBJDUMP
) -h
-S
$< > $@
322 # Create a symbol table from ELF output file.
325 @echo
$(MSG_SYMBOL_TABLE
) $@
330 # Link: create ELF output file from object files.
331 .SECONDARY
: $(TARGET
).elf
335 @echo
$(MSG_LINKING
) $@
336 $(CC
) $(ALL_CFLAGS
) $(OBJ
) --output
$@
$(LDFLAGS
)
339 # Compile: create object files from C source files.
342 @echo
$(MSG_COMPILING
) $<
343 $(CC
) -c
$(ALL_CFLAGS
) $< -o
$@
346 # Compile: create assembler files from C source files.
348 $(CC
) -S
$(ALL_CFLAGS
) $< -o
$@
351 # Assemble: create object files from assembler source files.
354 @echo
$(MSG_ASSEMBLING
) $<
355 $(CC
) -c
$(ALL_ASFLAGS
) $< -o
$@
362 # Target: clean project.
363 clean: begin clean_list finished end
367 @echo
$(MSG_CLEANING
)
368 $(REMOVE
) $(TARGET
).hex
369 $(REMOVE
) $(TARGET
).eep
370 $(REMOVE
) $(TARGET
).obj
371 $(REMOVE
) $(TARGET
).cof
372 $(REMOVE
) $(TARGET
).elf
373 $(REMOVE
) $(TARGET
).map
374 $(REMOVE
) $(TARGET
).obj
375 $(REMOVE
) $(TARGET
).a90
376 $(REMOVE
) $(TARGET
).sym
377 $(REMOVE
) $(TARGET
).lnk
378 $(REMOVE
) $(TARGET
).lss
381 $(REMOVE
) $(SRC
:.c
=.s
)
382 $(REMOVE
) $(SRC
:.c
=.d
)
385 # Automatically generate C source code dependencies.
386 # (Code originally taken from the GNU make user manual and modified
387 # (See README.txt Credits).)
389 # Note that this will work with sh (bash) and sed that is shipped with WinAVR
390 # (see the SHELL variable defined above).
391 # This may not work with other shells or other seds.
394 set
-e
; $(CC
) -MM
$(ALL_CFLAGS
) $< \
395 | sed
's,\(.*\)\.o[ :]*,\1.o \1.d : ,g' > $@
; \
396 [ -s
$@
] ||
rm -f
$@
399 # Remove the '-' if you want to see the dependency files generated.
400 -include $(SRC
:.c
=.d
)
404 # Listing of phony targets.
405 .PHONY
: all begin finish end sizebefore sizeafter gccversion coff extcoff \
406 clean clean_list program