Git Product home page Git Product logo

webdfu's Introduction

webdfu

This is a proof-of-concept demo of host USB DFU drivers in Javascript utilizing the WebUSB draft standard to implement USB firmware updates from the browser.

Demos

dfu-util

A demo re-implementing dfu-util functionality in the browser:

https://devanlai.github.io/webdfu/dfu-util/

mbed-download

A demo using WebUSB and the mbed remote compilation API to build and flash boards in one step:

https://devanlai.github.io/webdfu/mbed-download/

Host-side implementation

WebUSB is currently only supported by Chromium / Google Chrome.

For Chrome to communicate with a USB device, it must have permission to access the device and the operating system must be able to load a generic driver that libusb can talk to.

On Linux, that means that the current user must have permission to access the device.

On Windows, that means that an appropriate WinUSB/libusb driver must first be installed. This can be done manually with programs such as Zadig or automatically (sometimes...) with WCID

The javascript DFU driver is ported from the excellent open-source software, dfu-util.

Device-side implementation

The current WebUSB draft no longer requires the device to support additional WebUSB descriptors. However, implementing WebUSB descriptors allows the device to specify a landing page URL for the browser to present to the user when the device is plugged in.

For an example WebUSB-enabled USB DFU bootloader for the STM32F103 series, check out the dapboot project

Implemented features

  • Reading the current device firmware (DFU upload)
  • Writing new firmware to a device (DFU download)
  • Switching from the runtime configuration to the DFU bootloader (DFU detach)
  • ST DfuSe download
  • ST DfuSe upload

Planned future features:

  • DfuSe file format support
  • DFU file suffix support
  • Better support for remembering previous DFU configurations and pairing the bootloader/runtime versions of the same device.

Local testing

To test changes locally, you can run a simple web server.

For testing purposes, your browser will treat even an HTTP server as a secure context that can access WebUSB if it is accessed from localhost.

To this end, you can use the standard Python one-liner for running a local HTTP server.

For Python 2:

python -m SimpleHTTPServer

For Python 3:

python3 -m http.server

If you do want to test over HTTPS for development, you can run a toy HTTPS server with the following command. A pre-generated certificate is included for convenience.

python SimpleSecureHTTPServer.py --cert server.pem --port 8000

Note: Don't re-use this certificate outside of your development environment!

For additional tips and information about WebUSB, see this article:

https://web.dev/usb/

webdfu's People

Contributors

devanlai avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

webdfu's Issues

STM32F042 device in DFU mode not recognized on demo website

I have an STM32F042 device connected to my computer in DFU mode using the dfuse bootloader (I've verified that it's connected by checking windows device manager). when I enter the device vendor id and click connect, there is a popup "no compatible devices found". Does this library support connecting to STM32F0 devices in DFU mode?

I need help!...

I am trying to use webdfu to load a program on an STM32F042K6T6 (from a Mac)
Loading seems to be going well
BUT:

  • the program does not work
  • The number of bytes loaded is too large (4169 instead of 3860)

And when I look at the flash, I see that the header ("DfuSe ..") is there 2 times (1 => @ 0, 2 => @ 0x125)

Do you have an idea that could help me?
Thank you!

Louis

Please specify system requirements for the python server

This is what I get when I try to run. Are you using python 2? Can you provide a version for python 3?

/c/projects/webdfu/repo$ python --version
Python 3.8.5

/c/projects/webdfu/repo$ python SimpleSecureHTTPServer.py --cert server.pem --port 8000
Traceback (most recent call last):
File "SimpleSecureHTTPServer.py", line 2, in
import BaseHTTPServer, SimpleHTTPServer
ModuleNotFoundError: No module named 'BaseHTTPServer'

Device reset not working? (Windows and macOS)

Hi!

I'm trying to get this to work with the Coral USB Accelerator (on macOS)
https://github.com/google-coral/libedgetpu/releases/
https://github.com/google-coral/webcoral

https://devanlai.github.io/webdfu/dfu-util/ doesn't seem to work

Also the "Flash Firmware" step here
https://test.geogebra.org/~mike/coral/

in Google's own demo also doesn't work

In both cases it looks like it's worked but lsusb still shows
Bus 000 Device 001: ID 1a6e:089a Global Unichip Corp. Composite Device
Bus 000 Device 000: ID 1a6e:089a Global Unichip Corp. USB 3.1 Bus

Rather than the expected (which I do get after "make reset" from the terminal)
Bus 000 Device 000: ID 18d1:9302 Google Inc. Composite Device
Bus 000 Device 000: ID 18d1:9302 Google Inc. USB 3.1 Bus

Link to firmware file used:
https://test.geogebra.org/~mike/coral/firmware.bin
https://github.com/google-coral/libedgetpu/blob/efb73cc94dac29dc590a243109d4654c223e008c/driver/usb/apex_latest_single_ep.bin

webusb broken in new chrome

Hi devanlai,
The latest version of chrome has broken webdfu

When we connect to the device we get error:
InvalidStateError: The device must have a configuration selected.

It works fine with chrome 60.x.x.x.x.x but not with 70.x.x.x.x.x
Any ideas?
Thanks

Issue SET_INTERFACE even if alt=0

Some devices with several alt settings for the DFU interface expect a call to SET_INTERFACE even if the alt settings you want to use is the default 0 one.

dfu-util issues SET_INTERFACE all the time to deal with that, but seems the web impl doesn.

Please add URL parameters for customized firmware upgrade

The vid=xyz URL param is very useful as it allows to construct less confusing URLs for end users.

Please add similar params for the other aspect of the DFU flashing configuraiton:

  1. DFU Interface selection. For example, a substring or a regex that matches the interface name. In my example of an STM32F401CE, it will be "0x08000000", and since it will match exactly one interface, the existing code will skip the interface selection question.

DFU: cfg=1, intf=0, alt=0, name="@internal Flash /0x08000000/04016Kg,01064Kg,03128Kg"
DFU: cfg=1, intf=0, alt=1, name="@option Bytes /0x1FFFC000/01
016 e"
DFU: cfg=1, intf=0, alt=2, name="@otp Memory /0x1FFF7800/01512 e,01016 e"
DFU: cfg=1, intf=0, alt=3, name="@device Feature/0xFFFF0000/01*004 e"

  1. Binary file. That is a path to a URL that contains the binary file, for example on github. In my case it can be https://github.com/zapta/simple_stepper_motor_analyzer/raw/master/releases/firmware-2021-02-01.bin

This will also allow to have on my web page multiple links, for different versions, such as stable, nightly, etc.

  1. Board specific instructions. A url to a simple html page that is displayed as a frame and include board specific instructions. In my case (using WeAct blackpill), it will be a text explaining to hold down the Boot0 button while connecting the USB cable, maybe also with a picture or two.

Having such a customizable page on github will be a great tool for makers and small developers that are either don't know javascript enough to customize or don't want to fork away to benefit from all future improvements.

Decouple the library from the example

The current demo works really well, but it is rather painful to reuse.

My understanding is that dfu.js and dfuse.js were thought as an easily-reusable library, and that dfu-util.js is responsible for hooking up the library to the demo HTML.

The problem is, dfu-util.js still does some heavy lifting : for example, see the connect function which tries to figure out if a given device is DfuSe-compliant or not. Re-using this code currently means duplicating this function.

It would be very useful to have a minimal UI-less demo to make sure reusing this library is easy.

Help- Parameter settings

Hi,

I am using an STM32L0 board. I am able to put it in DFU mode and can see and connect to it using the demo site (Windows, Edge on Windows 10).
Once connected, I see several interfaces, and select the flash memory.
I am not sure what parameters to use for the DFuse start, and the upload size.
I am also not sure which format is needed for the file download (to USB device). I am currently using the IAR for development and St Mx programmer to upload the .hex firmware file generated by IAR.
I highly appreciate your help.
Thanks,
Ashraf

Running dfu-util demo locally

I'm pretty new to the concepts of WebUSB and webdfu, and web development in general. I have the demo working with my STM32F0 device - I am able to flash the device with a .bin file using your tool on chrome. However, if I download the repo and try to run the demo locally (opening dfu-util/index.html on chrome) the webpage is no longer able to connect to my STM32 device. When I click on the 'connect' button, I see the STM32 device listed in a chrome popup dialog but when I select it the 'status' text on the webpage changes to "NotFoundError: No device selected." I have tried running the demo locally, then immediately tried it online and it always works online. Is there something obvious I am missing here? Why does the dfu-util demo not work when run locally?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.