1 # Hey Emacs, this is a -*- makefile -*-
3 # WinARM makefile for the FreeRTOS-demo on LPC2138
4 # based in information from the FreeRTOS LPC2106 example
6 # by Martin Thomas, Kaiserslautern, Germany
7 # <eversmith@heizung-thomas.de>
9 # based on the WinAVR makefile written by Eric B. Weddington, Jörg Wunsch, et al.
10 # Released to the Public Domain
11 # Please read the make user manual!
16 # make all = Make software.
18 # make clean = Clean out built project files.
20 # make program = Download the hex file to the device
22 # (TODO: make filename.s = Just compile filename.c into the assembler code only)
24 # To rebuild project do "make clean" then "make all".
27 # - 17. Feb. 2005 - added thumb-interwork support (mth)
28 # - 28. Apr. 2005 - added C++ support (mth)
29 # - 29. Arp. 2005 - changed handling for lst-Filename (mth)
30 # - 1. Nov. 2005 - exception-vector placement options (mth)
31 # - 15. Nov. 2005 - added library-search-path (EXTRA_LIB...) (mth)
32 # - 2. Dec. 2005 - fixed ihex and binary file extensions (mth)
33 # - 22. Feb. 2006 - added AT91LIBNOWARN setting (mth)
34 # - 19. Apr. 2006 - option FLASH_TOOL (default lpc21isp); variable IMGEXT (mth)
35 # - 19. Mai. 2006 - USE_THUMB_MODE switch, ROM_RUN->RUN_FROM_ROM RAM_RUN->RUN_FROM_RAM
38 FLASH_TOOL = AT91FLASH
42 # MCU name and submodel
50 ## Create ROM-Image (final)
52 ## Create RAM-Image (debugging) - not used in this example
53 #RUN_MODE=RUN_FROM_RAM
55 ## We want to produce a full-flash image, but including DFU
59 PATH_TO_LINKSCRIPTS=link/
61 #### not used in this example:
62 ## Exception-Vector placement only supported for "ROM_RUN"
63 ## (placement settings ignored when using "RAM_RUN")
64 ## - Exception vectors in ROM:
65 #VECTOR_LOCATION=VECTORS_IN_ROM
66 ## - Exception vectors in RAM:
67 #VECTOR_LOCATION=VECTORS_IN_RAM
69 # Target file name (without extension).
72 USBSTRINGS=src/picc/usb_strings_dfu.h src/pcd/usb_strings_dfu.h
74 # List C source files here. (C dependencies are automatically generated.)
75 # use file-extension c for "c-only"-files
78 # List C source files here which must be compiled in ARM-Mode.
79 # use file-extension c for "c-only"-files
81 SRCARM = src/start/Cstartup_SAM7.c lib/lib_AT91SAM7.c \
82 src/dfu/dfu.c src/dfu/dbgu.c src/os/flash.c
84 # List C++ source files here.
85 # use file-extension cpp for C++-files (use extension .cpp)
88 # List C++ source files here which must be compiled in ARM-Mode.
89 # use file-extension cpp for C++-files (use extension .cpp)
90 #CPPSRCARM = $(TARGET).cpp
93 # List Assembler source files here.
94 # Make them always end in a capital .S. Files ending in a lowercase .s
95 # will not be considered source files but generated files (assembler
96 # output from the compiler), and will be deleted upon "make clean"!
97 # Even though the DOS/Win* filesystem matches both .s and .S the same,
98 # it will preserve the spelling of the filenames, and gcc itself does
99 # care about how the name is spelled on its command-line.
102 # List Assembler source files here which must be assembled in ARM-Mode..
103 ASRCARM = src/start/Cstartup.S
106 SRCARM += lib/vsprintf.c lib/ctype.c lib/string.c
107 ASRCARM += lib/div64.S
110 ## Output format. (can be ihex or binary)
111 ## (binary i.e. for openocd and SAM-BA, hex i.e. for lpc21isp and uVision)
115 # Optimization level, can be [0, 1, 2, 3, s].
116 # 0 = turn off optimization. s = optimize for size.
117 # (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
122 # Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
123 # AVR (extended) COFF requires stabs, plus an avr-objcopy run.
127 # List any extra directories to look for include files here.
128 # Each directory must be seperated by a space.
132 # List any extra directories to look for library files here.
133 # Each directory must be seperated by a space.
134 #EXTRA_LIBDIRS = ../arm7_efsl_0_2_4
137 ## Using the Atmel AT91_lib produces warning with
138 ## the default warning-levels.
139 ## yes - disable these warnings; no - keep default settings
143 # Compiler flag to set the C Standard level.
145 # gnu89 - c89 plus GCC extensions
146 # c99 - ISO C99 standard (not yet fully implemented)
147 # gnu99 - c99 plus GCC extensions
148 CSTANDARD = -std=gnu99
150 # Place -D or -U options for C here
151 CDEFS = -D$(RUN_MODE) -D__MS_types__ -D__LIBRFID__
158 ifeq ($(BOARD),OLIMEX)
170 SUBMDL = AT91SAM7S128
176 # Place -I options here
177 CINCS += -Iinclude -Isrc
179 # Place -D or -U options for ASM here
180 ADEFS += -D$(RUN_MODE)
182 ifdef VECTOR_LOCATION
183 CDEFS += -D$(VECTOR_LOCATION)
184 ADEFS += -D$(VECTOR_LOCATION)
187 CDEFS += -D__$(SUBMDL)__
188 ADEFS += -D__$(SUBMDL)__
192 # -g*: generate debugging information
193 # -O*: optimization level
194 # -f...: tuning, see GCC manual and avr-libc documentation
195 # -Wall...: warning level
196 # -Wa,...: tell GCC to pass this to the assembler.
197 # -adhlns...: create assembler listing
199 # Flags for C and C++ (arm-elf-gcc/arm-elf-g++)
200 CFLAGS += -g$(DEBUGF) -DBOARD=$(BOARD)
201 CFLAGS += $(CDEFS) $(CINCS)
203 CFLAGS += -Wall -Wextra -Wcast-align -Wimplicit -Wunused
204 CFLAGS += -Wpointer-arith -Wswitch
205 CFLAGS += -Wredundant-decls -Wreturn-type -Wshadow
206 CFLAGS += -Wbad-function-cast -Wsign-compare -Waggregate-return
207 CFLAGS += -Wa,-adhlns=$(subst $(suffix $<),.lst,$<)
208 CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
209 #CFLAGS += -ffunction-sections -fdata-sections
212 CONLYFLAGS += -Wnested-externs
213 CONLYFLAGS += $(CSTANDARD)
215 ifneq ($(AT91LIBNOWARN),yes)
216 #AT91-lib warnings with:
217 CFLAGS += -Wcast-qual
218 CONLYFLAGS += -Wmissing-prototypes
219 CONLYFLAGS += -Wstrict-prototypes
220 CONLYFLAGS += -Wmissing-declarations
223 # flags only for C++ (arm-elf-g++)
224 # CPPFLAGS = -fno-rtti -fno-exceptions
228 # -Wa,...: tell GCC to pass this to the assembler.
229 # -ahlns: create listing
230 # -g$(DEBUGF): have the assembler create line number information
231 ASFLAGS = $(ADEFS) -Wa,-adhlns=$(<:.S=.lst),--g$(DEBUGF) -Iinclude/ -D__ASSEMBLY__
234 #Additional libraries.
237 # Each library-name must be seperated by a space.
238 # To add libxyz.a, libabc.a and libefsl.a:
239 # EXTRA_LIBS = xyz abc efsl
243 #Support for newlibc-lpc (file: libnewlibc-lpc.a)
244 #NEWLIBLPC = -lnewlib-lpc
248 # CPLUSPLUS_LIB = -lstdc++
252 # -Wl,...: tell GCC to pass this to linker.
253 # -Map: create map file
254 # --cref: add cross reference to map file
255 LDFLAGS = -nostartfiles -Wl,-Map=$(TARGET).map,--cref
256 LDFLAGS += $(NEWLIBLPC) $(MATH_LIB)
258 LDFLAGS += $(CPLUSPLUS_LIB)
259 LDFLAGS += $(patsubst %,-L%,$(EXTRA_LIBDIRS))
260 LDFLAGS += $(patsubst %,-l%,$(EXTRA_LIBS))
261 #LDFLAGS += --gc-sections
263 # Set Linker-Script Depending On Selected Memory and Controller
264 ifeq ($(RUN_MODE),RUN_FROM_RAM)
265 LDFLAGS +=-T$(PATH_TO_LINKSCRIPTS)$(SUBMDL)-RAM.ld
267 LDFLAGS +=-T$(PATH_TO_LINKSCRIPTS)$(SUBMDL)-ROM$(IMGTYPE).ld
271 # ---------------------------------------------------------------------------
272 # Flash-Programming support using lpc21isp by Martin Maurer
273 # only for Philips LPC and Analog ADuC ARMs
275 # Settings and variables:
279 LPC21ISP_BAUD = 38400
280 LPC21ISP_XTAL = 12000
281 LPC21ISP_FLASHFILE = $(TARGET).hex
283 #LPC21ISP_DEBUG = -debug
284 # enter bootloader via RS232 DTR/RTS (only if hardware supports this
285 # feature - see Philips AppNote):
286 LPC21ISP_CONTROL = -control
287 # ---------------------------------------------------------------------------
290 # Define directories, if needed.
291 ## DIRARM = c:/WinARM/
292 ## DIRARMBIN = $(DIRAVR)/bin/
293 ## DIRAVRUTILS = $(DIRAVR)/utils/bin/
295 # Define programs and commands.
299 OBJCOPY = arm-elf-objcopy
300 OBJDUMP = arm-elf-objdump
308 MSG_ERRORS_NONE = Errors: none
309 MSG_BEGIN = "-------- begin (mode: $(RUN_MODE)) --------"
310 MSG_END = -------- end --------
311 MSG_SIZE_BEFORE = Size before:
312 MSG_SIZE_AFTER = Size after:
313 MSG_FLASH = Creating load file for Flash:
314 MSG_EXTENDED_LISTING = Creating Extended Listing:
315 MSG_SYMBOL_TABLE = Creating Symbol Table:
316 MSG_LINKING = Linking:
317 MSG_COMPILING = Compiling C:
318 MSG_COMPILING_ARM = "Compiling C (ARM-only):"
319 MSG_COMPILINGCPP = Compiling C++:
320 MSG_COMPILINGCPP_ARM = "Compiling C++ (ARM-only):"
321 MSG_ASSEMBLING = Assembling:
322 MSG_ASSEMBLING_ARM = "Assembling (ARM-only):"
323 MSG_CLEANING = Cleaning project:
324 MSG_FORMATERROR = Can not handle output-format
325 MSG_LPC21_RESETREMINDER = You may have to bring the target in bootloader-mode now.
327 # Define all object files.
330 COBJARM = $(SRCARM:.c=.o)
331 AOBJARM = $(ASRCARM:.S=.o)
332 CPPOBJ = $(CPPSRC:.cpp=.o)
333 CPPOBJARM = $(CPPSRCARM:.cpp=.o)
335 # Define all listing files.
336 LST = $(ASRC:.S=.lst) $(ASRCARM:.S=.lst) $(SRC:.c=.lst) $(SRCARM:.c=.lst)
337 LST += $(CPPSRC:.cpp=.lst) $(CPPSRCARM:.cpp=.lst)
339 # Compiler flags to generate dependency files.
340 ### GENDEPFLAGS = -Wp,-M,-MP,-MT,$(*F).o,-MF,.dep/$(@F).d
341 GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d
343 # Combine all necessary flags and optional flags.
344 # Add target processor to flags.
345 ALL_CFLAGS = -mcpu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
346 ALL_ASFLAGS = -mcpu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
350 all: begin gccversion sizebefore build sizeafter finished end
352 ifeq ($(FORMAT),ihex)
353 build: elf hex lss sym
357 ifeq ($(FORMAT),binary)
358 build: elf bin lss sym
362 $(error "$(MSG_FORMATERROR) $(FORMAT)")
376 @echo $(MSG_ERRORS_NONE)
383 # Display size of file.
384 HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
385 ELFSIZE = $(SIZE) -A $(TARGET).elf
387 @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi
390 @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
393 # Display compiler version information.
398 # Program the device.
399 # Program the device by using our relais card robot over USB
400 ifeq ($(FLASH_TOOL),AT91FLASH)
401 program: $(TARGET).$(IMGEXT)
402 ls -l $(TARGET).$(IMGEXT)
403 at91flash $(TARGET).$(IMGEXT)
405 ifeq ($(FLASH_TOOL),UVISION)
406 # Program the device with Keil's uVision (needs configured uVision-Workspace).
407 program: $(TARGET).$(IMGEXT)
409 @echo "Programming with uVision"
410 C:\Keil\uv3\Uv3.exe -f uvisionflash.Uv2 -ouvisionflash.txt
412 ifeq ($(FLASH_TOOL),OPENOCD)
413 # Program the device with Dominic Rath's OPENOCD in "batch-mode", needs cfg and "reset-script".
414 program: $(TARGET).$(IMGEXT)
416 @echo "Programming with OPENOCD"
417 C:\WinARM\utils\openocd\openocd_svn59\openocd.exe -f oocd_sam7_flash.cfg
419 # Program the device. - lpc21isp will not work for SAM7
420 program: $(TARGET).$(IMGEXT)
422 @echo $(MSG_LPC21_RESETREMINDER)
423 $(LPC21ISP) $(LPC21ISP_OPTIONS) $(LPC21ISP_DEBUG) $(LPC21ISP_FLASHFILE) $(LPC21ISP_PORT) $(LPC21ISP_BAUD) $(LPC21ISP_XTAL)
429 # Create final output file (.hex) from ELF output file.
432 @echo $(MSG_FLASH) $@
433 $(OBJCOPY) -O $(FORMAT) $< $@
435 # Create final output file (.bin) from ELF output file.
438 @echo $(MSG_FLASH) $@
439 $(OBJCOPY) -O $(FORMAT) $< $@
442 # Create extended listing file from ELF output file.
446 @echo $(MSG_EXTENDED_LISTING) $@
447 $(OBJDUMP) -h -S -C $< > $@
450 # Create a symbol table from ELF output file.
453 @echo $(MSG_SYMBOL_TABLE) $@
457 # Link: create ELF output file from object files.
458 .SECONDARY : $(TARGET).elf
459 .PRECIOUS : $(AOBJARM) $(AOBJ) $(COBJARM) $(COBJ) $(CPPOBJ) $(CPPOBJARM)
460 %.elf: $(AOBJARM) $(AOBJ) $(COBJARM) $(COBJ) $(CPPOBJ) $(CPPOBJARM)
462 @echo $(MSG_LINKING) $@
463 $(CC) $(ALL_CFLAGS) $(AOBJARM) $(AOBJ) $(COBJARM) $(COBJ) $(CPPOBJ) $(CPPOBJARM) --output $@ $(LDFLAGS)
465 # Compile: create object files from C source files. ARM/Thumb
468 @echo $(MSG_COMPILING) $<
469 $(CC) -c $(ALL_CFLAGS) $(CONLYFLAGS) $< -o $@
471 # Compile: create object files from C source files. ARM-only
472 $(COBJARM) : %.o : %.c include/compile.h $(USBSTRINGS)
474 @echo $(MSG_COMPILING_ARM) $<
475 $(CC) -c $(ALL_CFLAGS) $(CONLYFLAGS) $< -o $@
477 # Compile: create object files from C++ source files. ARM/Thumb
478 $(CPPOBJ) : %.o : %.cpp
480 @echo $(MSG_COMPILINGCPP) $<
481 $(CPP) -c $(ALL_CFLAGS) $(CPPFLAGS) $< -o $@
483 # Compile: create object files from C++ source files. ARM-only
484 $(CPPOBJARM) : %.o : %.cpp
486 @echo $(MSG_COMPILINGCPP_ARM) $<
487 $(CPP) -c $(ALL_CFLAGS) $(CPPFLAGS) $< -o $@
490 # Compile: create assembler files from C source files. ARM/Thumb
491 ## does not work - TODO - hints welcome
492 ##$(COBJ) : %.s : %.c
493 ## $(CC) $(THUMB) -S $(ALL_CFLAGS) $< -o $@
496 # Assemble: create object files from assembler source files. ARM/Thumb
499 @echo $(MSG_ASSEMBLING) $<
500 $(CC) -c $(ALL_ASFLAGS) $< -o $@
503 # Assemble: create object files from assembler source files. ARM-only
504 $(AOBJARM) : %.o : %.S
506 @echo $(MSG_ASSEMBLING_ARM) $<
507 $(CC) -c $(ALL_ASFLAGS) $< -o $@
510 # Target: clean project.
511 clean: begin clean_list finished end
516 @echo $(MSG_CLEANING)
517 $(REMOVE) $(TARGET).hex
518 $(REMOVE) $(TARGET).bin
519 $(REMOVE) $(TARGET).obj
520 $(REMOVE) $(TARGET).elf
521 $(REMOVE) $(TARGET).map
522 $(REMOVE) $(TARGET).obj
523 $(REMOVE) $(TARGET).a90
524 $(REMOVE) $(TARGET).sym
525 $(REMOVE) $(TARGET).lnk
526 $(REMOVE) $(TARGET).lss
531 $(REMOVE) $(CPPOBJARM)
534 $(REMOVE) $(SRC:.c=.s)
535 $(REMOVE) $(SRC:.c=.d)
536 $(REMOVE) $(SRCARM:.c=.s)
537 $(REMOVE) $(SRCARM:.c=.d)
538 $(REMOVE) $(CPPSRC:.cpp=.s)
539 $(REMOVE) $(CPPSRC:.cpp=.d)
540 $(REMOVE) $(CPPSRCARM:.cpp=.s)
541 $(REMOVE) $(CPPSRCARM:.cpp=.d)
543 $(REMOVE) src/picc/usb_strings_dfu.h
544 $(REMOVE) src/dfu/usb_strings_dfu.h
545 $(REMOVE) scripts/usbstring
547 .PHONY: include/compile.h
549 scripts/mkcompile_h > $@
552 $(USBSTRINGS): %.h : %.txt ./scripts/usbstring
553 cat $< | ./scripts/usbstring > $@
555 scripts/usbstring: scripts/usbstring.c
559 # Include the dependency files.
560 -include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
563 # Listing of phony targets.
564 .PHONY : all begin finish end sizebefore sizeafter gccversion \
565 build elf hex bin lss sym clean clean_list program