Switch mbed-based boards to patched Arduino dfuutil package

Issue #729
This commit is contained in:
valeros
2023-09-20 15:35:23 +03:00
parent ec4340602a
commit db0097cfe4
3 changed files with 34 additions and 16 deletions

View File

@@ -208,9 +208,14 @@ elif upload_protocol == "dfu":
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 @@ elif upload_protocol == "dfu":
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 @@ elif upload_protocol == "dfu":
"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,

View File

@@ -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",

View File

@@ -70,7 +70,13 @@ class Ststm32Platform(PlatformBase):
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"][