diff --git a/builder/main.py b/builder/main.py index 0cce148d..b75527ef 100644 --- a/builder/main.py +++ b/builder/main.py @@ -208,9 +208,14 @@ def _jlink_cmd_script(env, source): vid = hwids[0][0] pid = hwids[0][1] - # default tool for all boards with embedded DFU bootloader over USB - _upload_tool = '"%s"' % join(platform.get_package_dir( - "tool-dfuutil") or "", "bin", "dfu-util") + if env.subst("$BOARD").startswith(("portenta", "opta", "nicla")): + _upload_tool = '"%s"' % join(platform.get_package_dir( + "tool-dfuutil-arduino") or "", "dfu-util") + else: + # default tool for all boards with embedded DFU bootloader over USB + _upload_tool = '"%s"' % join(platform.get_package_dir( + "tool-dfuutil") or "", "bin", "dfu-util") + _upload_flags = [ "-d", ",".join(["%s:%s" % (hwid[0], hwid[1]) for hwid in hwids]), "-a", "0", "-s", @@ -220,7 +225,7 @@ def _jlink_cmd_script(env, source): upload_actions = [env.VerboseAction("$UPLOADCMD", "Uploading $SOURCE")] if "arduino" in frameworks: - if env.subst("$BOARD").startswith(("portenta", "opta")): + if env.subst("$BOARD").startswith(("portenta", "opta", "nicla")): upload_actions.insert( 0, env.VerboseAction(BeforeUpload, "Looking for upload port...") @@ -245,17 +250,18 @@ def __configure_upload_port(env): "Looking for upload port...")) if "dfu-util" in _upload_tool: - # Add special DFU header to the binary image - env.AddPostAction( - join("$BUILD_DIR", "${PROGNAME}.bin"), - env.VerboseAction( - " ".join([ - '"%s"' % join(platform.get_package_dir("tool-dfuutil") or "", - "bin", "dfu-suffix"), - "-v %s" % vid, - "-p %s" % pid, - "-d 0xffff", "-a", "$TARGET" - ]), "Adding dfu suffix to ${PROGNAME}.bin")) + if not env.subst("$BOARD").startswith(("portenta", "opta", "nicla")): + # Add special DFU header to the binary image + env.AddPostAction( + join("$BUILD_DIR", "${PROGNAME}.bin"), + env.VerboseAction( + " ".join([ + '"%s"' % join(platform.get_package_dir("tool-dfuutil") or "", + "bin", "dfu-suffix"), + "-v %s" % vid, + "-p %s" % pid, + "-d 0xffff", "-a", "$TARGET" + ]), "Adding dfu suffix to ${PROGNAME}.bin")) env.Replace( UPLOADER=_upload_tool, diff --git a/platform.json b/platform.json index f68f3b5a..e984f004 100644 --- a/platform.json +++ b/platform.json @@ -324,6 +324,12 @@ "owner": "platformio", "version": "~1.11.0" }, + "tool-dfuutil-arduino": { + "type": "uploader", + "optional": true, + "owner": "platformio", + "version": "~1.11.0" + }, "tool-cmake": { "optional": true, "owner": "platformio", diff --git a/platform.py b/platform.py index a2770606..5cc30824 100644 --- a/platform.py +++ b/platform.py @@ -70,7 +70,13 @@ def configure_default_packages(self, variables, targets): default_protocol = board_config.get("upload.protocol") or "" if variables.get("upload_protocol", default_protocol) == "dfu": - self.packages["tool-dfuutil"]["optional"] = False + dfu_package = "tool-dfuutil" + if board.startswith(("portenta", "opta", "nicla")): + dfu_package = "tool-dfuutil-arduino" + self.packages.pop("tool-dfuutil") + else: + self.packages.pop("tool-dfuutil-arduino") + self.packages[dfu_package]["optional"] = False if board == "mxchip_az3166": self.frameworks["arduino"][