1316867adSThibaut VIARD# Copyright (c) 2014-2015 Arduino LLC.  All right reserved.
2316867adSThibaut VIARD#
3316867adSThibaut VIARD# This library is free software; you can redistribute it and/or
4316867adSThibaut VIARD# modify it under the terms of the GNU Lesser General Public
5316867adSThibaut VIARD# License as published by the Free Software Foundation; either
6316867adSThibaut VIARD# version 2.1 of the License, or (at your option) any later version.
7316867adSThibaut VIARD#
8316867adSThibaut VIARD# This library is distributed in the hope that it will be useful,
9316867adSThibaut VIARD# but WITHOUT ANY WARRANTY; without even the implied warranty of
10316867adSThibaut VIARD# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11316867adSThibaut VIARD# See the GNU Lesser General Public License for more details.
12316867adSThibaut VIARD#
13316867adSThibaut VIARD# You should have received a copy of the GNU Lesser General Public
14316867adSThibaut VIARD# License along with this library; if not, write to the Free Software
15316867adSThibaut VIARD# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
16316867adSThibaut VIARD
1704521c8fSThibaut VIARD# Arduino SAMD Core and platform.
18973ccc47SThibaut VIARD#
19973ccc47SThibaut VIARD# For more info:
20973ccc47SThibaut VIARD# https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5---3rd-party-Hardware-specification
21973ccc47SThibaut VIARD
220997a2e3SMartino Facchinname=Arduino SAMD (32-bits ARM Cortex-M0+) Boards
23356a11aaSMartino Facchinversion=1.8.8
24973ccc47SThibaut VIARD
25ae42fd11SThibaut VIARD# Compile variables
26a17594a8SCristian Maglie# -----------------
27973ccc47SThibaut VIARD
2843a5ef63SCristian Magliecompiler.warning_flags=-w
2943a5ef63SCristian Magliecompiler.warning_flags.none=-w
3043a5ef63SCristian Magliecompiler.warning_flags.default=
318575a52aSSandeep Mistrycompiler.warning_flags.more=-Wall -Wno-expansion-to-defined
328575a52aSSandeep Mistrycompiler.warning_flags.all=-Wall -Wextra -Wno-expansion-to-defined
3343a5ef63SCristian Maglie
34f852a083SCristian Maglie# EXPERIMENTAL feature: optimization flags
35f852a083SCristian Maglie#  - this is alpha and may be subject to change without notice
36cf72acfeSrsoracompiler.optimization_flags=-Os
37cf72acfeSrsoracompiler.optimization_flags.release=-Os
38cf72acfeSrsoracompiler.optimization_flags.debug=-Og -g3
39cf72acfeSrsora
40606eb9aaSMartino Facchincompiler.path={runtime.tools.arm-none-eabi-gcc-7-2017q4.path}/bin/
41973ccc47SThibaut VIARDcompiler.c.cmd=arm-none-eabi-gcc
42cf72acfeSrsoracompiler.c.flags=-mcpu={build.mcu} -mthumb -c -g {compiler.optimization_flags} {compiler.warning_flags} -std=gnu11 -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -MMD
43906dbd95SHelmut Tschemernjakcompiler.c.elf.cmd=arm-none-eabi-g++
44cf72acfeSrsoracompiler.c.elf.flags={compiler.optimization_flags} -Wl,--gc-sections -save-temps
4509253856SCristian Magliecompiler.S.cmd=arm-none-eabi-gcc
46fdabc894SMartino Facchincompiler.S.flags=-c -g -x assembler-with-cpp -MMD
47973ccc47SThibaut VIARDcompiler.cpp.cmd=arm-none-eabi-g++
48cf72acfeSrsoracompiler.cpp.flags=-mcpu={build.mcu} -mthumb -c -g {compiler.optimization_flags} {compiler.warning_flags} -std=gnu++11 -ffunction-sections -fdata-sections -fno-threadsafe-statics -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -MMD
49973ccc47SThibaut VIARDcompiler.ar.cmd=arm-none-eabi-ar
50973ccc47SThibaut VIARDcompiler.ar.flags=rcs
51973ccc47SThibaut VIARDcompiler.objcopy.cmd=arm-none-eabi-objcopy
52973ccc47SThibaut VIARDcompiler.objcopy.eep.flags=-O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0
535f494e0aSMartino Facchincompiler.elf2hex.bin.flags=-O binary
545f494e0aSMartino Facchincompiler.elf2hex.hex.flags=-O ihex -R .eeprom
55973ccc47SThibaut VIARDcompiler.elf2hex.cmd=arm-none-eabi-objcopy
56afc2dde3SThibaut VIARDcompiler.ldflags=-mcpu={build.mcu} -mthumb -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align
57973ccc47SThibaut VIARDcompiler.size.cmd=arm-none-eabi-size
58973ccc47SThibaut VIARDcompiler.define=-DARDUINO=
5951369814SMartino Facchincompiler.readelf.cmd=arm-none-eabi-readelf
60ae42fd11SThibaut VIARD
61973ccc47SThibaut VIARD# this can be overriden in boards.txt
62973ccc47SThibaut VIARDbuild.extra_flags=
63973ccc47SThibaut VIARD
64ae42fd11SThibaut VIARD# These can be overridden in platform.local.txt
65ae42fd11SThibaut VIARDcompiler.c.extra_flags=
66ae42fd11SThibaut VIARDcompiler.c.elf.extra_flags=
6793c63552SThibaut VIARD#compiler.c.elf.extra_flags=-v
68ae42fd11SThibaut VIARDcompiler.cpp.extra_flags=
6909253856SCristian Magliecompiler.S.extra_flags=
70ae42fd11SThibaut VIARDcompiler.ar.extra_flags=
71ae42fd11SThibaut VIARDcompiler.elf2hex.extra_flags=
72973ccc47SThibaut VIARD
73606eb9aaSMartino Facchincompiler.arm.cmsis.c.flags="-I{runtime.tools.CMSIS-4.5.0.path}/CMSIS/Include/" "-I{runtime.tools.CMSIS-Atmel-1.2.0.path}/CMSIS/Device/ATMEL/"
746feccf8aSSandeep Mistrycompiler.arm.cmsis.ldflags="-L{runtime.tools.CMSIS-4.5.0.path}/CMSIS/Lib/GCC/" -larm_cortexM0l_math
75973ccc47SThibaut VIARD
7637c8d4f3SMartino Facchincompiler.libraries.ldflags=
7737c8d4f3SMartino Facchin
78973ccc47SThibaut VIARD# USB Flags
79973ccc47SThibaut VIARD# ---------
80973ccc47SThibaut VIARDbuild.usb_flags=-DUSB_VID={build.vid} -DUSB_PID={build.pid} -DUSBCON '-DUSB_MANUFACTURER={build.usb_manufacturer}' '-DUSB_PRODUCT={build.usb_product}'
81973ccc47SThibaut VIARD
82973ccc47SThibaut VIARD# Default usb manufacturer will be replaced at compile time using
83973ccc47SThibaut VIARD# numeric vendor ID if available or by board's specific value.
84973ccc47SThibaut VIARDbuild.usb_manufacturer="Unknown"
85973ccc47SThibaut VIARD
86ae42fd11SThibaut VIARD# Compile patterns
87a17594a8SCristian Maglie# ----------------
88973ccc47SThibaut VIARD
89973ccc47SThibaut VIARD## Compile c files
905f65854eSSandeep Mistryrecipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.c.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.c.extra_flags} {build.extra_flags} {compiler.arm.cmsis.c.flags} {includes} "{source_file}" -o "{object_file}"
91973ccc47SThibaut VIARD
92973ccc47SThibaut VIARD## Compile c++ files
935f65854eSSandeep Mistryrecipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {compiler.arm.cmsis.c.flags} {includes} "{source_file}" -o "{object_file}"
94973ccc47SThibaut VIARD
9509253856SCristian Maglie## Compile S files
965f65854eSSandeep Mistryrecipe.S.o.pattern="{compiler.path}{compiler.S.cmd}" {compiler.S.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.S.extra_flags} {build.extra_flags} {compiler.arm.cmsis.c.flags} {includes} "{source_file}" -o "{object_file}"
9709253856SCristian Maglie
98973ccc47SThibaut VIARD## Create archives
99e1b164f7SSandeep Mistry# archive_file_path is needed for backwards compatibility with IDE 1.6.5 or older, IDE 1.6.6 or newer overrides this value
100e1b164f7SSandeep Mistryarchive_file_path={build.path}/{archive_file}
1013748a622SBillrecipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{archive_file_path}" "{object_file}"
102973ccc47SThibaut VIARD
103973ccc47SThibaut VIARD## Combine gc-sections, archives, and objects
10437c8d4f3SMartino Facchinrecipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}"  "-L{build.path}" {compiler.c.elf.flags} {compiler.c.elf.extra_flags} "-T{build.variant.path}/{build.ldscript}" "-Wl,-Map,{build.path}/{build.project_name}.map" --specs=nano.specs --specs=nosys.specs {compiler.ldflags} -o "{build.path}/{build.project_name}.elf" {object_files} {compiler.libraries.ldflags} -Wl,--start-group {compiler.arm.cmsis.ldflags} -lm "{build.path}/{archive_file}" -Wl,--end-group
105973ccc47SThibaut VIARD
106319688b0SCristian Maglie## Create output (bin file)
1075f494e0aSMartino Facchinrecipe.objcopy.bin.pattern="{compiler.path}{compiler.elf2hex.cmd}" {compiler.elf2hex.bin.flags} {compiler.elf2hex.extra_flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.bin"
1085f494e0aSMartino Facchin
1095f494e0aSMartino Facchin## Create output (hex file)
1105f494e0aSMartino Facchinrecipe.objcopy.hex.pattern="{compiler.path}{compiler.elf2hex.cmd}" {compiler.elf2hex.hex.flags} {compiler.elf2hex.extra_flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.hex"
1115f494e0aSMartino Facchin
1125f494e0aSMartino Facchinbuild.preferred_out_format=bin
113973ccc47SThibaut VIARD
11443a5ef63SCristian Maglie## Save hex
1155f494e0aSMartino Facchinrecipe.output.tmp_file={build.project_name}.{build.preferred_out_format}
1165f494e0aSMartino Facchinrecipe.output.save_file={build.project_name}.{build.variant}.{build.preferred_out_format}
11743a5ef63SCristian Maglie
118973ccc47SThibaut VIARD## Compute size
119973ccc47SThibaut VIARDrecipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/{build.project_name}.elf"
120f7b24ecfSMatthijs Kooijmanrecipe.size.regex=^(?:\.text|\.data|)\s+([0-9]+).*
1211857cceeSMatthijs Kooijmanrecipe.size.regex.data=^(?:\.data|\.bss)\s+([0-9]+).*
122973ccc47SThibaut VIARD
123e6af98a7SCristian Maglie# Upload/Debug tools
124e6af98a7SCristian Maglie# ------------------
125973ccc47SThibaut VIARD
1266332f578SThibaut VIARD#
1275f494e0aSMartino Facchin# AVRDUDE
1285f494e0aSMartino Facchin#
1295f494e0aSMartino Facchintools.avrdude.path={runtime.tools.avrdude.path}
1305f494e0aSMartino Facchintools.avrdude.cmd={path}/bin/avrdude
1315f494e0aSMartino Facchintools.avrdude.config.path={path}/etc/avrdude.conf
1325f494e0aSMartino Facchin
1335f494e0aSMartino Facchintools.avrdude.upload.params.verbose=-v -v
1345f494e0aSMartino Facchintools.avrdude.upload.params.quiet=-q -q
1355f494e0aSMartino Facchintools.avrdude.upload.params.noverify=-V
1365f494e0aSMartino Facchintools.avrdude.upload.pattern="{cmd}" "-C{config.path}" {upload.verbose} -p{build.emu.mcu} -c{upload.protocol} -P{serial.port} -b{upload.speed} "-Uflash:w:{build.path}/{build.project_name}.hex:i"
1375f494e0aSMartino Facchin
1380e8e997bSsergiotomasellotools.avrdude_remote.upload.pattern="openocd --version 2>&1 | grep 2016 && if opkg update; then opkg upgrade openocd; exit 1; else echo 'Please connect your board to the Internet in order to upgrade tools' >&2; exit 1; fi || /usr/bin/run-avrdude /tmp/sketch.hex"
139ea6eade2SMartino Facchin
14035cae15aSJuraj Andrassytools.avrdude.network_cmd={runtime.tools.arduinoOTA.path}/bin/arduinoOTA
14135cae15aSJuraj Andrassytools.avrdude.upload.network_pattern="{network_cmd}" -address {serial.port} -port 65280 -username arduino -password "{network.password}" -sketch "{build.path}/{build.project_name}.bin" -upload /sketch -b
14235cae15aSJuraj Andrassy
1435f494e0aSMartino Facchin#
1446332f578SThibaut VIARD# BOSSA
1456332f578SThibaut VIARD#
146606eb9aaSMartino Facchintools.bossac.path={runtime.tools.bossac-1.7.0-arduino3.path}
147ae42fd11SThibaut VIARDtools.bossac.cmd=bossac
148ae42fd11SThibaut VIARDtools.bossac.cmd.windows=bossac.exe
149ae42fd11SThibaut VIARD
150ae42fd11SThibaut VIARDtools.bossac.upload.params.verbose=-i -d
151ae42fd11SThibaut VIARDtools.bossac.upload.params.quiet=
152abea3f55SThibaut VIARDtools.bossac.upload.pattern="{path}/{cmd}" {upload.verbose} --port={serial.port.file} -U {upload.native_usb} -i -e -w -v "{build.path}/{build.project_name}.bin" -R
153ae42fd11SThibaut VIARD
154e7bd6f4aSCristian Maglietools.bossac_remote.upload.pattern=/usr/bin/run-bossac {upload.verbose} --port=ttyATH0 -U {upload.native_usb} -e -w -v /tmp/sketch.bin -R
155e7bd6f4aSCristian Maglie
156cdf7899dSMartino Facchinarduinoota.extraflags=
157cdf7899dSMartino Facchintools.bossac.network_cmd={runtime.tools.arduinoOTA-1.3.0.path}/bin/arduinoOTA
158cdf7899dSMartino Facchintools.bossac.upload.network_pattern="{network_cmd}" -address {serial.port} -port 65280 -username arduino -password "{network.password}" -sketch "{build.path}/{build.project_name}.bin" -upload /sketch -b {arduinoota.extraflags}
159a15d190aSSandeep Mistry
1606332f578SThibaut VIARD#
161d0dc254cSMartino Facchin# BOSSA (ignore binary size)
162d0dc254cSMartino Facchin#
163606eb9aaSMartino Facchintools.bossacI.path={runtime.tools.bossac-1.7.0-arduino3.path}
164d0dc254cSMartino Facchintools.bossacI.cmd=bossac
165d0dc254cSMartino Facchintools.bossacI.cmd.windows=bossac.exe
166d0dc254cSMartino Facchin
167d0dc254cSMartino Facchintools.bossacI.upload.params.verbose=-i -d
168d0dc254cSMartino Facchintools.bossacI.upload.params.quiet=
1697b6434aaSMartino Facchintools.bossacI.upload.pattern="{path}/{cmd}" {upload.verbose} --port={serial.port.file} -I -U {upload.native_usb} -i -e -w "{build.path}/{build.project_name}.bin" -R
170d0dc254cSMartino Facchin
171d0dc254cSMartino Facchintools.bossacI_remote.upload.pattern=/usr/bin/run-bossac {upload.verbose} --port=ttyATH0 -U {upload.native_usb} -e -w -v /tmp/sketch.bin -R
172d0dc254cSMartino Facchin
173d0dc254cSMartino Facchintools.bossacI.network_cmd={runtime.tools.arduinoOTA.path}/bin/arduinoOTA
174d0dc254cSMartino Facchintools.bossacI.upload.network_pattern="{network_cmd}" -address {serial.port} -port 65280 -username arduino -password "{network.password}" -sketch "{build.path}/{build.project_name}.bin" -upload /sketch -b
175d0dc254cSMartino Facchin
176d0dc254cSMartino Facchin
177d0dc254cSMartino Facchin#
1786332f578SThibaut VIARD# OpenOCD sketch upload
1796332f578SThibaut VIARD#
1806332f578SThibaut VIARD
1812f97fc2aSMartino Facchintools.openocd.path={runtime.tools.openocd-0.10.0-arduino7.path}
182cb789d9aSCristian Maglietools.openocd.cmd=bin/openocd
18395da7fb4SCristian Maglietools.openocd.cmd.windows=bin/openocd.exe
184973ccc47SThibaut VIARD
185c81157e1SThibaut VIARDtools.openocd.upload.params.verbose=-d2
1866332f578SThibaut VIARDtools.openocd.upload.params.quiet=-d0
187eb629113SMartino Facchintools.openocd.upload.pattern="{path}/{cmd}" {upload.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; program {{build.path}/{build.project_name}.bin} verify reset 0x2000; shutdown"
18895510858SMartino Facchin
189a15d190aSSandeep Mistrytools.openocd.network_cmd={runtime.tools.arduinoOTA.path}/bin/arduinoOTA
190120d85feSSandeep Mistrytools.openocd.upload.network_pattern={network_cmd} -address {serial.port} -port 65280 -username arduino -password "{network.password}" -sketch "{build.path}/{build.project_name}.bin" -upload /sketch -b
191a15d190aSSandeep Mistry
192c81157e1SThibaut VIARDtools.openocd.program.params.verbose=-d2
1936332f578SThibaut VIARDtools.openocd.program.params.quiet=-d0
194166478fcSCristian Maglietools.openocd.program.pattern="{path}/{cmd}" {program.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; program {{build.path}/{build.project_name}.hex} verify reset; shutdown"
1956332f578SThibaut VIARD
1966332f578SThibaut VIARDtools.openocd.erase.params.verbose=-d3
1976332f578SThibaut VIARDtools.openocd.erase.params.quiet=-d0
198c81157e1SThibaut VIARDtools.openocd.erase.pattern=
1996332f578SThibaut VIARD
20093c63552SThibaut VIARDtools.openocd.bootloader.params.verbose=-d2
2016332f578SThibaut VIARDtools.openocd.bootloader.params.quiet=-d0
202eb629113SMartino Facchintools.openocd.bootloader.pattern="{path}/{cmd}" {bootloader.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; init; halt; at91samd bootloader 0; program {{runtime.platform.path}/bootloaders/{bootloader.file}} verify reset; shutdown"
20351369814SMartino Facchin
20451369814SMartino Facchin#
20551369814SMartino Facchin# OpenOCD sketch upload - version with configurable bootloader size
20651369814SMartino Facchin# FIXME: this programmer is a workaround for default options being overwritten by uploadUsingPreferences
20751369814SMartino Facchin#
20851369814SMartino Facchin
2092f97fc2aSMartino Facchintools.openocd-withbootsize.path={runtime.tools.openocd-0.10.0-arduino7.path}
21051369814SMartino Facchintools.openocd-withbootsize.cmd=bin/openocd
21151369814SMartino Facchintools.openocd-withbootsize.cmd.windows=bin/openocd.exe
21251369814SMartino Facchin
21351369814SMartino Facchintools.openocd-withbootsize.upload.params.verbose=-d2
21451369814SMartino Facchintools.openocd-withbootsize.upload.params.quiet=-d0
2155704a06fSMartino Facchintools.openocd-withbootsize.upload.pattern="{path}/{cmd}" {upload.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; program {{build.path}/{build.project_name}.bin} verify reset {bootloader.size}; shutdown"
21651369814SMartino Facchin
21751369814SMartino Facchin# Program flashes the binary at 0x0000, so use the linker script without_bootloader
21851369814SMartino Facchintools.openocd-withbootsize.program.params.verbose=-d2
21951369814SMartino Facchintools.openocd-withbootsize.program.params.quiet=-d0
220eb629113SMartino Facchintools.openocd-withbootsize.program.pattern="{path}/{cmd}" {program.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; program {{build.path}/{build.project_name}.elf} verify reset; shutdown"
22151369814SMartino Facchin
22251369814SMartino Facchintools.openocd-withbootsize.erase.params.verbose=-d3
22351369814SMartino Facchintools.openocd-withbootsize.erase.params.quiet=-d0
22451369814SMartino Facchintools.openocd-withbootsize.erase.pattern=
22551369814SMartino Facchin
22651369814SMartino Facchintools.openocd-withbootsize.bootloader.params.verbose=-d2
22751369814SMartino Facchintools.openocd-withbootsize.bootloader.params.quiet=-d0
228eb629113SMartino Facchintools.openocd-withbootsize.bootloader.pattern="{path}/{cmd}" {bootloader.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; init; halt; at91samd bootloader 0; program {{runtime.platform.path}/bootloaders/{bootloader.file}} verify reset; shutdown"
229e6af98a7SCristian Maglie
230e6af98a7SCristian Maglie#
231e6af98a7SCristian Maglie# GDB (Debugger)
232e6af98a7SCristian Maglie#
233f852a083SCristian Maglie# EXPERIMENTAL feature: debug.pattern
234f852a083SCristian Maglie#  - this is alpha and may be subject to change without notice
235f68e5297Srsoratools.gdb-openocd.path={runtime.tools.arm-none-eabi-gcc-7-2017q4.path}/bin/
236f68e5297Srsoratools.gdb-openocd.cmd=arm-none-eabi-gdb
237f68e5297Srsoratools.gdb-openocd.cmd.windows=arm-none-eabi-gdb.exe
238f68e5297Srsoratools.gdb-openocd.interpreter=console
2399b8098f9SAlexander Entingertools.gdb-openocd.debug.pattern="{path}/{cmd}" --interpreter={interpreter} -ex "set remotetimeout 5" -ex "set pagination off" -ex 'target extended-remote | "{tools.openocd.path}/{tools.openocd.cmd}" -s "{tools.openocd.path}/share/openocd/scripts/" --file "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "gdb_port pipe" -c "telnet_port 0"' "{build.path}/{build.project_name}.elf"
240