1.0.0 • Published 9 months ago

dfu-next v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

WebDFU

NPM package CI in main branch

WebDFU — driver for working with DFU and DfuseDriver in a browser over Web USB or Web Bluetooth.

  • Reading and writing the current device firmware by DFU 1.1
  • ST DfuSe download and upload firmware To be re-implemented.
  • Switching from the runtime configuration to the DFU bootloader (DFU detach)

Install

npm i dfu-next

Usage

Full example in: webdfu/demo

Basic example:

import { DeviceBootstrapper } from "dfu";


const connect = async () => {
    const device = await navigator.usb.requestDevice({ filters: [] });

    const bootstrapper = new DeviceBootstrapper(device);

    const dfuDevice = await bootstrapper.init();

    //  Read firmware from devie
    const readEvents = dfuDevice.beginRead();
    readEvents.on("read/finish", (bytesRead, blocks, data) => {
        // save the data (blob)
        console.log("Successfully read firmware from device")
    })

    // Write firmware to device
    const firmwareFile = new ArrayBuffer(1024);
    const writeEvents = dfuDevice.beginWrite(firmwareFile);

    writeEvents.on("write/finish", (bytesSent) => {
        console.log("Sucessfully written new firmware to device.")
    })
}

/*
  The browser's security policy requires that WebUSB be accessed only by an explicit user action.
  Add the button in your html and run the WebDFu after click in button.
  In HTML: <button id="connect-button">Connect</button>
*/
document.getElementById("connect-button").addEventListener("click", connect);```
1.0.0

9 months ago