Skip to content

Commit db0097c

Browse files
committed
Switch mbed-based boards to patched Arduino dfuutil package
Issue #729
1 parent ec43406 commit db0097c

File tree

3 files changed

+34
-16
lines changed

3 files changed

+34
-16
lines changed

builder/main.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,14 @@ def _jlink_cmd_script(env, source):
208208
vid = hwids[0][0]
209209
pid = hwids[0][1]
210210

211-
# default tool for all boards with embedded DFU bootloader over USB
212-
_upload_tool = '"%s"' % join(platform.get_package_dir(
213-
"tool-dfuutil") or "", "bin", "dfu-util")
211+
if env.subst("$BOARD").startswith(("portenta", "opta", "nicla")):
212+
_upload_tool = '"%s"' % join(platform.get_package_dir(
213+
"tool-dfuutil-arduino") or "", "dfu-util")
214+
else:
215+
# default tool for all boards with embedded DFU bootloader over USB
216+
_upload_tool = '"%s"' % join(platform.get_package_dir(
217+
"tool-dfuutil") or "", "bin", "dfu-util")
218+
214219
_upload_flags = [
215220
"-d", ",".join(["%s:%s" % (hwid[0], hwid[1]) for hwid in hwids]),
216221
"-a", "0", "-s",
@@ -220,7 +225,7 @@ def _jlink_cmd_script(env, source):
220225
upload_actions = [env.VerboseAction("$UPLOADCMD", "Uploading $SOURCE")]
221226

222227
if "arduino" in frameworks:
223-
if env.subst("$BOARD").startswith(("portenta", "opta")):
228+
if env.subst("$BOARD").startswith(("portenta", "opta", "nicla")):
224229
upload_actions.insert(
225230
0,
226231
env.VerboseAction(BeforeUpload, "Looking for upload port...")
@@ -245,17 +250,18 @@ def __configure_upload_port(env):
245250
"Looking for upload port..."))
246251

247252
if "dfu-util" in _upload_tool:
248-
# Add special DFU header to the binary image
249-
env.AddPostAction(
250-
join("$BUILD_DIR", "${PROGNAME}.bin"),
251-
env.VerboseAction(
252-
" ".join([
253-
'"%s"' % join(platform.get_package_dir("tool-dfuutil") or "",
254-
"bin", "dfu-suffix"),
255-
"-v %s" % vid,
256-
"-p %s" % pid,
257-
"-d 0xffff", "-a", "$TARGET"
258-
]), "Adding dfu suffix to ${PROGNAME}.bin"))
253+
if not env.subst("$BOARD").startswith(("portenta", "opta", "nicla")):
254+
# Add special DFU header to the binary image
255+
env.AddPostAction(
256+
join("$BUILD_DIR", "${PROGNAME}.bin"),
257+
env.VerboseAction(
258+
" ".join([
259+
'"%s"' % join(platform.get_package_dir("tool-dfuutil") or "",
260+
"bin", "dfu-suffix"),
261+
"-v %s" % vid,
262+
"-p %s" % pid,
263+
"-d 0xffff", "-a", "$TARGET"
264+
]), "Adding dfu suffix to ${PROGNAME}.bin"))
259265

260266
env.Replace(
261267
UPLOADER=_upload_tool,

platform.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,12 @@
324324
"owner": "platformio",
325325
"version": "~1.11.0"
326326
},
327+
"tool-dfuutil-arduino": {
328+
"type": "uploader",
329+
"optional": true,
330+
"owner": "platformio",
331+
"version": "~1.11.0"
332+
},
327333
"tool-cmake": {
328334
"optional": true,
329335
"owner": "platformio",

platform.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,13 @@ def configure_default_packages(self, variables, targets):
7070

7171
default_protocol = board_config.get("upload.protocol") or ""
7272
if variables.get("upload_protocol", default_protocol) == "dfu":
73-
self.packages["tool-dfuutil"]["optional"] = False
73+
dfu_package = "tool-dfuutil"
74+
if board.startswith(("portenta", "opta", "nicla")):
75+
dfu_package = "tool-dfuutil-arduino"
76+
self.packages.pop("tool-dfuutil")
77+
else:
78+
self.packages.pop("tool-dfuutil-arduino")
79+
self.packages[dfu_package]["optional"] = False
7480

7581
if board == "mxchip_az3166":
7682
self.frameworks["arduino"][

0 commit comments

Comments
 (0)