blob: 042c87139070b98dadf77584f27aec660a4ecc6d [file] [log] [blame]
Christina Quastc8ae58b2014-11-28 11:02:16 +01001# ----------------------------------------------------------------------------
2# ATMEL Microcontroller Software Support
3# ----------------------------------------------------------------------------
4# Copyright (c) 2010, Atmel Corporation
5#
6# All rights reserved.
7#
8# Redistribution and use in source and binary forms, with or without
9# modification, are permitted provided that the following conditions are met:
10#
11# - Redistributions of source code must retain the above copyright notice,
12# this list of conditions and the disclaimer below.
13#
14# Atmel's name may not be used to endorse or promote products derived from
15# this software without specific prior written permission.
16#
17# DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
18# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
20# DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
21# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
23# OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27# ----------------------------------------------------------------------------
28
29# Makefile for compiling the Getting Started with SAM3S Microcontrollers project
30
31#-------------------------------------------------------------------------------
32# User-modifiable options
33#-------------------------------------------------------------------------------
34
35# Chip & board used for compilation
36# (can be overriden by adding CHIP=chip and BOARD=board to the command-line)
37CHIP = sam3s2
38BOARD = simtrace
39
40# Defines which are the available memory targets for the SAM3S-EK board.
41MEMORIES = flash
42
43# Trace level used for compilation
44# (can be overriden by adding TRACE_LEVEL=#number to the command-line)
45# TRACE_LEVEL_DEBUG 5
46# TRACE_LEVEL_INFO 4
47# TRACE_LEVEL_WARNING 3
48# TRACE_LEVEL_ERROR 2
49# TRACE_LEVEL_FATAL 1
50# TRACE_LEVEL_NO_TRACE 0
Christina Quast96493612015-01-03 22:22:36 +010051TRACE_LEVEL = 1
Christina Quastc8ae58b2014-11-28 11:02:16 +010052
53# Optimization level, put in comment for debugging
54OPTIMIZATION = -O0
55
56# Output file basename
57OUTPUT = project
58
59# Output directories
60BIN = bin
61OBJ = obj
62
63#-------------------------------------------------------------------------------
64# Tools
65#-------------------------------------------------------------------------------
66
Christina Quast96493612015-01-03 22:22:36 +010067AT91LIB_USB_COMMON_CORE_PATH = atmel_softpack_libraries/usb/common/core
68AT91LIB_USB_CORE_PATH = atmel_softpack_libraries/usb/device/core
69AT91LIB_CCIDDEV_PATH = atmel_softpack_libraries/usb/device/ccid
70
Christina Quastc8ae58b2014-11-28 11:02:16 +010071# Tool suffix when cross-compiling
72CROSS_COMPILE = arm-none-eabi-
73
Christina Quastf1192c62014-12-05 13:03:27 +010074LIBC_PATH=../Baselibc
75
Christina Quastc8ae58b2014-11-28 11:02:16 +010076LIBS = -Wl,--start-group -lgcc -lc -Wl,--end-group
77#LIB_PATH+=-L=/lib/thumb2
78#LIB_PATH+=-L=/../lib/gcc/arm-none-eabi/4.4.1/thumb2
Christina Quast99f9f7b2014-12-13 13:30:31 +010079LIB += -L=$(LIBC_PATH)/include -lc
Christina Quastc8ae58b2014-11-28 11:02:16 +010080
81# Compilation tools
82CC = $(CROSS_COMPILE)gcc
83LD = $(CROSS_COMPILE)ld
84SIZE = $(CROSS_COMPILE)size
85STRIP = $(CROSS_COMPILE)strip
86OBJCOPY = $(CROSS_COMPILE)objcopy
87GDB = $(CROSS_COMPILE)gdb
88NM = $(CROSS_COMPILE)nm
89
90# Flags
Christina Quast96493612015-01-03 22:22:36 +010091INCLUDES_USB = -Iatmel_softpack_libraries/usb/include
92INCLUDES_USB += -I$(AT91LIB_CCIDDEV_PATH)
93
94INCLUDES = -Iinclude_board -Iinclude_sam3s -Iinclude
Christina Quastc8ae58b2014-11-28 11:02:16 +010095INCLUDES += -Icmsis
Christina Quastf1192c62014-12-05 13:03:27 +010096INCLUDES += -I$(LIBC_PATH)/include
Christina Quast96493612015-01-03 22:22:36 +010097INCLUDES += $(INCLUDES_USB)
Christina Quastc8ae58b2014-11-28 11:02:16 +010098#INCLUDES += -I$(LIBRARIES)
99
Christina Quast96493612015-01-03 22:22:36 +0100100CFLAGS += -Wall -Wchar-subscripts -Wcomment -Wimplicit-int #-Wformat=2
Christina Quastc8ae58b2014-11-28 11:02:16 +0100101CFLAGS += -Werror-implicit-function-declaration -Wmain -Wparentheses
Christina Quast96493612015-01-03 22:22:36 +0100102CFLAGS += -Wsequence-point -Wreturn-type -Wswitch -Wtrigraphs #-Wunused
Christina Quastc8ae58b2014-11-28 11:02:16 +0100103CFLAGS += -Wuninitialized -Wunknown-pragmas -Wfloat-equal -Wundef
104CFLAGS += -Wshadow -Wpointer-arith -Wbad-function-cast -Wwrite-strings
105CFLAGS += -Wsign-compare -Waggregate-return
Christina Quast96493612015-01-03 22:22:36 +0100106#CFLAGS += -Wformat
107CFLAGS += -Wmissing-format-attribute -Wno-deprecated-declarations
108#CFLAGS += -Wpacked
109CFLAGS += -Wredundant-decls -Wnested-externs -Winline #-Wlong-long
Christina Quastc8ae58b2014-11-28 11:02:16 +0100110CFLAGS += -Wunreachable-code
111CFLAGS += -Wcast-align
Christina Quast99f9f7b2014-12-13 13:30:31 +0100112CFLAGS += -std=c11
Christina Quastc8ae58b2014-11-28 11:02:16 +0100113#CFLAGS += -Wmissing-noreturn
114#CFLAGS += -Wconversion
115
116# To reduce application size use only integer printf function.
Christina Quast96493612015-01-03 22:22:36 +0100117#CFLAGS += -Dprintf=iprintf
Christina Quastc8ae58b2014-11-28 11:02:16 +0100118
119# -mlong-calls -Wall
120#CFLAGS += -save-temps -fverbose-asm
121#CFLAGS += -Wa,-a,-ad
122CFLAGS += --param max-inline-insns-single=500 -mcpu=cortex-m3 -mthumb # -mfix-cortex-m3-ldrd
123CFLAGS += -ffunction-sections -g $(OPTIMIZATION) $(INCLUDES) -D$(CHIP) -DTRACE_LEVEL=$(TRACE_LEVEL)
124ASFLAGS = -mcpu=cortex-m3 -mthumb -Wall -g $(OPTIMIZATION) $(INCLUDES) -D$(CHIP) -D__ASSEMBLY__
Christina Quastf1192c62014-12-05 13:03:27 +0100125LDFLAGS = -mcpu=cortex-m3 -mthumb -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--entry=ResetException -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align -Wl,--warn-unresolved-symbols $(LIB)
Christina Quastc8ae58b2014-11-28 11:02:16 +0100126#LD_OPTIONAL=-Wl,--print-gc-sections -Wl,--stats
127
128#-------------------------------------------------------------------------------
129# Files
130#-------------------------------------------------------------------------------
131
132# Directories where source files can be found
133
Christina Quast96493612015-01-03 22:22:36 +0100134USB_PATHS = $(AT91LIB_CCIDDEV_PATH) $(AT91LIB_USB_CORE_PATH) $(AT91LIB_USB_COMMON_CORE_PATH)
135VPATH += src_board src_sam3s cmsis $(USB_PATHS)
Christina Quastc8ae58b2014-11-28 11:02:16 +0100136
137# Objects built from C source files
138C_CMSIS = core_cm3.o
139C_LOWLEVEL = board_cstartup_gnu.o board_lowlevel.o syscalls.o exceptions.o
Christina Quast96493612015-01-03 22:22:36 +0100140C_LIBLEVEL = spi.o pio.o pmc.o usart.o pio_it.o pio_capture.o uart_console.o iso7816_4.o wdt.o led.o
141C_CCID = cciddriver.o USBD.o USBDDriver.o USBD_HAL.o USBRequests.o USBDCallbacks.o USBDescriptors.o USBDDriverCallbacks.o
Christina Quastc8ae58b2014-11-28 11:02:16 +0100142C_APPLEVEL = main.o
Christina Quast96493612015-01-03 22:22:36 +0100143C_OBJECTS = $(C_CMSIS) $(C_LOWLEVEL) $(C_LIBLEVEL) $(C_APPLEVEL) $(C_CCID)
Christina Quastc8ae58b2014-11-28 11:02:16 +0100144
145# Append OBJ and BIN directories to output filename
146OUTPUT := $(BIN)/$(OUTPUT)
147
148#-------------------------------------------------------------------------------
149# Rules
150#-------------------------------------------------------------------------------
151
152all: $(BIN) $(OBJ) $(MEMORIES)
153
154$(BIN) $(OBJ):
155 mkdir $@
156
157define RULES
158C_OBJECTS_$(1) = $(addprefix $(OBJ)/$(1)_, $(C_OBJECTS))
159ASM_OBJECTS_$(1) = $(addprefix $(OBJ)/$(1)_, $(ASM_OBJECTS))
160
161$(1): $$(ASM_OBJECTS_$(1)) $$(C_OBJECTS_$(1))
162 @$(CC) $(LDFLAGS) $(LD_OPTIONAL) -T"$$@.ld" -Wl,-Map,$(OUTPUT)-$$@.map -o $(OUTPUT)-$$@.elf $$^ $(LIBS)
163 $(NM) $(OUTPUT)-$$@.elf >$(OUTPUT)-$$@.elf.txt
164 $(OBJCOPY) -O binary $(OUTPUT)-$$@.elf $(OUTPUT)-$$@.bin
165 $(SIZE) $$^ $(OUTPUT)-$$@.elf
166
167$$(C_OBJECTS_$(1)): $(OBJ)/$(1)_%.o: %.c Makefile $(OBJ) $(BIN)
168 @echo [COMPILING $$@]
169 @$(CC) $(CFLAGS) -D$(1) -Wa,-ahlms=$(BIN)/$$*.lst -c -o $$@ $$<
170
171$$(ASM_OBJECTS_$(1)): $(OBJ)/$(1)_%.o: %.S Makefile $(OBJ) $(BIN)
172 @echo [ASSEMBLING $$@]
173 @$(CC) $(ASFLAGS) -D$(1) -c -o $$@ $$<
174
175debug_$(1): $(1)
176 $(GDB) -x "$(BOARD_LIB)/resources/gcc/$(BOARD)_$(1).gdb" -ex "reset" -readnow -se $(OUTPUT)-$(1).elf
177endef
178
179$(foreach MEMORY, $(MEMORIES), $(eval $(call RULES,$(MEMORY))))
180
181program:
Christina Quast8be71e42014-12-02 13:06:01 +0100182 openocd -f /home/chrysh/ba_thesis/thesis/openocd/openocd.cfg -c "init" -c "halt" -c "flash write_bank 0 ./bin/project-flash.bin 0" -c "reset" -c "shutdown"
Christina Quastc8ae58b2014-11-28 11:02:16 +0100183
184clean:
185 -rm -fR $(OBJ)/*.o $(BIN)/*.bin $(BIN)/*.elf $(BIN)/*.elf.txt $(BIN)/*.map $(BIN)/*.lst
186
187rmbak:
188 -rm *~ $(BIN)/*~