dfu-next

1.0.0 • Public • Published

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);```

/dfu-next/

    Package Sidebar

    Install

    npm i dfu-next

    Weekly Downloads

    0

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    109 kB

    Total Files

    44

    Last publish

    Collaborators

    • prouser123