1 #----------------------------------------------------------------------------
3 # Makefile based on the public domain Makefile by Peter Fleury
5 #----------------------------------------------------------------------------
8 # make all = Make software.
10 # make clean = Clean out built project files.
12 # make coff = Convert ELF to AVR COFF.
14 # make extcoff = Convert ELF to AVR Extended COFF.
16 # make program = Download the hex file to the device, using avrdude.
17 # Please customize the avrdude settings below first!
19 # make debug = Start either simulavr or avarice as specified for debugging,
20 # with avr-gdb or avr-insight as the front end for debugging.
22 # make filename.s = Just compile filename.c into the assembler code only.
24 # make filename.i = Create a preprocessed source file for use in submitting
25 # bug reports to the GCC project.
27 # To rebuild project do "make clean" then "make all".
28 #----------------------------------------------------------------------------
32 include mk
/${CONFIG}.mk
34 INCLUDES
+=-I mm
/include -I
include
35 SRC
+= mm
/src
/mm_switch.c
36 CFLAGS
+=-D__HW_CONF_HEADER__
="<config/${CONFIG}.h>"
41 # Processor frequency.
42 # This will define a symbol, F_CPU, in all source code files equal to the
43 # processor frequency. You can then use this symbol in your source code to
44 # calculate timings. Do NOT tack on a 'UL' at the end, this will be done
45 # automatically to create a 32-bit value in your source code.
49 # Output format. (can be srec, ihex, binary)
53 # Target file name (without extension).
56 # List C source files here. (C dependencies are automatically generated.)
62 # Optimization level, can be [0, 1, 2, 3, s].
63 # 0 = turn off optimization. s = optimize for size.
64 # (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
69 # Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
70 # AVR Studio 4.10 requires dwarf-2.
71 # AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.
75 # List any extra directories to look for include files here.
76 # Each directory must be seperated by a space.
77 # Use forward slashes for directory separators.
78 # For a directory that has spaces, enclose it in quotes.
82 # Compiler flag to set the C Standard level.
84 # gnu89 = c89 plus GCC extensions
85 # c99 = ISO C99 standard (not yet fully implemented)
86 # gnu99 = c99 plus GCC extensions
87 CSTANDARD
= -std
=gnu99
90 # Place -D or -U options here
91 CDEFS
= -DF_CPU
=$(F_CPU
)UL
-DBOOT_START
=${BOOT_START} -DBOOT_PAGES
=${BOOT_PAGES}
94 # Place -I options here
98 #BOOT_LDFLAGS=-Wl,-Ttext=${BOOT_START}
100 #---------------- Compiler Options ----------------
101 # -g*: generate debugging information
102 # -O*: optimization level
103 # -f...: tuning, see GCC manual and avr-libc documentation
104 # -Wall...: warning level
105 # -Wa,...: tell GCC to pass this to the assembler.
106 # -adhlns...: create assembler listing
108 CFLAGS
+= $(CDEFS
) $(CINCS
)
110 CFLAGS
+= -funsigned-char
-funsigned-bitfields
-fpack-struct
-fshort-enums
111 CFLAGS
+= -Wall
-Wstrict-prototypes
112 CFLAGS
+= -Wa
,-adhlns
=$(<:.c
=.lst
)
113 CFLAGS
+= $(patsubst %,-I
%,$(EXTRAINCDIRS
))
114 CFLAGS
+= $(CSTANDARD
)
115 CFLAGS
+= $(INCLUDES
)
118 #---------------- Assembler Options ----------------
119 # -Wa,...: tell GCC to pass this to the assembler.
120 # -ahlms: create listing
121 # -gstabs: have the assembler create line number information; note that
122 # for use in COFF files, additional information about filenames
123 # and function names needs to be present in the assembler source
124 # files -- see avr-libc docs [FIXME: not yet described there]
125 ASFLAGS
= -Wa
,-adhlns
=$(<:.S
=.lst
),-gstabs
128 #---------------- Library Options ----------------
129 # Minimalistic printf version
130 PRINTF_LIB_MIN
= -Wl
,-u
,vfprintf
-lprintf_min
132 # Floating point printf version (requires MATH_LIB = -lm below)
133 PRINTF_LIB_FLOAT
= -Wl
,-u
,vfprintf
-lprintf_flt
135 # If this is left blank, then it will use the Standard printf version.
137 #PRINTF_LIB = $(PRINTF_LIB_MIN)
138 #PRINTF_LIB = $(PRINTF_LIB_FLOAT)
141 # Minimalistic scanf version
142 SCANF_LIB_MIN
= -Wl
,-u
,vfscanf
-lscanf_min
144 # Floating point + %[ scanf version (requires MATH_LIB = -lm below)
145 SCANF_LIB_FLOAT
= -Wl
,-u
,vfscanf
-lscanf_flt
147 # If this is left blank, then it will use the Standard scanf version.
149 #SCANF_LIB = $(SCANF_LIB_MIN)
150 #SCANF_LIB = $(SCANF_LIB_FLOAT)
156 #---------------- External Memory Options ----------------
158 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
159 # used for variables (.data/.bss) and heap (malloc()).
160 #EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
162 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
163 # only used for heap (malloc()).
164 #EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff
170 #---------------- Linker Options ----------------
171 # -Wl,...: tell GCC to pass this to linker.
172 # -Map: create map file
173 # --cref: add cross reference to map file
174 LDFLAGS
= $(BOOT_LDFLAGS
) -Wl
,-Map
=$(TARGET
).map
,--cref
175 LDFLAGS
+= $(EXTMEMOPTS
)
176 LDFLAGS
+= $(PRINTF_LIB
) $(SCANF_LIB
) $(MATH_LIB
)
180 #---------------- Programming Options (avrdude) ----------------
182 # Programming hardware: alf avr910 avrisp bascom bsd
183 # dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
186 # to get a full listing.
189 AVRDUDE_PROGRAMMER ?
= avrisp2
192 # com1 = serial port. Use lpt1 to connect to parallel port.
195 AVRDUDE_WRITE_FLASH
= -U flash
:w
:$(TARGET
).hex
196 #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
198 AVRDUDE_WRITE_FUSES
= -U lfuse
:w
:${LFUSE}:m
-U hfuse
:w
:${HFUSE}:m \
199 -U efuse
:w
:${EFUSE}:m
201 # Uncomment the following if you want avrdude's erase cycle counter.
202 # Note that this counter needs to be initialized first using -Yn,
203 # see avrdude manual.
204 #AVRDUDE_ERASE_COUNTER = -y
206 # Uncomment the following if you do /not/ wish a verification to be
207 # performed after programming the device.
208 # AVRDUDE_NO_VERIFY = -V
210 # Increase verbosity level. Please use this when submitting bug
211 # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
212 # to submit bug reports.
213 #AVRDUDE_VERBOSE = -v -v
215 AVRDUDE_FLAGS
= -p
$(MCU
) -P
$(AVRDUDE_PORT
) -c
$(AVRDUDE_PROGRAMMER
)
216 AVRDUDE_FLAGS
+= $(AVRDUDE_NO_VERIFY
)
217 AVRDUDE_FLAGS
+= $(AVRDUDE_VERBOSE
)
218 AVRDUDE_FLAGS
+= $(AVRDUDE_ERASE_COUNTER
)
219 AVRDUDE_FLAGS
+= -B
2
222 #---------------- Debugging Options ----------------
224 # For simulavr only - target MCU frequency.
225 DEBUG_MFREQ
= $(F_CPU
)
227 # Set the DEBUG_UI to either gdb or insight.
231 # Set the debugging back-end to either avarice, simulavr.
232 DEBUG_BACKEND
= avarice
233 #DEBUG_BACKEND = simulavr
236 GDBINIT_FILE
= __avr_gdbinit
238 # When using avarice settings for the JTAG
241 # Debugging port used to communicate between GDB / avarice / simulavr.
244 # Debugging host used to communicate between GDB / avarice / simulavr, normally
245 # just set to localhost unless doing some sort of crazy debugging when
246 # avarice is running on a different computer.
247 DEBUG_HOST
= localhost
251 #============================================================================
254 # Define programs and commands.
257 OBJCOPY
= avr-objcopy
258 OBJDUMP
= avr-objdump
269 MSG_ERRORS_NONE
= Errors
: none
270 MSG_BEGIN
= -------- begin
--------
271 MSG_END
= -------- end
--------
272 MSG_SIZE_BEFORE
= Size before
:
273 MSG_SIZE_AFTER
= Size after
:
274 MSG_COFF
= Converting to AVR COFF
:
275 MSG_EXTENDED_COFF
= Converting to AVR Extended COFF
:
276 MSG_FLASH
= Creating load file for Flash
:
277 MSG_EEPROM
= Creating load file for EEPROM
:
278 MSG_EXTENDED_LISTING
= Creating Extended Listing
:
279 MSG_SYMBOL_TABLE
= Creating Symbol Table
:
280 MSG_LINKING
= Linking
:
281 MSG_COMPILING
= Compiling
:
282 MSG_ASSEMBLING
= Assembling
:
283 MSG_CLEANING
= Cleaning project
:
286 # Define all object files.
287 OBJ
= $(SRC
:.c
=.o
) $(ASRC
:.S
=.o
)
289 # Define all listing files.
290 LST
= $(SRC
:.c
=.lst
) $(ASRC
:.S
=.lst
)
293 # Compiler flags to generate dependency files.
294 GENDEPFLAGS
= -MD
-MP
-MF .dep
/$(@F
).d
297 # Combine all necessary flags and optional flags.
298 # Add target processor to flags.
299 ALL_CFLAGS
= -mmcu
=$(MCU
) -I.
$(CFLAGS
) $(GENDEPFLAGS
)
300 ALL_ASFLAGS
= -mmcu
=$(MCU
) -I.
-x assembler-with-cpp
$(ASFLAGS
)
304 all: begin gccversion sizebefore build sizeafter end
306 build
: elf hex eep lss sym
316 # AVR Studio 3.x does not check make's exit code but relies on
317 # the following magic strings to be generated by the compile job.
327 # Display size of file.
328 HEXSIZE
= $(SIZE
) --target
=$(FORMAT
) $(TARGET
).hex
329 ELFSIZE
= $(SIZE
) -A
$(TARGET
).elf
330 AVRMEM
= avr-mem.sh
$(TARGET
).elf
$(MCU
)
333 @if
test -f
$(TARGET
).elf
; then echo
; echo
$(MSG_SIZE_BEFORE
); $(ELFSIZE
); \
334 $(AVRMEM
) 2>/dev
/null
; echo
; fi
337 @if
test -f
$(TARGET
).elf
; then echo
; echo
$(MSG_SIZE_AFTER
); $(ELFSIZE
); \
338 $(AVRMEM
) 2>/dev
/null
; echo
; fi
342 # Display compiler version information.
348 # Program the device.
349 program
: $(TARGET
).hex
$(TARGET
).eep
350 $(AVRDUDE
) $(AVRDUDE_FLAGS
) $(AVRDUDE_WRITE_FLASH
) $(AVRDUDE_WRITE_EEPROM
)
353 $(AVRDUDE
) $(AVRDUDE_FLAGS
) $(AVRDUDE_WRITE_FUSES
)
355 # Generate avr-gdb config/init file which does the following:
356 # define the reset signal, load the target file, connect to target, and set
357 # a breakpoint at main().
359 @
$(REMOVE
) $(GDBINIT_FILE
)
360 @echo
define reset
>> $(GDBINIT_FILE
)
361 @echo SIGNAL SIGHUP
>> $(GDBINIT_FILE
)
362 @echo end
>> $(GDBINIT_FILE
)
363 @echo file
$(TARGET
).elf
>> $(GDBINIT_FILE
)
364 @echo target remote
$(DEBUG_HOST
):$(DEBUG_PORT
) >> $(GDBINIT_FILE
)
365 ifeq ($(DEBUG_BACKEND
),simulavr
)
366 @echo load
>> $(GDBINIT_FILE
)
368 @echo break main
>> $(GDBINIT_FILE
)
370 debug
: gdb-config
$(TARGET
).elf
371 ifeq ($(DEBUG_BACKEND
), avarice
)
372 @echo Starting AVaRICE
- Press enter when
"waiting to connect" message displays.
373 @
$(WINSHELL
) /c start avarice
--jtag
$(JTAG_DEV
) --erase
--program
--file \
374 $(TARGET
).elf
$(DEBUG_HOST
):$(DEBUG_PORT
)
375 @
$(WINSHELL
) /c pause
378 @
$(WINSHELL
) /c start simulavr
--gdbserver
--device
$(MCU
) --clock-freq \
379 $(DEBUG_MFREQ
) --port
$(DEBUG_PORT
)
381 @
$(WINSHELL
) /c start avr-
$(DEBUG_UI
) --command
=$(GDBINIT_FILE
)
384 # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
385 COFFCONVERT
=$(OBJCOPY
) --debugging \
386 --change-section-address .data-0x800000 \
387 --change-section-address .bss-0x800000 \
388 --change-section-address .noinit-0x800000 \
389 --change-section-address .eeprom-0x810000
394 @echo
$(MSG_COFF
) $(TARGET
).cof
395 $(COFFCONVERT
) -O coff-avr
$< $(TARGET
).cof
398 extcoff
: $(TARGET
).elf
400 @echo
$(MSG_EXTENDED_COFF
) $(TARGET
).cof
401 $(COFFCONVERT
) -O coff-ext-avr
$< $(TARGET
).cof
405 # Create final output files (.hex, .eep) from ELF output file.
408 @echo
$(MSG_FLASH
) $@
409 $(OBJCOPY
) -O
$(FORMAT
) -R .eeprom
$< $@
413 @echo
$(MSG_EEPROM
) $@
414 -$(OBJCOPY
) -j .eeprom
--set-section-flags
=.eeprom
="alloc,load" \
415 --change-section-lma .eeprom
=0 -O
$(FORMAT
) $< $@
417 # Create extended listing file from ELF output file.
420 @echo
$(MSG_EXTENDED_LISTING
) $@
421 $(OBJDUMP
) -h
-S
$< > $@
423 # Create a symbol table from ELF output file.
426 @echo
$(MSG_SYMBOL_TABLE
) $@
431 # Link: create ELF output file from object files.
432 .SECONDARY
: $(TARGET
).elf
436 @echo
$(MSG_LINKING
) $@
437 $(CC
) $(ALL_CFLAGS
) $^
--output
$@
$(LDFLAGS
)
440 # Compile: create object files from C source files.
443 @echo
$(MSG_COMPILING
) $<
444 $(CC
) -c
$(ALL_CFLAGS
) $< -o
$@
447 # Compile: create assembler files from C source files.
449 $(CC
) -S
$(ALL_CFLAGS
) $< -o
$@
452 # Assemble: create object files from assembler source files.
455 @echo
$(MSG_ASSEMBLING
) $<
456 $(CC
) -c
$(ALL_ASFLAGS
) $< -o
$@
458 # Create preprocessed source for use in sending a bug report.
460 $(CC
) -E
-mmcu
=$(MCU
) -I.
$(CFLAGS
) $< -o
$@
463 # Target: clean project.
464 clean: begin clean_list end
468 @echo
$(MSG_CLEANING
)
469 $(REMOVE
) $(TARGET
).hex
470 $(REMOVE
) $(TARGET
).eep
471 $(REMOVE
) $(TARGET
).cof
472 $(REMOVE
) $(TARGET
).elf
473 $(REMOVE
) $(TARGET
).map
474 $(REMOVE
) $(TARGET
).sym
475 $(REMOVE
) $(TARGET
).lss
478 $(REMOVE
) $(SRC
:.c
=.s
)
479 $(REMOVE
) $(SRC
:.c
=.d
)
485 # Include the dependency files.
486 -include $(shell mkdir .dep
2>/dev
/null
) $(wildcard .dep
/*)
489 # Listing of phony targets.
490 .PHONY
: all begin finish end sizebefore sizeafter gccversion \
491 build elf hex eep lss sym coff extcoff \
492 clean clean_list program debug gdb-config