Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
/ uf2 Public

USB Flashing Format (UF2) JavaScript Library

License

Notifications You must be signed in to change notification settings

wokwi/uf2

Repository files navigation

USB Flashing Format (UF2) JavaScript Library

JavaScript implementation of the UF2 file format

NPM Version License: MIT Types: TypeScript

Usage example

const fs = require('fs');
const { decodeBlock, familyMap } = require('uf2');
const file = fs.openSync('blink.uf2', 'r');
const buffer = new Uint8Array(512);
while (fs.readSync(file, buffer) === buffer.length) {
 const block = decodeBlock(buffer);
 const family = familyMap.get(block.boardFamily) || 'unknown';
 const { totalBlocks, blockNumber, flashAddress, payload } = block;
 const hexAddress = '0x' + flashAddress.toString(16);
 console.log(`Block ${blockNumber + 1}/${totalBlocks} @${hexAddress}, Family: ${family}`);
 // Do something with payload...
}
fs.closeSync(file);

For more examples, see the unit tests file.

License

Copyright (C) 2021 Uri Shaked. The code is released under the terms of the MIT license.

About

USB Flashing Format (UF2) JavaScript Library

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

AltStyle によって変換されたページ (->オリジナル) /