5353
5454ifndef CORE_VER
5555 CORE_VER := $(wildcard $(ARDUINO_PACKAGE_DIR ) /$(ARDMK_VENDOR ) /hardware/$(ARCHITECTURE ) /1.* )
56- ifdef CORE_VER
56+ ifneq ($( CORE_VER),)
5757 CORE_VER := $(shell basename $(CORE_VER ) )
5858 $(call show_config_variable,CORE_VER,[AUTODETECTED],(from ARDUINO_PACKAGE_DIR))
5959 endif
6262endif
6363
6464ifndef CMSIS_VER
65- CMSIS_VER := $(shell basename $(wildcard $(ARDUINO_PACKAGE_DIR ) /$(ARDMK_VENDOR ) /tools/CMSIS/4.* ) )
66- $(call show_config_variable,CMSIS_VER,[AUTODETECTED],(from ARDUINO_PACKAGE_DIR))
65+ CMSIS_VER := $(wildcard $(ARDUINO_PACKAGE_DIR ) /$(ARDMK_VENDOR ) /tools/CMSIS/4.* )
66+ ifneq ($(CMSIS_VER),)
67+ CMSIS_VER := $(shell basename $(CMSIS_VER ) )
68+ $(call show_config_variable,CMSIS_VER,[AUTODETECTED],(from ARDUINO_PACKAGE_DIR))
69+ endif
6770else
6871 $(call show_config_variable,CMSIS_VER,[USER])
6972endif
7073
7174ifndef CMSIS_ATMEL_VER
72- CMSIS_ATMEL_VER := $(shell basename $(wildcard $(ARDUINO_PACKAGE_DIR ) /$(ARDMK_VENDOR ) /tools/CMSIS-Atmel/1.* ) )
73- $(call show_config_variable,CMSIS_ATMEL_VER,[AUTODETECTED],(from ARDUINO_PACKAGE_DIR))
75+ CMSIS_ATMEL_VER := $(wildcard $(ARDUINO_PACKAGE_DIR ) /$(ARDMK_VENDOR ) /tools/CMSIS-Atmel/1.* )
76+ ifneq ($(CMSIS_ATMEL_VER),)
77+ CMSIS_ATMEL_VER := $(shell basename $(CMSIS_ATMEL_VER ) )
78+ $(call show_config_variable,CMSIS_ATMEL_VER,[AUTODETECTED],(from ARDUINO_PACKAGE_DIR))
79+ endif
7480else
7581 $(call show_config_variable,CMSIS_ATMEL_VER,[USER])
7682endif
7783
7884ifndef CMSIS_DIR
79- CMSIS_DIR := $(ARDUINO_PACKAGE_DIR ) /$(ARDMK_VENDOR ) /tools/CMSIS/$(CMSIS_VER ) /CMSIS
85+ ifeq ($(findstring samd, $(strip $(ARCHITECTURE))), samd)
86+ CMSIS_DIR := $(ARDUINO_PACKAGE_DIR ) /$(ARDMK_VENDOR ) /tools/CMSIS/$(CMSIS_VER ) /CMSIS
87+ else
88+ CMSIS_DIR = $(ALTERNATE_CORE_PATH ) /system/CMSIS/CMSIS
89+ endif
8090 $(call show_config_variable,CMSIS_DIR,[AUTODETECTED],(from ARDUINO_PACKAGE_DIR))
8191else
8292 $(call show_config_variable,CMSIS_DIR,[USER])
8393endif
8494
8595ifndef CMSIS_ATMEL_DIR
86- CMSIS_ATMEL_DIR := $(ARDUINO_PACKAGE_DIR ) /$(ARDMK_VENDOR ) /tools/CMSIS-Atmel/$(CMSIS_ATMEL_VER ) /CMSIS
96+ ifeq ($(findstring samd, $(strip $(ARCHITECTURE))), samd)
97+ CMSIS_ATMEL_DIR := $(ARDUINO_PACKAGE_DIR ) /$(ARDMK_VENDOR ) /tools/CMSIS-Atmel/$(CMSIS_ATMEL_VER ) /CMSIS
98+ else
99+ CMSIS_ATMEL_DIR = $(ALTERNATE_CORE_PATH ) /system/CMSIS
100+ endif
87101 $(call show_config_variable,CMSIS_ATMEL_DIR,[AUTODETECTED],(from ARDUINO_PACKAGE_DIR))
88102else
89103 $(call show_config_variable,CMSIS_ATMEL_DIR,[USER])
@@ -129,9 +143,27 @@ ifndef VARIANT
129143endif
130144
131145# grab any sources in the variant core path (variant.cpp defines pin/port mapping on SAM devices)
132- ALT_CORE_C_SRCS := $(wildcard $(ALTERNATE_CORE_PATH ) /variants/$(VARIANT ) /* .c)
133- ALT_CORE_CPP_SRCS := $(wildcard $(ALTERNATE_CORE_PATH ) /variants/$(VARIANT ) /* .cpp)
134- ALT_CORE_S_SRCS := $(wildcard $(ALTERNATE_CORE_PATH ) /variants/$(VARIANT ) /* .S)
146+ ifndef SAM_CORE_PATH
147+ SAM_CORE_PATH := $(ALTERNATE_CORE_PATH ) /variants/$(VARIANT )
148+ endif
149+ SAM_CORE_C_SRCS := $(wildcard $(SAM_CORE_PATH ) /* .c)
150+ SAM_CORE_CPP_SRCS := $(wildcard $(SAM_CORE_PATH ) /* .cpp)
151+ SAM_CORE_S_SRCS := $(wildcard $(SAM_CORE_PATH ) /* .S)
152+
153+ # due/sam specific paths hard define chip type for SystemInit function in system_CHIP.c as not included in core like samd
154+ ifeq ($(findstring arduino_due, $(strip $(VARIANT ) ) ) , arduino_due)
155+ ifndef SAM_SYSTEM_PATH
156+ SAM_SYSTEM_PATH := $(CMSIS_ATMEL_DIR ) /Device/ATMEL/sam3xa
157+ endif
158+ ifndef SAM_LIBSAM_PATH
159+ SAM_LIBSAM_PATH := $(ALTERNATE_CORE_PATH ) /system/libsam
160+ endif
161+ CPPFLAGS += -I$(SAM_SYSTEM_PATH ) /include
162+ CPPFLAGS += -I$(SAM_LIBSAM_PATH )
163+ CPPFLAGS += -I$(SAM_LIBSAM_PATH ) /include
164+ SAM_CORE_C_SRCS += $(wildcard $(SAM_LIBSAM_PATH ) /source/* .c)
165+ SAM_CORE_C_SRCS += $(wildcard $(SAM_SYSTEM_PATH ) /source/* .c)
166+ endif
135167
136168# Use arm-toolchain from Arduino install if exists and user has not defined global version
137169ifndef ARM_TOOLS_DIR
@@ -160,7 +192,7 @@ ifndef CC_NAME
160192endif
161193
162194ifndef CXX_NAME
163- CXX_NAME := $(call PARSE_BOARD,$(BOARD_TAG ) ,build.command.g+ +)
195+ CXX_NAME := $(call PARSE_BOARD,$(BOARD_TAG ) ,build.command.g\+\ +)
164196 ifndef CXX_NAME
165197 CXX_NAME := arm-none-eabi-g++
166198 else
@@ -330,6 +362,10 @@ endif
330362
331363ifndef BOSSA_OPTS
332364 BOSSA_OPTS += -d --info --erase --write --verify --reset
365+ # Arduino Due forces RS-232 mode and boots from flash
366+ ifeq ($(findstring arduino_due, $(strip $(VARIANT))), arduino_due)
367+ BOSSA_OPTS += -U false -b
368+ endif
333369endif
334370
335371get_bootloader = $(shell $(RESET_CMD ) | tail -1)
@@ -340,7 +376,7 @@ ifndef ISP_PORT
340376 ifeq ($(CURRENT_OS), WINDOWS)
341377 BOSSA_OPTS += --port=$(COM_STYLE_MONITOR_PORT )
342378 else
343- BOSSA_OPTS += --port=$(call get_monitor_port)
379+ BOSSA_OPTS += --port=$(notdir $( call get_monitor_port) )
344380 endif
345381else
346382 BOSSA_OPTS += --port=$(ISP_PORT )
@@ -460,11 +496,20 @@ CXXFLAGS += -fno-rtti -fno-threadsafe-statics -std=gnu++11
460496AMCU := $(call PARSE_BOARD,$(BOARD_TAG ) ,build.mcu)
461497BOARD_LINKER_SCRIPT := $(call PARSE_BOARD,$(BOARD_TAG ) ,build.ldscript)
462498OPENOCD_SCRIPT := $(call PARSE_BOARD,$(BOARD_TAG ) ,build.openocdscript)
463- # TODO Hard defines Cortex M0 math lib - should be dynamic
464- LDFLAGS += --specs=nano.specs --specs=nosys.specs -mthumb -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align -Wl,--start-group -L$(LIB_PATH ) -larm_cortexM0l_math -lm
465499LINKER_SCRIPTS := -T$(ALTERNATE_CORE_PATH ) /variants/$(VARIANT ) /$(BOARD_LINKER_SCRIPT )
466500OTHER_LIBS := $(call PARSE_BOARD,$(BOARD_TAG ) ,build.flags.libs)
467501
502+ # Due and SAMD boards have different flags/chip specific libs
503+ ifeq ($(findstring arduino_due, $(strip $(VARIANT ) ) ) , arduino_due)
504+ CPPFLAGS += -Dprintf=iprintf -DARDUINO_SAM_DUE
505+ LDFLAGS += -mthumb -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--entry=Reset_Handler -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align -Wl,--start-group -u _sbrk -u link -u _close -u _fstat -u _isatty -u _lseek -u _read -u _write -u _exit -u kill -u _getpid
506+ LDFLAGS += -L$(LIB_PATH ) -lm # -larm_cortexM3l_math # IDE doesn't include Cortex-M3 math lib on Due for some reason
507+ OTHER_LIBS += $(ALTERNATE_CORE_PATH ) /variants/$(VARIANT ) /libsam_sam3x8e_gcc_rel.a
508+ else
509+ LDFLAGS += --specs=nano.specs --specs=nosys.specs -mthumb -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align -Wl,--start-group
510+ LDFLAGS += -larm_cortexM0l_math -L$(LIB_PATH ) -lm
511+ endif
512+
468513# OpenOCD reset command only for now
469514ifeq ($(strip $(UPLOAD_TOOL ) ) , openocd)
470515 RESET_CMD = $(OPENOCD ) $(OPENOCD_OPTS ) -c "telnet_port disabled; init; targets; reset run; shutdown"
@@ -479,3 +524,5 @@ endif
479524$(call show_separator)
480525$(call arduino_output,Arduino.mk Configuration :)
481526include $(ARDMK_DIR ) /Arduino.mk
527+
528+ print-% : ; @echo $* = $($* )
0 commit comments