Christina Quast | c8ae58b | 2014-11-28 11:02:16 +0100 | [diff] [blame] | 1 | # ---------------------------------------------------------------------------- |
| 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 Welte | d8a003d | 2017-02-27 20:31:09 +0100 | [diff] [blame] | 37 | CHIP ?= sam3s4 |
| 38 | BOARD ?= qmod |
Christina Quast | c8ae58b | 2014-11-28 11:02:16 +0100 | [diff] [blame] | 39 | |
| 40 | # Defines which are the available memory targets for the SAM3S-EK board. |
Harald Welte | d8a003d | 2017-02-27 20:31:09 +0100 | [diff] [blame] | 41 | MEMORIES ?= flash dfu |
Christina Quast | c8ae58b | 2014-11-28 11:02:16 +0100 | [diff] [blame] | 42 | |
Christina Quast | c8ae58b | 2014-11-28 11:02:16 +0100 | [diff] [blame] | 43 | # Output file basename |
Harald Welte | d09829d | 2017-02-27 22:58:59 +0100 | [diff] [blame] | 44 | APP ?= dfu |
Christina Quast | c8ae58b | 2014-11-28 11:02:16 +0100 | [diff] [blame] | 45 | |
| 46 | # Output directories |
Harald Welte | d8a003d | 2017-02-27 20:31:09 +0100 | [diff] [blame] | 47 | OUTPUT = $(BOARD)-$(APP) |
Christina Quast | c8ae58b | 2014-11-28 11:02:16 +0100 | [diff] [blame] | 48 | BIN = bin |
Harald Welte | d8a003d | 2017-02-27 20:31:09 +0100 | [diff] [blame] | 49 | OBJ = obj/$(BOARD) |
Christina Quast | c8ae58b | 2014-11-28 11:02:16 +0100 | [diff] [blame] | 50 | |
| 51 | #------------------------------------------------------------------------------- |
| 52 | # Tools |
| 53 | #------------------------------------------------------------------------------- |
| 54 | |
Harald Welte | 3f5e3dd | 2017-02-27 13:53:17 +0100 | [diff] [blame] | 55 | AT91LIB = ./atmel_softpack_libraries |
| 56 | |
| 57 | AT91LIB_USB_COMMON_CORE_PATH = $(AT91LIB)/usb/common/core |
| 58 | AT91LIB_USB_CORE_PATH = $(AT91LIB)/usb/device/core |
| 59 | AT91LIB_USB_DFU_PATH = $(AT91LIB)/usb/device/dfu |
Christina Quast | 9649361 | 2015-01-03 22:22:36 +0100 | [diff] [blame] | 60 | |
Christina Quast | c8ae58b | 2014-11-28 11:02:16 +0100 | [diff] [blame] | 61 | # Tool suffix when cross-compiling |
| 62 | CROSS_COMPILE = arm-none-eabi- |
| 63 | |
Harald Welte | d09829d | 2017-02-27 22:58:59 +0100 | [diff] [blame] | 64 | LIBS = -Wl,--start-group -lgcc -Wl,--end-group -nostdlib |
Christina Quast | c8ae58b | 2014-11-28 11:02:16 +0100 | [diff] [blame] | 65 | |
| 66 | # Compilation tools |
| 67 | CC = $(CROSS_COMPILE)gcc |
| 68 | LD = $(CROSS_COMPILE)ld |
| 69 | SIZE = $(CROSS_COMPILE)size |
| 70 | STRIP = $(CROSS_COMPILE)strip |
| 71 | OBJCOPY = $(CROSS_COMPILE)objcopy |
| 72 | GDB = $(CROSS_COMPILE)gdb |
| 73 | NM = $(CROSS_COMPILE)nm |
| 74 | |
Harald Welte | 2315e6b | 2016-03-19 21:37:55 +0100 | [diff] [blame] | 75 | TOP=.. |
| 76 | GIT_VERSION=$(shell $(TOP)/git-version-gen $(TOP)/.tarvers) |
| 77 | |
Harald Welte | d09829d | 2017-02-27 22:58:59 +0100 | [diff] [blame] | 78 | #------------------------------------------------------------------------------- |
| 79 | # Files |
| 80 | #------------------------------------------------------------------------------- |
| 81 | |
| 82 | # Directories where source files can be found |
| 83 | |
| 84 | USB_PATHS = $(AT91LIB_USB_CORE_PATH) $(AT91LIB_USB_DFU_PATH) $(AT91LIB_USB_COMMON_CORE_PATH) |
| 85 | |
| 86 | VPATH += $(USB_PATHS) |
| 87 | VPATH += $(AT91LIB)/libchip_sam3s/source/ $(AT91LIB)/libchip_sam3s/cmsis |
| 88 | VPATH += libboard/common/source libboard/$(BOARD)/source |
| 89 | VPATH += libcommon/source |
Harald Welte | 37b6e41 | 2017-02-27 23:20:38 +0100 | [diff] [blame] | 90 | VPATH += libosmocore/source |
Harald Welte | d09829d | 2017-02-27 22:58:59 +0100 | [diff] [blame] | 91 | VPATH += apps/$(APP) |
| 92 | |
| 93 | # Objects built from C source files |
| 94 | C_OSMOCORE = $(notdir $(wildcard libosmocore/source/*.c)) |
| 95 | C_LIBCHIP = $(notdir $(wildcard $(AT91LIB)/libchip_sam3s/source/*.c) $(wildcard $(AT91LIB)/libchip_sam3s/cmsis/*.c)) |
| 96 | |
| 97 | C_LIBUSB = USBDescriptors.c USBRequests.c USBD.c USBDCallbacks.c USBDDriver.c USBDDriverCallbacks.c |
| 98 | C_LIBUSB_RT = dfu.c dfu_desc.c dfu_runtime.c |
| 99 | C_LIBUSB_DFU = dfu.c dfu_desc.c dfu_driver.c |
| 100 | C_LIBCOMMON = string.c stdio.c fputs.c req_ctx.c ringbuffer.c |
| 101 | |
| 102 | C_BOARD = $(notdir $(wildcard libboard/common/source/*.c)) |
| 103 | C_BOARD += $(notdir $(wildcard libboard/$(BOARD)/source/*.c)) |
| 104 | |
| 105 | C_APPLEVEL = $(notdir $(wildcard apps/$(APP)/*.c)) |
| 106 | |
| 107 | C_FILES = $(C_OSMOCORE) $(C_LIBCHIP) $(C_LIBUSB) $(C_LIBCOMMON) $(C_BOARD) $(C_APPLEVEL) |
| 108 | |
| 109 | -include apps/$(APP)/Makefile |
| 110 | |
| 111 | C_OBJECTS = $(C_FILES:%.c=%.o) |
| 112 | |
| 113 | # Trace level used for compilation |
| 114 | # (can be overriden by adding TRACE_LEVEL=#number to the command-line) |
| 115 | # TRACE_LEVEL_DEBUG 5 |
| 116 | # TRACE_LEVEL_INFO 4 |
| 117 | # TRACE_LEVEL_WARNING 3 |
| 118 | # TRACE_LEVEL_ERROR 2 |
| 119 | # TRACE_LEVEL_FATAL 1 |
| 120 | # TRACE_LEVEL_NO_TRACE 0 |
| 121 | TRACE_LEVEL ?= 4 |
| 122 | |
| 123 | DEBUG_PHONE_SNIFF?=0 |
| 124 | |
| 125 | #CFLAGS+=-DUSB_NO_DEBUG=1 |
| 126 | |
| 127 | # Optimization level, put in comment for debugging |
Harald Welte | edf9c9d | 2017-02-27 23:24:22 +0100 | [diff] [blame] | 128 | OPTIMIZATION ?= -Os |
Harald Welte | d09829d | 2017-02-27 22:58:59 +0100 | [diff] [blame] | 129 | |
| 130 | |
| 131 | |
Christina Quast | c8ae58b | 2014-11-28 11:02:16 +0100 | [diff] [blame] | 132 | # Flags |
Harald Welte | 3f5e3dd | 2017-02-27 13:53:17 +0100 | [diff] [blame] | 133 | INCLUDES_USB = -I$(AT91LIB)/usb/include -I$(AT91LIB) |
Christina Quast | 9649361 | 2015-01-03 22:22:36 +0100 | [diff] [blame] | 134 | |
Harald Welte | 3f5e3dd | 2017-02-27 13:53:17 +0100 | [diff] [blame] | 135 | INCLUDES = $(INCLUDES_USB) |
| 136 | INCLUDES += -I$(AT91LIB)/libchip_sam3s -I$(AT91LIB)/libchip_sam3s/include |
| 137 | INCLUDES += -I$(AT91LIB)/libchip_sam3s/cmsis |
| 138 | INCLUDES += -Ilibboard/common/include -Ilibboard/$(BOARD)/include |
| 139 | INCLUDES += -Ilibcommon/include |
| 140 | INCLUDES += -Ilibosmocore/include |
Harald Welte | 3f5e3dd | 2017-02-27 13:53:17 +0100 | [diff] [blame] | 141 | INCLUDES += -Isrc_simtrace -Iinclude |
Christina Quast | c8ae58b | 2014-11-28 11:02:16 +0100 | [diff] [blame] | 142 | |
Christina Quast | 29c99b9 | 2015-04-07 20:13:44 +0200 | [diff] [blame] | 143 | CFLAGS += -Wall -Wchar-subscripts -Wcomment -Wimplicit-int #-Wformat=2 |
Christina Quast | c8ae58b | 2014-11-28 11:02:16 +0100 | [diff] [blame] | 144 | CFLAGS += -Werror-implicit-function-declaration -Wmain -Wparentheses |
Christina Quast | 9649361 | 2015-01-03 22:22:36 +0100 | [diff] [blame] | 145 | CFLAGS += -Wsequence-point -Wreturn-type -Wswitch -Wtrigraphs #-Wunused |
Christina Quast | c8ae58b | 2014-11-28 11:02:16 +0100 | [diff] [blame] | 146 | CFLAGS += -Wuninitialized -Wunknown-pragmas -Wfloat-equal -Wundef |
| 147 | CFLAGS += -Wshadow -Wpointer-arith -Wbad-function-cast -Wwrite-strings |
| 148 | CFLAGS += -Wsign-compare -Waggregate-return |
Christina Quast | 076396f | 2015-04-06 19:57:53 +0200 | [diff] [blame] | 149 | CFLAGS += -Wformat=0 |
Christina Quast | 9649361 | 2015-01-03 22:22:36 +0100 | [diff] [blame] | 150 | CFLAGS += -Wmissing-format-attribute -Wno-deprecated-declarations |
Christina Quast | 29c99b9 | 2015-04-07 20:13:44 +0200 | [diff] [blame] | 151 | CFLAGS += #-Wpacked |
Christina Quast | 9649361 | 2015-01-03 22:22:36 +0100 | [diff] [blame] | 152 | CFLAGS += -Wredundant-decls -Wnested-externs -Winline #-Wlong-long |
Christina Quast | c8ae58b | 2014-11-28 11:02:16 +0100 | [diff] [blame] | 153 | CFLAGS += -Wunreachable-code |
Harald Welte | 7abdb51 | 2016-03-03 17:48:32 +0100 | [diff] [blame] | 154 | #CFLAGS += -Wcast-align |
Harald Welte | f672e9d | 2016-02-29 14:08:12 +0100 | [diff] [blame] | 155 | #CFLAGS += -std=c11 |
Christina Quast | 87d141e | 2015-01-27 14:56:33 +0100 | [diff] [blame] | 156 | CFLAGS += -Wmissing-noreturn |
| 157 | #CFLAGS += -Wconversion |
Christina Quast | d20f26d | 2015-01-27 14:40:31 +0100 | [diff] [blame] | 158 | CFLAGS += -Wno-unused-but-set-variable -Wno-unused-variable |
Christina Quast | 87d141e | 2015-01-27 14:56:33 +0100 | [diff] [blame] | 159 | CFLAGS += -Wno-suggest-attribute=noreturn |
Christina Quast | c8ae58b | 2014-11-28 11:02:16 +0100 | [diff] [blame] | 160 | |
Christina Quast | c8ae58b | 2014-11-28 11:02:16 +0100 | [diff] [blame] | 161 | # -mlong-calls -Wall |
| 162 | #CFLAGS += -save-temps -fverbose-asm |
| 163 | #CFLAGS += -Wa,-a,-ad |
Harald Welte | 9d3e382 | 2015-11-09 00:50:54 +0100 | [diff] [blame] | 164 | CFLAGS += -D__ARM |
Christina Quast | c8ae58b | 2014-11-28 11:02:16 +0100 | [diff] [blame] | 165 | CFLAGS += --param max-inline-insns-single=500 -mcpu=cortex-m3 -mthumb # -mfix-cortex-m3-ldrd |
Christina Quast | 5c6a299 | 2015-04-11 20:03:14 +0200 | [diff] [blame] | 166 | CFLAGS += -ffunction-sections -g $(OPTIMIZATION) $(INCLUDES) -D$(CHIP) -DTRACE_LEVEL=$(TRACE_LEVEL) -DDEBUG_PHONE_SNIFF=$(DEBUG_PHONE_SNIFF) |
Harald Welte | adbe72a | 2017-03-02 23:16:01 +0100 | [diff] [blame] | 167 | CFLAGS += -DGIT_VERSION=\"$(GIT_VERSION)\" |
| 168 | CFLAGS += -DBOARD=\"$(BOARD)\" -DBOARD_$(BOARD) |
| 169 | CFLAGS += -DAPPLICATION=\"$(APP)\" -DAPPLICATION_$(APP) |
Christina Quast | c8ae58b | 2014-11-28 11:02:16 +0100 | [diff] [blame] | 170 | ASFLAGS = -mcpu=cortex-m3 -mthumb -Wall -g $(OPTIMIZATION) $(INCLUDES) -D$(CHIP) -D__ASSEMBLY__ |
Christina Quast | f1192c6 | 2014-12-05 13:03:27 +0100 | [diff] [blame] | 171 | LDFLAGS = -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 Quast | c8ae58b | 2014-11-28 11:02:16 +0100 | [diff] [blame] | 172 | #LD_OPTIONAL=-Wl,--print-gc-sections -Wl,--stats |
| 173 | |
Christina Quast | c8ae58b | 2014-11-28 11:02:16 +0100 | [diff] [blame] | 174 | |
| 175 | # Append OBJ and BIN directories to output filename |
| 176 | OUTPUT := $(BIN)/$(OUTPUT) |
| 177 | |
| 178 | #------------------------------------------------------------------------------- |
| 179 | # Rules |
| 180 | #------------------------------------------------------------------------------- |
| 181 | |
| 182 | all: $(BIN) $(OBJ) $(MEMORIES) |
| 183 | |
| 184 | $(BIN) $(OBJ): |
| 185 | mkdir $@ |
| 186 | |
| 187 | define RULES |
| 188 | C_OBJECTS_$(1) = $(addprefix $(OBJ)/$(1)_, $(C_OBJECTS)) |
| 189 | ASM_OBJECTS_$(1) = $(addprefix $(OBJ)/$(1)_, $(ASM_OBJECTS)) |
| 190 | |
| 191 | $(1): $$(ASM_OBJECTS_$(1)) $$(C_OBJECTS_$(1)) |
Harald Welte | d8a003d | 2017-02-27 20:31:09 +0100 | [diff] [blame] | 192 | @$(CC) $(LDFLAGS) $(LD_OPTIONAL) -T"libboard/common/resources/$(CHIP)/$$@.ld" -Wl,-Map,$(OUTPUT)-$$@.map -o $(OUTPUT)-$$@.elf $$^ $(LIBS) |
Christina Quast | b6f77d3 | 2015-04-07 20:36:23 +0200 | [diff] [blame] | 193 | @$(NM) $(OUTPUT)-$$@.elf >$(OUTPUT)-$$@.elf.txt |
| 194 | @$(OBJCOPY) -O binary $(OUTPUT)-$$@.elf $(OUTPUT)-$$@.bin |
| 195 | @$(SIZE) $$^ $(OUTPUT)-$$@.elf |
Christina Quast | c8ae58b | 2014-11-28 11:02:16 +0100 | [diff] [blame] | 196 | |
| 197 | $$(C_OBJECTS_$(1)): $(OBJ)/$(1)_%.o: %.c Makefile $(OBJ) $(BIN) |
Christina Quast | b6f77d3 | 2015-04-07 20:36:23 +0200 | [diff] [blame] | 198 | @echo [COMPILING $$<] |
Harald Welte | adbe72a | 2017-03-02 23:16:01 +0100 | [diff] [blame] | 199 | @$(CC) $(CFLAGS) -DENVIRONMENT_$(1) -DENVIRONMENT=\"$(1)\" -Wa,-ahlms=$(BIN)/$$*.lst -c -o $$@ $$< |
Christina Quast | c8ae58b | 2014-11-28 11:02:16 +0100 | [diff] [blame] | 200 | |
| 201 | $$(ASM_OBJECTS_$(1)): $(OBJ)/$(1)_%.o: %.S Makefile $(OBJ) $(BIN) |
| 202 | @echo [ASSEMBLING $$@] |
Harald Welte | adbe72a | 2017-03-02 23:16:01 +0100 | [diff] [blame] | 203 | @$(CC) $(ASFLAGS) -DENVIRONMENT_$(1) -DENVIRONMENT=\"$(1)\" -c -o $$@ $$< |
Christina Quast | c8ae58b | 2014-11-28 11:02:16 +0100 | [diff] [blame] | 204 | |
| 205 | debug_$(1): $(1) |
| 206 | $(GDB) -x "$(BOARD_LIB)/resources/gcc/$(BOARD)_$(1).gdb" -ex "reset" -readnow -se $(OUTPUT)-$(1).elf |
| 207 | endef |
| 208 | |
| 209 | $(foreach MEMORY, $(MEMORIES), $(eval $(call RULES,$(MEMORY)))) |
| 210 | |
| 211 | program: |
Christina Quast | 58c1ae3 | 2015-04-07 18:19:13 +0200 | [diff] [blame] | 212 | openocd -f openocd/openocd.cfg -c "init" -c "halt" -c "flash write_bank 0 ./bin/project-flash.bin 0" -c "reset" -c "shutdown" |
Christina Quast | c8ae58b | 2014-11-28 11:02:16 +0100 | [diff] [blame] | 213 | |
Christina Quast | 55cd873 | 2015-04-08 00:10:50 +0200 | [diff] [blame] | 214 | SERIAL ?= /dev/ttyUSB0 |
| 215 | log: |
| 216 | stty -F $(SERIAL) 115200 |
Christina Quast | c63da3f | 2015-04-13 22:09:50 +0200 | [diff] [blame] | 217 | lsof $(SERIAL) && echo "log is already opened" || ( sed -u "s/\r//" $(SERIAL) | ts ) |
Christina Quast | 55cd873 | 2015-04-08 00:10:50 +0200 | [diff] [blame] | 218 | |
Christina Quast | c8ae58b | 2014-11-28 11:02:16 +0100 | [diff] [blame] | 219 | clean: |
| 220 | -rm -fR $(OBJ)/*.o $(BIN)/*.bin $(BIN)/*.elf $(BIN)/*.elf.txt $(BIN)/*.map $(BIN)/*.lst |