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) |
| 37 | CHIP = sam3s2 |
| 38 | BOARD = simtrace |
| 39 | |
| 40 | # Defines which are the available memory targets for the SAM3S-EK board. |
| 41 | MEMORIES = 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 Quast | 32906bb | 2015-02-24 11:35:19 +0100 | [diff] [blame^] | 51 | TRACE_LEVEL = 5 |
| 52 | #FIXME: Remove this variable |
| 53 | NOAUTOCALLBACK=no |
Christina Quast | c8ae58b | 2014-11-28 11:02:16 +0100 | [diff] [blame] | 54 | |
| 55 | # Optimization level, put in comment for debugging |
| 56 | OPTIMIZATION = -O0 |
| 57 | |
| 58 | # Output file basename |
| 59 | OUTPUT = project |
| 60 | |
| 61 | # Output directories |
| 62 | BIN = bin |
| 63 | OBJ = obj |
| 64 | |
| 65 | #------------------------------------------------------------------------------- |
| 66 | # Tools |
| 67 | #------------------------------------------------------------------------------- |
| 68 | |
Christina Quast | 9649361 | 2015-01-03 22:22:36 +0100 | [diff] [blame] | 69 | AT91LIB_USB_COMMON_CORE_PATH = atmel_softpack_libraries/usb/common/core |
| 70 | AT91LIB_USB_CORE_PATH = atmel_softpack_libraries/usb/device/core |
| 71 | AT91LIB_CCIDDEV_PATH = atmel_softpack_libraries/usb/device/ccid |
| 72 | |
Christina Quast | c8ae58b | 2014-11-28 11:02:16 +0100 | [diff] [blame] | 73 | # Tool suffix when cross-compiling |
| 74 | CROSS_COMPILE = arm-none-eabi- |
| 75 | |
Christina Quast | f1192c6 | 2014-12-05 13:03:27 +0100 | [diff] [blame] | 76 | LIBC_PATH=../Baselibc |
| 77 | |
Christina Quast | c8ae58b | 2014-11-28 11:02:16 +0100 | [diff] [blame] | 78 | LIBS = -Wl,--start-group -lgcc -lc -Wl,--end-group |
| 79 | #LIB_PATH+=-L=/lib/thumb2 |
| 80 | #LIB_PATH+=-L=/../lib/gcc/arm-none-eabi/4.4.1/thumb2 |
Christina Quast | 99f9f7b | 2014-12-13 13:30:31 +0100 | [diff] [blame] | 81 | LIB += -L=$(LIBC_PATH)/include -lc |
Christina Quast | c8ae58b | 2014-11-28 11:02:16 +0100 | [diff] [blame] | 82 | |
| 83 | # Compilation tools |
| 84 | CC = $(CROSS_COMPILE)gcc |
| 85 | LD = $(CROSS_COMPILE)ld |
| 86 | SIZE = $(CROSS_COMPILE)size |
| 87 | STRIP = $(CROSS_COMPILE)strip |
| 88 | OBJCOPY = $(CROSS_COMPILE)objcopy |
| 89 | GDB = $(CROSS_COMPILE)gdb |
| 90 | NM = $(CROSS_COMPILE)nm |
| 91 | |
| 92 | # Flags |
Christina Quast | 9649361 | 2015-01-03 22:22:36 +0100 | [diff] [blame] | 93 | INCLUDES_USB = -Iatmel_softpack_libraries/usb/include |
| 94 | INCLUDES_USB += -I$(AT91LIB_CCIDDEV_PATH) |
| 95 | |
Christina Quast | 32906bb | 2015-02-24 11:35:19 +0100 | [diff] [blame^] | 96 | INCLUDES = -Iinclude_board -Iinclude_sam3s -Iinclude -Isimtrace |
Christina Quast | c8ae58b | 2014-11-28 11:02:16 +0100 | [diff] [blame] | 97 | INCLUDES += -Icmsis |
Christina Quast | f1192c6 | 2014-12-05 13:03:27 +0100 | [diff] [blame] | 98 | INCLUDES += -I$(LIBC_PATH)/include |
Christina Quast | 9649361 | 2015-01-03 22:22:36 +0100 | [diff] [blame] | 99 | INCLUDES += $(INCLUDES_USB) |
Christina Quast | c8ae58b | 2014-11-28 11:02:16 +0100 | [diff] [blame] | 100 | #INCLUDES += -I$(LIBRARIES) |
| 101 | |
Christina Quast | 32906bb | 2015-02-24 11:35:19 +0100 | [diff] [blame^] | 102 | CFLAGS += -Wall -Wchar-subscripts -Wcomment -Wimplicit-int #-Wformat=2 |
Christina Quast | c8ae58b | 2014-11-28 11:02:16 +0100 | [diff] [blame] | 103 | CFLAGS += -Werror-implicit-function-declaration -Wmain -Wparentheses |
Christina Quast | 9649361 | 2015-01-03 22:22:36 +0100 | [diff] [blame] | 104 | CFLAGS += -Wsequence-point -Wreturn-type -Wswitch -Wtrigraphs #-Wunused |
Christina Quast | c8ae58b | 2014-11-28 11:02:16 +0100 | [diff] [blame] | 105 | CFLAGS += -Wuninitialized -Wunknown-pragmas -Wfloat-equal -Wundef |
| 106 | CFLAGS += -Wshadow -Wpointer-arith -Wbad-function-cast -Wwrite-strings |
| 107 | CFLAGS += -Wsign-compare -Waggregate-return |
Christina Quast | 87d141e | 2015-01-27 14:56:33 +0100 | [diff] [blame] | 108 | CFLAGS += -Wformat |
Christina Quast | 9649361 | 2015-01-03 22:22:36 +0100 | [diff] [blame] | 109 | CFLAGS += -Wmissing-format-attribute -Wno-deprecated-declarations |
Christina Quast | 87d141e | 2015-01-27 14:56:33 +0100 | [diff] [blame] | 110 | CFLAGS += #-Wpacked |
Christina Quast | 9649361 | 2015-01-03 22:22:36 +0100 | [diff] [blame] | 111 | CFLAGS += -Wredundant-decls -Wnested-externs -Winline #-Wlong-long |
Christina Quast | c8ae58b | 2014-11-28 11:02:16 +0100 | [diff] [blame] | 112 | CFLAGS += -Wunreachable-code |
| 113 | CFLAGS += -Wcast-align |
Christina Quast | 99f9f7b | 2014-12-13 13:30:31 +0100 | [diff] [blame] | 114 | CFLAGS += -std=c11 |
Christina Quast | 87d141e | 2015-01-27 14:56:33 +0100 | [diff] [blame] | 115 | CFLAGS += -Wmissing-noreturn |
| 116 | #CFLAGS += -Wconversion |
Christina Quast | d20f26d | 2015-01-27 14:40:31 +0100 | [diff] [blame] | 117 | # Disable unused variable warnings |
| 118 | CFLAGS += -Wno-unused-but-set-variable -Wno-unused-variable |
Christina Quast | 87d141e | 2015-01-27 14:56:33 +0100 | [diff] [blame] | 119 | CFLAGS += -Wno-suggest-attribute=noreturn |
Christina Quast | c8ae58b | 2014-11-28 11:02:16 +0100 | [diff] [blame] | 120 | |
| 121 | # To reduce application size use only integer printf function. |
Christina Quast | 9649361 | 2015-01-03 22:22:36 +0100 | [diff] [blame] | 122 | #CFLAGS += -Dprintf=iprintf |
Christina Quast | c8ae58b | 2014-11-28 11:02:16 +0100 | [diff] [blame] | 123 | |
| 124 | # -mlong-calls -Wall |
| 125 | #CFLAGS += -save-temps -fverbose-asm |
| 126 | #CFLAGS += -Wa,-a,-ad |
| 127 | CFLAGS += --param max-inline-insns-single=500 -mcpu=cortex-m3 -mthumb # -mfix-cortex-m3-ldrd |
| 128 | CFLAGS += -ffunction-sections -g $(OPTIMIZATION) $(INCLUDES) -D$(CHIP) -DTRACE_LEVEL=$(TRACE_LEVEL) |
| 129 | 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] | 130 | 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] | 131 | #LD_OPTIONAL=-Wl,--print-gc-sections -Wl,--stats |
| 132 | |
| 133 | #------------------------------------------------------------------------------- |
| 134 | # Files |
| 135 | #------------------------------------------------------------------------------- |
| 136 | |
| 137 | # Directories where source files can be found |
| 138 | |
Christina Quast | 9649361 | 2015-01-03 22:22:36 +0100 | [diff] [blame] | 139 | USB_PATHS = $(AT91LIB_CCIDDEV_PATH) $(AT91LIB_USB_CORE_PATH) $(AT91LIB_USB_COMMON_CORE_PATH) |
Christina Quast | 32906bb | 2015-02-24 11:35:19 +0100 | [diff] [blame^] | 140 | VPATH += src_board src_sam3s cmsis $(USB_PATHS) simtrace |
Christina Quast | c8ae58b | 2014-11-28 11:02:16 +0100 | [diff] [blame] | 141 | |
| 142 | # Objects built from C source files |
| 143 | C_CMSIS = core_cm3.o |
| 144 | C_LOWLEVEL = board_cstartup_gnu.o board_lowlevel.o syscalls.o exceptions.o |
Christina Quast | 9649361 | 2015-01-03 22:22:36 +0100 | [diff] [blame] | 145 | C_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 |
| 146 | C_CCID = cciddriver.o USBD.o USBDDriver.o USBD_HAL.o USBRequests.o USBDCallbacks.o USBDescriptors.o USBDDriverCallbacks.o |
Christina Quast | c8ae58b | 2014-11-28 11:02:16 +0100 | [diff] [blame] | 147 | C_APPLEVEL = main.o |
Christina Quast | 9649361 | 2015-01-03 22:22:36 +0100 | [diff] [blame] | 148 | C_OBJECTS = $(C_CMSIS) $(C_LOWLEVEL) $(C_LIBLEVEL) $(C_APPLEVEL) $(C_CCID) |
Christina Quast | c8ae58b | 2014-11-28 11:02:16 +0100 | [diff] [blame] | 149 | |
| 150 | # Append OBJ and BIN directories to output filename |
| 151 | OUTPUT := $(BIN)/$(OUTPUT) |
| 152 | |
| 153 | #------------------------------------------------------------------------------- |
| 154 | # Rules |
| 155 | #------------------------------------------------------------------------------- |
| 156 | |
| 157 | all: $(BIN) $(OBJ) $(MEMORIES) |
| 158 | |
| 159 | $(BIN) $(OBJ): |
| 160 | mkdir $@ |
| 161 | |
| 162 | define RULES |
| 163 | C_OBJECTS_$(1) = $(addprefix $(OBJ)/$(1)_, $(C_OBJECTS)) |
| 164 | ASM_OBJECTS_$(1) = $(addprefix $(OBJ)/$(1)_, $(ASM_OBJECTS)) |
| 165 | |
| 166 | $(1): $$(ASM_OBJECTS_$(1)) $$(C_OBJECTS_$(1)) |
| 167 | @$(CC) $(LDFLAGS) $(LD_OPTIONAL) -T"$$@.ld" -Wl,-Map,$(OUTPUT)-$$@.map -o $(OUTPUT)-$$@.elf $$^ $(LIBS) |
| 168 | $(NM) $(OUTPUT)-$$@.elf >$(OUTPUT)-$$@.elf.txt |
| 169 | $(OBJCOPY) -O binary $(OUTPUT)-$$@.elf $(OUTPUT)-$$@.bin |
| 170 | $(SIZE) $$^ $(OUTPUT)-$$@.elf |
| 171 | |
| 172 | $$(C_OBJECTS_$(1)): $(OBJ)/$(1)_%.o: %.c Makefile $(OBJ) $(BIN) |
| 173 | @echo [COMPILING $$@] |
Christina Quast | d20f26d | 2015-01-27 14:40:31 +0100 | [diff] [blame] | 174 | $(CC) $(CFLAGS) -D$(1) -Wa,-ahlms=$(BIN)/$$*.lst -c -o $$@ $$< |
Christina Quast | c8ae58b | 2014-11-28 11:02:16 +0100 | [diff] [blame] | 175 | |
| 176 | $$(ASM_OBJECTS_$(1)): $(OBJ)/$(1)_%.o: %.S Makefile $(OBJ) $(BIN) |
| 177 | @echo [ASSEMBLING $$@] |
| 178 | @$(CC) $(ASFLAGS) -D$(1) -c -o $$@ $$< |
| 179 | |
| 180 | debug_$(1): $(1) |
| 181 | $(GDB) -x "$(BOARD_LIB)/resources/gcc/$(BOARD)_$(1).gdb" -ex "reset" -readnow -se $(OUTPUT)-$(1).elf |
| 182 | endef |
| 183 | |
| 184 | $(foreach MEMORY, $(MEMORIES), $(eval $(call RULES,$(MEMORY)))) |
| 185 | |
| 186 | program: |
Christina Quast | 8be71e4 | 2014-12-02 13:06:01 +0100 | [diff] [blame] | 187 | 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 Quast | c8ae58b | 2014-11-28 11:02:16 +0100 | [diff] [blame] | 188 | |
| 189 | clean: |
| 190 | -rm -fR $(OBJ)/*.o $(BIN)/*.bin $(BIN)/*.elf $(BIN)/*.elf.txt $(BIN)/*.map $(BIN)/*.lst |
| 191 | |
| 192 | rmbak: |
| 193 | -rm *~ $(BIN)/*~ |