Skip to content

Commit 5563fcc

Browse files
committed
pybricksdev.dfu: Fix not rebooting hub on Windows.
Fix not rebooting hub on Windows after flashing firmware by using the dfu-util.exe fallback. The --reset option doesn't work on Windows because WinUSB doesn't support it. Instead, we can use the --dfuse-address option with ":leave" to exit DFU mode and reboot the device. This is a bit simpler than creating a .dfu file anyway. Fixes: #112
1 parent 50fdf36 commit 5563fcc

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
### Fixed
10+
- Fixed USB/DFU hub not rebooting after flashing firmware on Windows (pybricksdev#112).
11+
12+
[pybricksdev#112]: https://github.com/pybricks/pybricksdev/issues/112
13+
914
## [2.1.0] - 2025-09-10
1015

1116
### Added

pybricksdev/dfu.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -225,20 +225,24 @@ def flash_dfu(firmware_bin: bytes, metadata: AnyFirmwareMetadata) -> None:
225225
# if libusb was not found, try using dfu-util command line tool
226226

227227
with _get_dfu_util() as dfu_util:
228-
dev_id = _get_vid_pid(dfu_util)
229-
230-
dfu_create.build(outfile, [[target]], dev_id)
228+
with open(os.path.join(out_dir, "firmware.bin"), "wb") as bin_file:
229+
bin_file.write(firmware_bin)
231230

232231
exit(
233232
call(
234233
[
235234
dfu_util,
236235
"--device",
237-
f",{dev_id}",
236+
f",{_get_vid_pid(dfu_util)}",
238237
"--alt",
239238
"0",
239+
# We have to use dfuse option to be able to use
240+
# "leave" to exit DFU mode after flashing. --reset
241+
# doesn't work on Windows, so we can't use a .dfu file
242+
"--dfuse-address",
243+
f"{target['address']}:leave",
240244
"--download",
241-
outfile,
245+
bin_file.name,
242246
]
243247
)
244248
)

0 commit comments

Comments
 (0)