blob: 703c456d565b17d6fb8c93bba3cbc60f03a42780 [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)
Harald Welted8a003d2017-02-27 20:31:09 +010037CHIP ?= sam3s4
38BOARD ?= qmod
Christina Quastc8ae58b2014-11-28 11:02:16 +010039
40# Defines which are the available memory targets for the SAM3S-EK board.
Harald Welted8a003d2017-02-27 20:31:09 +010041MEMORIES ?= flash dfu
Christina Quastc8ae58b2014-11-28 11:02:16 +010042
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 Welted8a003d2017-02-27 20:31:09 +010051TRACE_LEVEL ?= 4
Christina Quastc8ae58b2014-11-28 11:02:16 +010052
Christina Quast5c6a2992015-04-11 20:03:14 +020053DEBUG_PHONE_SNIFF=0
54
Christina Quastce8fa7e2015-03-13 13:09:51 +010055#CFLAGS+=-DUSB_NO_DEBUG=1
56
Christina Quastc8ae58b2014-11-28 11:02:16 +010057# Optimization level, put in comment for debugging
58OPTIMIZATION = -O0
59
60# Output file basename
Harald Welted8a003d2017-02-27 20:31:09 +010061APP = dfu
Christina Quastc8ae58b2014-11-28 11:02:16 +010062
63# Output directories
Harald Welted8a003d2017-02-27 20:31:09 +010064OUTPUT = $(BOARD)-$(APP)
Christina Quastc8ae58b2014-11-28 11:02:16 +010065BIN = bin
Harald Welted8a003d2017-02-27 20:31:09 +010066OBJ = obj/$(BOARD)
Christina Quastc8ae58b2014-11-28 11:02:16 +010067
68#-------------------------------------------------------------------------------
69# Tools
70#-------------------------------------------------------------------------------
71
Harald Welte3f5e3dd2017-02-27 13:53:17 +010072AT91LIB = ./atmel_softpack_libraries
73
74AT91LIB_USB_COMMON_CORE_PATH = $(AT91LIB)/usb/common/core
75AT91LIB_USB_CORE_PATH = $(AT91LIB)/usb/device/core
76AT91LIB_USB_DFU_PATH = $(AT91LIB)/usb/device/dfu
Christina Quast96493612015-01-03 22:22:36 +010077
Christina Quastc8ae58b2014-11-28 11:02:16 +010078# Tool suffix when cross-compiling
79CROSS_COMPILE = arm-none-eabi-
80
81LIBS = -Wl,--start-group -lgcc -lc -Wl,--end-group
Christina Quastc8ae58b2014-11-28 11:02:16 +010082
83# Compilation tools
84CC = $(CROSS_COMPILE)gcc
85LD = $(CROSS_COMPILE)ld
86SIZE = $(CROSS_COMPILE)size
87STRIP = $(CROSS_COMPILE)strip
88OBJCOPY = $(CROSS_COMPILE)objcopy
89GDB = $(CROSS_COMPILE)gdb
90NM = $(CROSS_COMPILE)nm
91
Harald Welte2315e6b2016-03-19 21:37:55 +010092TOP=..
93GIT_VERSION=$(shell $(TOP)/git-version-gen $(TOP)/.tarvers)
94
Christina Quastc8ae58b2014-11-28 11:02:16 +010095# Flags
Harald Welte3f5e3dd2017-02-27 13:53:17 +010096INCLUDES_USB = -I$(AT91LIB)/usb/include -I$(AT91LIB)
Christina Quast96493612015-01-03 22:22:36 +010097
Harald Welte3f5e3dd2017-02-27 13:53:17 +010098INCLUDES = $(INCLUDES_USB)
99INCLUDES += -I$(AT91LIB)/libchip_sam3s -I$(AT91LIB)/libchip_sam3s/include
100INCLUDES += -I$(AT91LIB)/libchip_sam3s/cmsis
101INCLUDES += -Ilibboard/common/include -Ilibboard/$(BOARD)/include
102INCLUDES += -Ilibcommon/include
103INCLUDES += -Ilibosmocore/include
104INCLUDES += -Iinclude_board
105INCLUDES += -Isrc_simtrace -Iinclude
Christina Quastc8ae58b2014-11-28 11:02:16 +0100106
Christina Quast29c99b92015-04-07 20:13:44 +0200107CFLAGS += -Wall -Wchar-subscripts -Wcomment -Wimplicit-int #-Wformat=2
Christina Quastc8ae58b2014-11-28 11:02:16 +0100108CFLAGS += -Werror-implicit-function-declaration -Wmain -Wparentheses
Christina Quast96493612015-01-03 22:22:36 +0100109CFLAGS += -Wsequence-point -Wreturn-type -Wswitch -Wtrigraphs #-Wunused
Christina Quastc8ae58b2014-11-28 11:02:16 +0100110CFLAGS += -Wuninitialized -Wunknown-pragmas -Wfloat-equal -Wundef
111CFLAGS += -Wshadow -Wpointer-arith -Wbad-function-cast -Wwrite-strings
112CFLAGS += -Wsign-compare -Waggregate-return
Christina Quast076396f2015-04-06 19:57:53 +0200113CFLAGS += -Wformat=0
Christina Quast96493612015-01-03 22:22:36 +0100114CFLAGS += -Wmissing-format-attribute -Wno-deprecated-declarations
Christina Quast29c99b92015-04-07 20:13:44 +0200115CFLAGS += #-Wpacked
Christina Quast96493612015-01-03 22:22:36 +0100116CFLAGS += -Wredundant-decls -Wnested-externs -Winline #-Wlong-long
Christina Quastc8ae58b2014-11-28 11:02:16 +0100117CFLAGS += -Wunreachable-code
Harald Welte7abdb512016-03-03 17:48:32 +0100118#CFLAGS += -Wcast-align
Harald Weltef672e9d2016-02-29 14:08:12 +0100119#CFLAGS += -std=c11
Christina Quast87d141e2015-01-27 14:56:33 +0100120CFLAGS += -Wmissing-noreturn
121#CFLAGS += -Wconversion
Christina Quastd20f26d2015-01-27 14:40:31 +0100122CFLAGS += -Wno-unused-but-set-variable -Wno-unused-variable
Christina Quast87d141e2015-01-27 14:56:33 +0100123CFLAGS += -Wno-suggest-attribute=noreturn
Christina Quastc8ae58b2014-11-28 11:02:16 +0100124
125# To reduce application size use only integer printf function.
Christina Quast29c99b92015-04-07 20:13:44 +0200126CFLAGS += -Dprintf=iprintf
Christina Quastc8ae58b2014-11-28 11:02:16 +0100127
128# -mlong-calls -Wall
129#CFLAGS += -save-temps -fverbose-asm
130#CFLAGS += -Wa,-a,-ad
Harald Welte9d3e3822015-11-09 00:50:54 +0100131CFLAGS += -D__ARM
Christina Quastc8ae58b2014-11-28 11:02:16 +0100132CFLAGS += --param max-inline-insns-single=500 -mcpu=cortex-m3 -mthumb # -mfix-cortex-m3-ldrd
Christina Quast5c6a2992015-04-11 20:03:14 +0200133CFLAGS += -ffunction-sections -g $(OPTIMIZATION) $(INCLUDES) -D$(CHIP) -DTRACE_LEVEL=$(TRACE_LEVEL) -DDEBUG_PHONE_SNIFF=$(DEBUG_PHONE_SNIFF)
Harald Welted8a003d2017-02-27 20:31:09 +0100134CFLAGS += -DGIT_VERSION=\"$(GIT_VERSION)\" -DBOARD=\"$(BOARD)\" -DAPPLICATION=\"$(APP)\"
Christina Quastc8ae58b2014-11-28 11:02:16 +0100135ASFLAGS = -mcpu=cortex-m3 -mthumb -Wall -g $(OPTIMIZATION) $(INCLUDES) -D$(CHIP) -D__ASSEMBLY__
Christina Quastf1192c62014-12-05 13:03:27 +0100136LDFLAGS = -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 +0100137#LD_OPTIONAL=-Wl,--print-gc-sections -Wl,--stats
138
139#-------------------------------------------------------------------------------
140# Files
141#-------------------------------------------------------------------------------
142
143# Directories where source files can be found
144
Harald Welte7ed6f3b2017-02-26 17:00:43 +0100145USB_PATHS = $(AT91LIB_USB_CORE_PATH) $(AT91LIB_USB_DFU_PATH) $(AT91LIB_USB_COMMON_CORE_PATH)
Harald Welte3f5e3dd2017-02-27 13:53:17 +0100146
147VPATH += $(USB_PATHS)
148VPATH += $(AT91LIB)/libchip_sam3s/source/ $(AT91LIB)/libchip_sam3s/cmsis
149VPATH += libboard/common/source libboard/$(BOARD)/source
150VPATH += libcommon/source
151VPATH += libosmocore/source src_board src_simtrace
Harald Welted8a003d2017-02-27 20:31:09 +0100152VPATH += apps/$(APP)
Christina Quastc8ae58b2014-11-28 11:02:16 +0100153
154# Objects built from C source files
Harald Welted8a003d2017-02-27 20:31:09 +0100155C_OSMOCORE = $(notdir $(wildcard libosmocore/source/*.c))
156C_LIBCHIP = $(notdir $(wildcard $(AT91LIB)/libchip_sam3s/source/*.c) $(wildcard $(AT91LIB)/libchip_sam3s/cmsis/*.c))
157
158C_LIBUSB = USBDescriptors.c USBRequests.c USBD.c USBDCallbacks.c USBDDriver.c USBDDriverCallbacks.c
159C_LIBUSB_RT = dfu.c dfu_desc.c dfu_runtime.c
160C_LIBUSB_DFU = dfu.c dfu_desc.c dfu_driver.c
161C_LIBCOMMON = syscalls.c req_ctx.c ringbuffer.c
162
163C_BOARD = $(notdir $(wildcard libboard/common/source/*.c))
164C_BOARD += $(notdir $(wildcard libboard/$(BOARD)/source/*.c))
165
166C_APPLEVEL = $(notdir $(wildcard apps/$(APP)/*.c))
167
168C_FILES = $(C_OSMOCORE) $(C_LIBCHIP) $(C_LIBUSB) $(C_LIBCOMMON) $(C_BOARD) $(C_APPLEVEL)
169
170-include apps/$(APP)/Makefile
171
172C_OBJECTS = $(C_FILES:%.c=%.o)
Christina Quastc8ae58b2014-11-28 11:02:16 +0100173
174# Append OBJ and BIN directories to output filename
175OUTPUT := $(BIN)/$(OUTPUT)
176
177#-------------------------------------------------------------------------------
178# Rules
179#-------------------------------------------------------------------------------
180
181all: $(BIN) $(OBJ) $(MEMORIES)
182
183$(BIN) $(OBJ):
184 mkdir $@
185
186define RULES
187C_OBJECTS_$(1) = $(addprefix $(OBJ)/$(1)_, $(C_OBJECTS))
188ASM_OBJECTS_$(1) = $(addprefix $(OBJ)/$(1)_, $(ASM_OBJECTS))
189
190$(1): $$(ASM_OBJECTS_$(1)) $$(C_OBJECTS_$(1))
Harald Welted8a003d2017-02-27 20:31:09 +0100191 @$(CC) $(LDFLAGS) $(LD_OPTIONAL) -T"libboard/common/resources/$(CHIP)/$$@.ld" -Wl,-Map,$(OUTPUT)-$$@.map -o $(OUTPUT)-$$@.elf $$^ $(LIBS)
Christina Quastb6f77d32015-04-07 20:36:23 +0200192 @$(NM) $(OUTPUT)-$$@.elf >$(OUTPUT)-$$@.elf.txt
193 @$(OBJCOPY) -O binary $(OUTPUT)-$$@.elf $(OUTPUT)-$$@.bin
194 @$(SIZE) $$^ $(OUTPUT)-$$@.elf
Christina Quastc8ae58b2014-11-28 11:02:16 +0100195
196$$(C_OBJECTS_$(1)): $(OBJ)/$(1)_%.o: %.c Makefile $(OBJ) $(BIN)
Christina Quastb6f77d32015-04-07 20:36:23 +0200197 @echo [COMPILING $$<]
Harald Welted8a003d2017-02-27 20:31:09 +0100198 @$(CC) $(CFLAGS) -D$(1) -DENVIRONMENT=\"$(1)\" -Wa,-ahlms=$(BIN)/$$*.lst -c -o $$@ $$<
Christina Quastc8ae58b2014-11-28 11:02:16 +0100199
200$$(ASM_OBJECTS_$(1)): $(OBJ)/$(1)_%.o: %.S Makefile $(OBJ) $(BIN)
201 @echo [ASSEMBLING $$@]
Harald Welted8a003d2017-02-27 20:31:09 +0100202 @$(CC) $(ASFLAGS) -D$(1) -DENVIRONMENT=\"$(1)\" -c -o $$@ $$<
Christina Quastc8ae58b2014-11-28 11:02:16 +0100203
204debug_$(1): $(1)
205 $(GDB) -x "$(BOARD_LIB)/resources/gcc/$(BOARD)_$(1).gdb" -ex "reset" -readnow -se $(OUTPUT)-$(1).elf
206endef
207
208$(foreach MEMORY, $(MEMORIES), $(eval $(call RULES,$(MEMORY))))
209
210program:
Christina Quast58c1ae32015-04-07 18:19:13 +0200211 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 +0100212
Christina Quast55cd8732015-04-08 00:10:50 +0200213SERIAL ?= /dev/ttyUSB0
214log:
215 stty -F $(SERIAL) 115200
Christina Quastc63da3f2015-04-13 22:09:50 +0200216 lsof $(SERIAL) && echo "log is already opened" || ( sed -u "s/\r//" $(SERIAL) | ts )
Christina Quast55cd8732015-04-08 00:10:50 +0200217
Christina Quastc8ae58b2014-11-28 11:02:16 +0100218clean:
219 -rm -fR $(OBJ)/*.o $(BIN)/*.bin $(BIN)/*.elf $(BIN)/*.elf.txt $(BIN)/*.map $(BIN)/*.lst