dfu-rs / dfu-libusb

DFU library implementation using libusb
10 stars 12 forks source link

Support for DFU format #15

Open karniv00l opened 1 year ago

karniv00l commented 1 year ago

Hi there,

firstly, thank you for this great library! I've stumbled upon it when researching DFU libraries for a Flutter package I was planing on developing.

I did some quick tests, flashing both .bin and .dfu formats. So the .bin file works flawlessly without specifying address or interface, but after .dfu is downloaded, the microcontroller won't boot/run properly. The chip is STM32F405.

Here's how I tested it:

dfu-libusb

For both bin and dfu files, I use the same command, just a different file:

Binary

cargo run --example download -- --device 0483:df11 fw.bin

DFU

cargo run --example download -- --device 0483:df11 fw.dfu

dfu-util

Compared to dfu-util which works for both files, but different args are required:

Binary

dfu-util -a 0 --dfuse-address 0x08000000 -D fw.bin

DFU

dfu-util -d 0483:df11 -D fw.dfu

I'm attaching logs for both executions:

logs_bin.txt logs_dfu.txt

not sure how much you can help me here, but I appreciate your time.

cecton commented 1 year ago

Hello!

Unfortunately we have not developed the DFU format afaik so that's probably why it doesn't work. It's writing the .dfu like it is a .bin file

If you have time feel free to make a PR. Otherwise maybe someone will take it at some point (maybe @yozhgoor if he wants to get into embedded development :grin:)

biner88 commented 1 year ago

Can you briefly talk about what work to do, or what documents to refer to, so that it can support files in dfu format? I have the time and interest to perfect it. @cecton

cecton commented 1 year ago

hmm ... I will try :sweat_smile: @biner88

So... to avoid writing another state machine for the "download" command, we would need to make a reader (impl std::io::Read) that wraps the .dfu file. I think that's what I would do. You can even put that in a separate crate if you want (this could be useful for others I suppose?).

Then, in the DfuSync, we would need a new method that takes a .dfu file in argument.

Does that help? You probably need to find the specs for the .dfu file somewhere or just copy/inspire from the source code of dfu-util directly.

biner88 commented 1 year ago

Sorry for replying so late, we finally used the bin file to update it. Thanks for sharing the crate.

cecton commented 1 year ago

No problem! I will keep the ticket open because it's a feature request (and it's useful)