Skip to content

Commit

Permalink
Switch mbed-based boards to patched Arduino dfuutil package
Browse files Browse the repository at this point in the history
Issue #729
  • Loading branch information
valeros committed Sep 20, 2023
1 parent ec43406 commit db0097c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 16 deletions.
36 changes: 21 additions & 15 deletions builder/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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...")
Expand All @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions platform.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 7 additions & 1 deletion platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"][
Expand Down

0 comments on commit db0097c

Please sign in to comment.