Git Product home page Git Product logo

webdfu's Introduction

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
  • Switching from the runtime configuration to the DFU bootloader (DFU detach)

Install

npm i dfu

Usage

Full example in: webdfu/demo

Basic example:

import { WebDFU } from "dfu";

async function connect() {
  // Load the device by WebUSB
  const selectedDevice = await navigator.usb.requestDevice({ filters: [] });

  // Create and init the WebDFU instance
  const webdfu = new WebDFU(selectedDevice, { forceInterfacesName: true });
  await webdfu.init();

  if (webdfu.interfaces.length == 0) {
    throw new Error("The selected device does not have any USB DFU interfaces.");
  }

  // Connect to first device interface
  await webdfu.connect(0);

  console.log({
    Version: webdfu.properties.DFUVersion.toString(16),
    CanUpload: webdfu.properties.CanUpload,
    CanDownload: webdfu.properties.CanDownload,
    TransferSize: webdfu.properties.TransferSize,
    DetachTimeOut: webdfu.properties.DetachTimeOut,
  });

  // Read firmware from device
  try {
    const firmwareFile = await webdfu.read();

    console.log("Read: ", firmwareFile);
  } catch (error) {
    console.error(error);
  }

  // Write firmware in device
  try {
    // Your firmware in binary mode
    const firmwareFile = new ArrayBuffer("");
    await webdfu.write(1024, firmwareFile);

    console.log("Written!");
  } catch (error) {
    console.error(error);
  }
}

/*
  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);

webdfu's People

Contributors

aprosvetova avatar nikolay-govorov avatar slipn3r avatar trn1ty 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

webdfu's Issues

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.