Skip to content

Commit 3f32563

Browse files
committed
Support for Arduino Due added
Update HISTORY.md Add avr core emulation to C sources
1 parent 0809b54 commit 3f32563

File tree

7 files changed

+137
-30
lines changed

7 files changed

+137
-30
lines changed

Arduino.mk

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,7 @@ ifeq ($(strip $(NO_CORE)),)
832832

833833
# USB Core if samd or sam
834834
ifeq ($(findstring sam, $(strip $(ARCHITECTURE))), sam)
835+
CORE_C_SRCS += $(wildcard $(ARDUINO_CORE_PATH)/avr/*.c) # avr core emulation files
835836
CORE_C_SRCS += $(wildcard $(ARDUINO_CORE_PATH)/USB/*.c)
836837
CORE_CPP_SRCS += $(wildcard $(ARDUINO_CORE_PATH)/USB/*.cpp)
837838
endif
@@ -841,11 +842,22 @@ ifeq ($(strip $(NO_CORE)),)
841842
$(call show_config_info,NO_CORE_MAIN_CPP set so core library will not include main.cpp,[MANUAL])
842843
endif
843844

844-
# Put alt core variant file for M0 devices in OTHER_OJBS
845-
ifdef ALT_CORE_CPP_SRCS
846-
ALT_CORE_OBJ_FILES = $(ALT_CORE_C_SRCS:.c=.c.o) $(ALT_CORE_CPP_SRCS:.cpp=.cpp.o) $(ALT_CORE_AS_SRCS:.S=.S.o)
847-
OTHER_OBJS := $(patsubst $(ALTERNATE_CORE_PATH)/variants/$(VARIANT)/%, \
848-
$(OBJDIR)/core/%,$(ALT_CORE_OBJ_FILES))
845+
# Add core files for sam devices in CORE_OJBS filtering specific paths
846+
ifdef SAM_CORE_PATH
847+
SAM_CORE_OBJ_FILES = $(SAM_CORE_C_SRCS:.c=.c.o) $(SAM_CORE_CPP_SRCS:.cpp=.cpp.o) $(SAM_CORE_AS_SRCS:.S=.S.o)
848+
# variant core files
849+
CORE_OBJS += $(patsubst $(SAM_CORE_PATH)/%, \
850+
$(OBJDIR)/core/%, $(filter $(SAM_CORE_PATH)/%, $(SAM_CORE_OBJ_FILES)))
851+
# libsam on Due
852+
ifdef SAM_LIBSAM_PATH
853+
CORE_OBJS += $(patsubst $(SAM_LIBSAM_PATH)/source/%, \
854+
$(OBJDIR)/core/%, $(filter $(SAM_LIBSAM_PATH)/source/%, $(SAM_CORE_OBJ_FILES)))
855+
endif
856+
# chip sources on Due
857+
ifdef SAM_SYSTEM_PATH
858+
CORE_OBJS += $(patsubst $(SAM_SYSTEM_PATH)/source/%, \
859+
$(OBJDIR)/core/%, $(filter $(SAM_SYSTEM_PATH)/source/%, $(SAM_CORE_OBJ_FILES)))
860+
endif
849861
endif
850862

851863
CORE_OBJ_FILES = $(CORE_C_SRCS:.c=.c.o) $(CORE_CPP_SRCS:.cpp=.cpp.o) $(CORE_AS_SRCS:.S=.S.o)
@@ -1324,19 +1336,28 @@ $(OBJDIR)/core/%.S.o: $(ARDUINO_CORE_PATH)/%.S $(COMMON_DEPS) | $(OBJDIR)
13241336
@$(MKDIR) $(dir $@)
13251337
$(CC) -MMD -c $(CPPFLAGS) $(ASFLAGS) $< -o $@
13261338

1327-
# alt core files
1328-
$(OBJDIR)/core/%.c.o: $(ALTERNATE_CORE_PATH)/variants/$(VARIANT)/%.c $(COMMON_DEPS) | $(OBJDIR)
1339+
# sam core files
1340+
$(OBJDIR)/core/%.c.o: $(SAM_CORE_PATH)/%.c $(COMMON_DEPS) | $(OBJDIR)
13291341
@$(MKDIR) $(dir $@)
13301342
$(CC) -MMD -c $(CPPFLAGS) $(CFLAGS) $< -o $@
13311343

1332-
$(OBJDIR)/core/%.cpp.o: $(ALTERNATE_CORE_PATH)/variants/$(VARIANT)/%.cpp $(COMMON_DEPS) | $(OBJDIR)
1344+
$(OBJDIR)/core/%.cpp.o: $(SAM_CORE_PATH)/%.cpp $(COMMON_DEPS) | $(OBJDIR)
13331345
@$(MKDIR) $(dir $@)
13341346
$(CXX) -MMD -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@
13351347

1336-
$(OBJDIR)/core/%.S.o: $(ALTERNATE_CORE_PATH)/variants/$(VARIANT)/%.S $(COMMON_DEPS) | $(OBJDIR)
1348+
$(OBJDIR)/core/%.S.o: $(SAM_CORE_PATH)/%.S $(COMMON_DEPS) | $(OBJDIR)
13371349
@$(MKDIR) $(dir $@)
13381350
$(CC) -MMD -c $(CPPFLAGS) $(ASFLAGS) $< -o $@
13391351

1352+
# due specific sources from sam core as doesn't core doesn't have SystemInit startup file
1353+
$(OBJDIR)/core/%.c.o: $(SAM_LIBSAM_PATH)/source/%.c $(COMMON_DEPS) | $(OBJDIR)
1354+
@$(MKDIR) $(dir $@)
1355+
$(CC) -MMD -c $(CPPFLAGS) $(CFLAGS) $< -o $@
1356+
1357+
$(OBJDIR)/core/%.c.o: $(SAM_SYSTEM_PATH)/source/%.c $(COMMON_DEPS) | $(OBJDIR)
1358+
@$(MKDIR) $(dir $@)
1359+
$(CC) -MMD -c $(CPPFLAGS) $(CFLAGS) $< -o $@
1360+
13401361
# various object conversions
13411362
$(OBJDIR)/%.bin: $(OBJDIR)/%.elf $(COMMON_DEPS)
13421363
@$(MKDIR) $(dir $@)

HISTORY.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ I tried to give credit whenever possible. If I have missed anyone, kindly add it
2020
- New: Add template Makefile and project boilerplate initialise script, `ardmk-init`. (https://github.com/tuna-f1sh)
2121
- New: Support atmelice_isp JTAG tool as ISP programmer. (https://github.com/tuna-f1sh)
2222
- New: Compatibility with deprecated pgmspace.h API can now be disabled since it sometimes causes bogus compiler warnings (issue #546)
23-
- New: Support Arduino ARM-based (SAM/SAMD) devices. (https://github.com/tuna-f1sh)
23+
- New: Support Arduino ARM SAMD devices (Zero, M0 Pro, Feather M0). (https://github.com/tuna-f1sh)
24+
- New: Support Arduino ARM SAM devices (Due). (https://github.com/tuna-f1sh)
2425

2526
### 1.6.0 (2017-07-11)
2627
- Fix: Allowed for SparkFun's weird usb pid/vid submenu shenanigans (issue #499). (https://github.com/sej7278)

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This is a very simple Makefile which knows how to build Arduino sketches. It def
88
- Highly customizable
99
- Supports all official AVR-based Arduino boards
1010
- Supports official ARM-based Arduino boards using Atmel SAM chip family
11-
(Cortex M0) and includes on-device debugging targets.
11+
and includes on-device debugging targets.
1212
- Supports chipKIT
1313
- Supports Teensy 3.x (via Teensyduino)
1414
- Works on all three major OS (Mac, Linux, Windows)
@@ -318,14 +318,14 @@ For large Robotis projects, [libmaple](https://github.com/Rhoban/Maple) may be m
318318
## Arduino ARM Boards
319319

320320
For Arduino boards using ARM architechure, specifically the Atmel SAM series
321-
(Arduino M0 [Pro], Zero, MKR1000, Feather M0, etc.), first
321+
((SAM3X8E) Due; (SAMD21) Arduino M0 [Pro], Zero, MKR1000, Feather M0, etc.), first
322322
install the board support package from the IDE or other distribution channels.
323323

324324
Define`ARDUINO_PACKAGE_DIR` as the root path containing the ARM support
325325
package (the manufacturer folder) and the `BOARD_TAG` (see `make show_boards`
326326
for help) within your project Makefile. Include 'Sam.mk' rather than
327-
'Arduino.mk' at the end of your file - see examples/ZeroBlink and
328-
examples/MZeroBlink for example usage.
327+
'Arduino.mk' at the end of your file - see examples/ZeroBlink,
328+
examples/MZeroBlink and examples/DueBlink for example usage.
329329

330330
**Note**: The Arduino IDE does not install board support packages to
331331
the base Arduino installation directory (the directory that will work with AVR
@@ -351,7 +351,7 @@ bootloaders. External CMSIS tools such as Atmel Ice will also work with this
351351
method. Black Magic Probe (BMP) support is also included using GDB for both
352352
uploading and debugging.
353353

354-
Native USB programing using Bossa (Zero, MKR1000, Feather style bootloaders)
354+
Native USB programing using Bossa (Due, Zero, MKR1000, Feather style bootloaders)
355355
and avrdude (M0 bootloaders) is supported. The bootloaders on these devices
356356
requires a double press of the reset button or open/closing the serial port at
357357
1200 BAUD. The automatic entry of the bootloader is attempted using

Sam.mk

Lines changed: 61 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ endif
5353

5454
ifndef 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
@@ -62,28 +62,42 @@ else
6262
endif
6363

6464
ifndef 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
6770
else
6871
$(call show_config_variable,CMSIS_VER,[USER])
6972
endif
7073

7174
ifndef 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
7480
else
7581
$(call show_config_variable,CMSIS_ATMEL_VER,[USER])
7682
endif
7783

7884
ifndef 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))
8191
else
8292
$(call show_config_variable,CMSIS_DIR,[USER])
8393
endif
8494

8595
ifndef 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))
88102
else
89103
$(call show_config_variable,CMSIS_ATMEL_DIR,[USER])
@@ -129,9 +143,27 @@ ifndef VARIANT
129143
endif
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
137169
ifndef ARM_TOOLS_DIR
@@ -160,7 +192,7 @@ ifndef CC_NAME
160192
endif
161193

162194
ifndef 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

331363
ifndef 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
333369
endif
334370

335371
get_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
345381
else
346382
BOSSA_OPTS += --port=$(ISP_PORT)
@@ -460,11 +496,20 @@ CXXFLAGS += -fno-rtti -fno-threadsafe-statics -std=gnu++11
460496
AMCU := $(call PARSE_BOARD,$(BOARD_TAG),build.mcu)
461497
BOARD_LINKER_SCRIPT := $(call PARSE_BOARD,$(BOARD_TAG),build.ldscript)
462498
OPENOCD_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
465499
LINKER_SCRIPTS := -T$(ALTERNATE_CORE_PATH)/variants/$(VARIANT)/$(BOARD_LINKER_SCRIPT)
466500
OTHER_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
469514
ifeq ($(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:)
481526
include $(ARDMK_DIR)/Arduino.mk
527+
528+
print-% : ; @echo $* = $($*)

examples/DueBlink/DueBlink.ino

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
Blink
3+
Turns on an LED on for one second, then off for one second, repeatedly.
4+
5+
This example code is in the public domain.
6+
*/
7+
8+
void setup() {
9+
// initialize the digital pin as an output.
10+
// Pin 13 has an LED connected on most Arduino boards:
11+
pinMode(13, OUTPUT);
12+
}
13+
14+
void loop() {
15+
digitalWrite(13, HIGH); // set the LED on
16+
delay(1000); // wait for a second
17+
digitalWrite(13, LOW); // set the LED off
18+
delay(1000); // wait for a second
19+
}

examples/DueBlink/Makefile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Arduino Due uses SAM3X8E SAM chip
2+
BOARD_TAG = arduino_due_x
3+
ARCHITECTURE = sam
4+
5+
# Define ARM toolchain dir if not using Arduino supplied
6+
#ARM_TOOLS_DIR = /usr
7+
8+
# Define AVR toolchain dir if not using Arduino supplied and using native port
9+
#AVR_TOOLS_DIR = /usr
10+
11+
# Define Arduino support package installation path where SAM device support has been installed
12+
# Linux
13+
#ARDUINO_PACKAGE_DIR := $(HOME)/.arduino15/packages
14+
# macOS
15+
#ARDUINO_PACKAGE_DIR := $(HOME)/Library/Arduino15/packages
16+
# Windows
17+
#ARDUINO_PACKAGE_DIR := "C:/Users/$(USER)/AppData/Local/Arduino15/packages"
18+
19+
include ../../Sam.mk

tests/script/runtests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ failures=()
77
# These examples cannot be tested easily at the moment as they require
88
# alternate cores. The MakefileExample doesn't actually contain any source code
99
# to compile.
10-
NON_TESTABLE_EXAMPLES=(ATtinyBlink MakefileExample TinySoftWareSerial BlinkOpenCM BlinkTeensy BlinkNetworkRPi BlinkInAVRC MZeroBlink ZeroBlink)
10+
NON_TESTABLE_EXAMPLES=(ATtinyBlink MakefileExample TinySoftWareSerial BlinkOpenCM BlinkTeensy BlinkNetworkRPi BlinkInAVRC MZeroBlink ZeroBlink DueBlink)
1111

1212
for dir in $TESTS_DIR/*/
1313
do

0 commit comments

Comments
 (0)