https://github.com/flipperdevices/webdfu
Driver for working with DFU in a browser over WebUSB
https://github.com/flipperdevices/webdfu
dfu dfuse flipper
Last synced: about 1 year ago
JSON representation
Driver for working with DFU in a browser over WebUSB
- Host: GitHub
- URL: https://github.com/flipperdevices/webdfu
- Owner: flipperdevices
- License: mit
- Created: 2021-05-26T17:40:42.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2022-02-02T12:53:17.000Z (over 4 years ago)
- Last Synced: 2024-10-16T12:20:12.819Z (over 1 year ago)
- Topics: dfu, dfuse, flipper
- Language: TypeScript
- Homepage:
- Size: 594 KB
- Stars: 36
- Watchers: 6
- Forks: 9
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# WebDFU
[](https://www.npmjs.com/package/dfu)
[](https://github.com/Flipper-Zero/webdfu/actions/workflows/main.yml)
WebDFU — driver for working with DFU and DfuseDriver in a browser over [Web USB](https://wicg.github.io/webusb/) or [Web Bluetooth](https://webbluetoothcg.github.io/web-bluetooth/).
- Reading and writing the current device firmware by [DFU 1.1](https://www.usb.org/sites/default/files/DFU_1.1.pdf)
- [ST DfuSe](http://dfu-util.sourceforge.net/dfuse.html) download and upload firmware
- Switching from the runtime configuration to the DFU bootloader (DFU detach)
## Install
```shell
npm i dfu
```
## Usage
Full example in: [webdfu/demo](https://github.com/Flipper-Zero/webdfu/tree/main/demo)
Basic example:
```javascript
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: Connect
*/
document.getElementById("connect-button").addEventListener("click", connect);
```