-
Notifications
You must be signed in to change notification settings - Fork 120
Expand file tree
/
Copy patharduino-samd.py
More file actions
173 lines (141 loc) · 4.69 KB
/
arduino-samd.py
File metadata and controls
173 lines (141 loc) · 4.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# Copyright 2014-present PlatformIO <contact@platformio.org>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Arduino
Arduino Wiring-based Framework allows writing cross-platform software to
control devices attached to a wide range of Arduino boards to create all
kinds of creative coding, interactive objects, spaces or physical experiences.
http://arduino.cc/en/Reference/HomePage
"""
import os
from SCons.Script import DefaultEnvironment
env = DefaultEnvironment()
platform = env.PioPlatform()
board = env.BoardConfig()
VENDOR_CORE = board.get("build.core", "").lower()
framework_package = "framework-arduino-samd"
if VENDOR_CORE != "arduino":
framework_package += "-%s" % VENDOR_CORE
FRAMEWORK_DIR = platform.get_package_dir(framework_package)
CMSIS_DIR = platform.get_package_dir("framework-cmsis")
CMSIS_ATMEL_DIR = platform.get_package_dir("framework-cmsis-atmel")
assert all(os.path.isdir(d) for d in (FRAMEWORK_DIR, CMSIS_DIR, CMSIS_ATMEL_DIR))
env.SConscript("arduino-common.py")
BUILD_CORE = "arduino"
if VENDOR_CORE == "sparkfun" and board.get("build.mcu", "").startswith("samd51"):
BUILD_CORE = "arduino51"
if VENDOR_CORE == "industruino":
BUILD_CORE = "industruino"
env.Append(
CPPDEFINES=[
"ARDUINO_ARCH_SAMD"
],
CPPPATH=[
os.path.join(
CMSIS_DIR,
"CMSIS",
os.path.join("Core", "Include") if VENDOR_CORE in ("adafruit", "seeed") else "Include",
), # Adafruit and Seeed cores use CMSIS v5.4 with different folder structure
os.path.join(CMSIS_ATMEL_DIR, "CMSIS", "Device", "ATMEL"),
os.path.join(CMSIS_ATMEL_DIR, "CMSIS-Atmel", "CMSIS", "Device", "ATMEL"),
os.path.join(FRAMEWORK_DIR, "cores", BUILD_CORE)
],
LIBPATH=[
os.path.join(CMSIS_DIR, "CMSIS", "Lib", "GCC"),
],
LINKFLAGS=[
"--specs=nosys.specs",
"--specs=nano.specs"
]
)
if board.get("build.cpu") == "cortex-m4":
env.Prepend(
CCFLAGS=[
"-mfloat-abi=hard",
"-mfpu=fpv4-sp-d16"
],
LINKFLAGS=[
"-mfloat-abi=hard",
"-mfpu=fpv4-sp-d16"
],
LIBS=["arm_cortexM4lf_math"]
)
else:
env.Prepend(
LIBS=["arm_cortexM0l_math"]
)
if VENDOR_CORE in ("seeed", "adafruit", "moteino"):
env.Append(
CPPDEFINES=[
("USB_CONFIG_POWER", board.get("build.usb_power", 100))
],
CCFLAGS=[
"-Wno-expansion-to-defined"
],
CPPPATH=[
os.path.join(FRAMEWORK_DIR, "cores", BUILD_CORE, "TinyUSB"),
os.path.join(FRAMEWORK_DIR, "cores", BUILD_CORE, "TinyUSB",
"Adafruit_TinyUSB_ArduinoCore"),
os.path.join(FRAMEWORK_DIR, "cores", BUILD_CORE, "TinyUSB",
"Adafruit_TinyUSB_ArduinoCore", "tinyusb", "src")
]
)
if VENDOR_CORE in ("adafruit", "seeed"):
env.Append(CPPPATH=[os.path.join(CMSIS_DIR, "CMSIS", "DSP", "Include")])
#
# Vendor-specific configurations
#
if VENDOR_CORE == "moteino":
env.Append(
CPPDEFINES=[
"ARM_MATH_CM0PLUS"
]
)
elif VENDOR_CORE == "seeed":
env.Append(
LINKFLAGS=[
"-Wl,--wrap,_write",
"-u", "__wrap__write"
]
)
elif VENDOR_CORE == "arduino":
env.Prepend(
CPPPATH=[
os.path.join(FRAMEWORK_DIR, "cores", BUILD_CORE, "api", "deprecated"),
os.path.join(FRAMEWORK_DIR, "cores", BUILD_CORE, "api", "deprecated-avr-comp")
]
)
env.Append(
ASFLAGS=env.get("CCFLAGS", [])[:],
)
#
# Target: Build Core Library
#
libs = []
if "build.variant" in board:
variants_dir = os.path.join(
"$PROJECT_DIR", board.get("build.variants_dir")) if board.get(
"build.variants_dir", "") else os.path.join(FRAMEWORK_DIR, "variants")
env.Append(
CPPPATH=[os.path.join(variants_dir, board.get("build.variant"))]
)
libs.append(env.BuildLibrary(
os.path.join("$BUILD_DIR", "FrameworkArduinoVariant"),
os.path.join(variants_dir, board.get("build.variant"))
))
libs.append(env.BuildLibrary(
os.path.join("$BUILD_DIR", "FrameworkArduino"),
os.path.join(FRAMEWORK_DIR, "cores", BUILD_CORE)
))
env.Prepend(LIBS=libs)