embassy-rs / embassy

Modern embedded framework, using Rust and async.
https://embassy.dev
Apache License 2.0
5.64k stars 781 forks source link

Cannot update using dfu-util #3536

Open Gerharddc opened 1 week ago

Gerharddc commented 1 week ago

Hi, I have implemented a USB bootloader with DFU based on the closest example I could find: https://github.com/embassy-rs/embassy/tree/main/examples/boot/bootloader/stm32wb-dfu. I have managed to get it to compile and run just fine, but I can't seem to manage to use it to perform updates using dfu-util.

I have installed the latest win64 version of dfu-util from https://dfu-util.sourceforge.net/releases/dfu-util-0.11-binaries.tar.xz. I also used https://zadig.akeo.ie/ to install the WinUSB driver for the device so that dfu-util can talk to it via libusb.

When I run ./dfu-util.exe --list I get:

dfu-util 0.11

Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
Copyright 2010-2021 Tormod Volden and Stefan Schmidt
This program is Free Software and has ABSOLUTELY NO WARRANTY
Please report bugs to http://sourceforge.net/p/dfu-util/tickets/

Found DFU: [c0de:cafe] ver=0010, devnum=29, cfg=1, intf=0, path="1-9.3", alt=0, name="UNKNOWN", serial="12345678"

Here my device shows up so things are clearly working to some extent. The vid, pid and even serial number are correct. I am not sure why the name is reported as "UNKNOWN" though as my config.product has been set to something else.

Since I saw that the device number is 29, I then run ./dfu-util.exe -n 29 -D mcu-fw-app to perform an update and get:

dfu-util 0.11

Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
Copyright 2010-2021 Tormod Volden and Stefan Schmidt
This program is Free Software and has ABSOLUTELY NO WARRANTY
Please report bugs to http://sourceforge.net/p/dfu-util/tickets/

Warning: Invalid DFU suffix signature
A valid DFU suffix will be required in a future dfu-util release
Opening DFU capable USB device...
Device ID c0de:cafe
Device DFU version 0110
Claiming USB DFU Interface...
Setting Alternate Interface #0 ...
Determining device status...
DFU state(2) = dfuIDLE, status(0) = No error condition is present
DFU mode device DFU version 0110
Device returned transfer size 4096
Copying data from PC to DFU device
Download        [                         ]   0%         4096 bytesError during download (LIBUSB_ERROR_PIPE)

For some reason here the update manages to start but then immediately fails with an uninformative error message on the dfu-util side. I have installed the "defmt" feature for embassy-usb-dfu but am not seeing any errors being logged on that side. I also don't see a crash or anything like that.

Any idea if I am using dfu-util wrong or if this an issue with embassy-usb-dfu and/or possibly the way I am using it? Thanks!

P.S. all my embassy components are the latest versions from git.