blob: a32ddc6534e175c9e0528dcb45f5aa691682f8e9 [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
Harald Welte7abdb512016-03-03 17:48:32 +010051TRACE_LEVEL = 4
Christina Quast32906bb2015-02-24 11:35:19 +010052#FIXME: Remove this variable
53NOAUTOCALLBACK=no
Christina Quastc8ae58b2014-11-28 11:02:16 +010054
Christina Quast5c6a2992015-04-11 20:03:14 +020055DEBUG_PHONE_SNIFF=0
56
Christina Quastce8fa7e2015-03-13 13:09:51 +010057#CFLAGS+=-DUSB_NO_DEBUG=1
58
Christina Quastc8ae58b2014-11-28 11:02:16 +010059# Optimization level, put in comment for debugging
60OPTIMIZATION = -O0
61
62# Output file basename
63OUTPUT = project
64
65# Output directories
66BIN = bin
67OBJ = obj
68
69#-------------------------------------------------------------------------------
70# Tools
71#-------------------------------------------------------------------------------
72
Christina Quast96493612015-01-03 22:22:36 +010073AT91LIB_USB_COMMON_CORE_PATH = atmel_softpack_libraries/usb/common/core
74AT91LIB_USB_CORE_PATH = atmel_softpack_libraries/usb/device/core
Christina Quast96493612015-01-03 22:22:36 +010075
Christina Quastc8ae58b2014-11-28 11:02:16 +010076# Tool suffix when cross-compiling
77CROSS_COMPILE = arm-none-eabi-
78
79LIBS = -Wl,--start-group -lgcc -lc -Wl,--end-group
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
Harald Welte2315e6b2016-03-19 21:37:55 +010090TOP=..
91GIT_VERSION=$(shell $(TOP)/git-version-gen $(TOP)/.tarvers)
92
Christina Quastc8ae58b2014-11-28 11:02:16 +010093# Flags
Christina Quast96493612015-01-03 22:22:36 +010094INCLUDES_USB = -Iatmel_softpack_libraries/usb/include
Christina Quast96493612015-01-03 22:22:36 +010095
Christina Quaste2dddd52015-04-09 17:07:04 +020096INCLUDES = -Iinclude_board -Iinclude_sam3s -Iinclude -Isrc_simtrace
Harald Welteba0c6882016-02-28 19:32:36 +010097
98# FIXME: This must be made configurable!
99#INCLUDES += -Iinclude_board/simtrace
100INCLUDES += -Iinclude_board/owhw
101
Christina Quastc8ae58b2014-11-28 11:02:16 +0100102INCLUDES += -Icmsis
Christina Quast96493612015-01-03 22:22:36 +0100103INCLUDES += $(INCLUDES_USB)
Christina Quastc8ae58b2014-11-28 11:02:16 +0100104
Christina Quast29c99b92015-04-07 20:13:44 +0200105CFLAGS += -Wall -Wchar-subscripts -Wcomment -Wimplicit-int #-Wformat=2
Christina Quastc8ae58b2014-11-28 11:02:16 +0100106CFLAGS += -Werror-implicit-function-declaration -Wmain -Wparentheses
Christina Quast96493612015-01-03 22:22:36 +0100107CFLAGS += -Wsequence-point -Wreturn-type -Wswitch -Wtrigraphs #-Wunused
Christina Quastc8ae58b2014-11-28 11:02:16 +0100108CFLAGS += -Wuninitialized -Wunknown-pragmas -Wfloat-equal -Wundef
109CFLAGS += -Wshadow -Wpointer-arith -Wbad-function-cast -Wwrite-strings
110CFLAGS += -Wsign-compare -Waggregate-return
Christina Quast076396f2015-04-06 19:57:53 +0200111CFLAGS += -Wformat=0
Christina Quast96493612015-01-03 22:22:36 +0100112CFLAGS += -Wmissing-format-attribute -Wno-deprecated-declarations
Christina Quast29c99b92015-04-07 20:13:44 +0200113CFLAGS += #-Wpacked
Christina Quast96493612015-01-03 22:22:36 +0100114CFLAGS += -Wredundant-decls -Wnested-externs -Winline #-Wlong-long
Christina Quastc8ae58b2014-11-28 11:02:16 +0100115CFLAGS += -Wunreachable-code
Harald Welte7abdb512016-03-03 17:48:32 +0100116#CFLAGS += -Wcast-align
Harald Weltef672e9d2016-02-29 14:08:12 +0100117#CFLAGS += -std=c11
Christina Quast87d141e2015-01-27 14:56:33 +0100118CFLAGS += -Wmissing-noreturn
119#CFLAGS += -Wconversion
Christina Quastd20f26d2015-01-27 14:40:31 +0100120CFLAGS += -Wno-unused-but-set-variable -Wno-unused-variable
Christina Quast87d141e2015-01-27 14:56:33 +0100121CFLAGS += -Wno-suggest-attribute=noreturn
Christina Quastc8ae58b2014-11-28 11:02:16 +0100122
123# To reduce application size use only integer printf function.
Christina Quast29c99b92015-04-07 20:13:44 +0200124CFLAGS += -Dprintf=iprintf
Christina Quastc8ae58b2014-11-28 11:02:16 +0100125
126# -mlong-calls -Wall
127#CFLAGS += -save-temps -fverbose-asm
128#CFLAGS += -Wa,-a,-ad
Harald Welte9d3e3822015-11-09 00:50:54 +0100129CFLAGS += -D__ARM
Christina Quastc8ae58b2014-11-28 11:02:16 +0100130CFLAGS += --param max-inline-insns-single=500 -mcpu=cortex-m3 -mthumb # -mfix-cortex-m3-ldrd
Christina Quast5c6a2992015-04-11 20:03:14 +0200131CFLAGS += -ffunction-sections -g $(OPTIMIZATION) $(INCLUDES) -D$(CHIP) -DTRACE_LEVEL=$(TRACE_LEVEL) -DDEBUG_PHONE_SNIFF=$(DEBUG_PHONE_SNIFF)
Harald Welte2315e6b2016-03-19 21:37:55 +0100132CFLAGS += -DGIT_VERSION=\"$(GIT_VERSION)\"
Christina Quastc8ae58b2014-11-28 11:02:16 +0100133ASFLAGS = -mcpu=cortex-m3 -mthumb -Wall -g $(OPTIMIZATION) $(INCLUDES) -D$(CHIP) -D__ASSEMBLY__
Christina Quastf1192c62014-12-05 13:03:27 +0100134LDFLAGS = -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 +0100135#LD_OPTIONAL=-Wl,--print-gc-sections -Wl,--stats
136
137#-------------------------------------------------------------------------------
138# Files
139#-------------------------------------------------------------------------------
140
141# Directories where source files can be found
142
Christina Quast6838fb62015-03-10 15:25:51 +0100143USB_PATHS = $(AT91LIB_USB_CORE_PATH) $(AT91LIB_USB_COMMON_CORE_PATH)
Christina Quaste2dddd52015-04-09 17:07:04 +0200144VPATH += src_board src_sam3s cmsis $(USB_PATHS) src_simtrace
Christina Quastc8ae58b2014-11-28 11:02:16 +0100145
146# Objects built from C source files
147C_CMSIS = core_cm3.o
148C_LOWLEVEL = board_cstartup_gnu.o board_lowlevel.o syscalls.o exceptions.o
Harald Welte8ee15db2016-03-20 16:00:39 +0100149C_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 tc.o unique_id.o
Christina Quast96493612015-01-03 22:22:36 +0100150C_CCID = cciddriver.o USBD.o USBDDriver.o USBD_HAL.o USBRequests.o USBDCallbacks.o USBDescriptors.o USBDDriverCallbacks.o
Harald Welte2a6d3af2016-02-28 19:29:14 +0100151C_SIMTRACE = simtrace_iso7816.o usb.o ccid.o sniffer.o mitm.o ringbuffer.o host_communication.o iso7816_fidi.o tc_etu.o req_ctx.o card_emu.o mode_cardemu.o
Christina Quastc8ae58b2014-11-28 11:02:16 +0100152C_APPLEVEL = main.o
Christina Quastf5462b42015-02-25 18:47:45 +0100153C_OBJECTS = $(C_CMSIS) $(C_LOWLEVEL) $(C_LIBLEVEL) $(C_APPLEVEL) $(C_CCID) $(C_SIMTRACE)
Christina Quastc8ae58b2014-11-28 11:02:16 +0100154
155# Append OBJ and BIN directories to output filename
156OUTPUT := $(BIN)/$(OUTPUT)
157
158#-------------------------------------------------------------------------------
159# Rules
160#-------------------------------------------------------------------------------
161
162all: $(BIN) $(OBJ) $(MEMORIES)
163
164$(BIN) $(OBJ):
165 mkdir $@
166
167define RULES
168C_OBJECTS_$(1) = $(addprefix $(OBJ)/$(1)_, $(C_OBJECTS))
169ASM_OBJECTS_$(1) = $(addprefix $(OBJ)/$(1)_, $(ASM_OBJECTS))
170
171$(1): $$(ASM_OBJECTS_$(1)) $$(C_OBJECTS_$(1))
172 @$(CC) $(LDFLAGS) $(LD_OPTIONAL) -T"$$@.ld" -Wl,-Map,$(OUTPUT)-$$@.map -o $(OUTPUT)-$$@.elf $$^ $(LIBS)
Christina Quastb6f77d32015-04-07 20:36:23 +0200173 @$(NM) $(OUTPUT)-$$@.elf >$(OUTPUT)-$$@.elf.txt
174 @$(OBJCOPY) -O binary $(OUTPUT)-$$@.elf $(OUTPUT)-$$@.bin
175 @$(SIZE) $$^ $(OUTPUT)-$$@.elf
Christina Quastc8ae58b2014-11-28 11:02:16 +0100176
177$$(C_OBJECTS_$(1)): $(OBJ)/$(1)_%.o: %.c Makefile $(OBJ) $(BIN)
Christina Quastb6f77d32015-04-07 20:36:23 +0200178 @echo [COMPILING $$<]
179 @$(CC) $(CFLAGS) -D$(1) -Wa,-ahlms=$(BIN)/$$*.lst -c -o $$@ $$<
Christina Quastc8ae58b2014-11-28 11:02:16 +0100180
181$$(ASM_OBJECTS_$(1)): $(OBJ)/$(1)_%.o: %.S Makefile $(OBJ) $(BIN)
182 @echo [ASSEMBLING $$@]
183 @$(CC) $(ASFLAGS) -D$(1) -c -o $$@ $$<
184
185debug_$(1): $(1)
186 $(GDB) -x "$(BOARD_LIB)/resources/gcc/$(BOARD)_$(1).gdb" -ex "reset" -readnow -se $(OUTPUT)-$(1).elf
187endef
188
189$(foreach MEMORY, $(MEMORIES), $(eval $(call RULES,$(MEMORY))))
190
191program:
Christina Quast58c1ae32015-04-07 18:19:13 +0200192 openocd -f 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 +0100193
Christina Quast55cd8732015-04-08 00:10:50 +0200194SERIAL ?= /dev/ttyUSB0
195log:
196 stty -F $(SERIAL) 115200
Christina Quastc63da3f2015-04-13 22:09:50 +0200197 lsof $(SERIAL) && echo "log is already opened" || ( sed -u "s/\r//" $(SERIAL) | ts )
Christina Quast55cd8732015-04-08 00:10:50 +0200198
Christina Quastc8ae58b2014-11-28 11:02:16 +0100199clean:
200 -rm -fR $(OBJ)/*.o $(BIN)/*.bin $(BIN)/*.elf $(BIN)/*.elf.txt $(BIN)/*.map $(BIN)/*.lst
201
202rmbak:
203 -rm *~ $(BIN)/*~