uftwo
For working with the UF2 file format.
Why the name? uf2 was already taken and appears to be abandoned.
Features
- Stream-based API: Read and write UF2 data from/to any
Read/Writeimplementor - no-std support: Core functionality works without std (no_std + alloc)
- Flexible: Works with files, memory buffers, network streams, etc.
- Comprehensive: Supports all UF2 features including extensions, checksums, and family IDs
Feature Flags
std- Enables writer functionality and std-dependent featuresdefmt- Enables defmtFormaton relevant types
Using the Library
Basic Usage
cargo add uftwo
Reading UF2 Files
use ;
use File;
use Read;
// Read from a file
let mut file = open.unwrap;
let uf2_file = from_stream.unwrap;
// Or read from bytes
let bytes = read.unwrap;
let uf2_file = from_bytes.unwrap;
// Access blocks
for block in uf2_file.blocks
// Extract payload
if let Some = uf2_file.get_payload
Writing UF2 Files
use ;
use File;
use Write;
// Create a new UF2 file
let mut uf2_file = new;
// Add payload with optional family ID
uf2_file.add_payload.unwrap;
// Write to a file
let mut file = create.unwrap;
uf2_file.to_writer.unwrap;
// Or write to bytes
let bytes = uf2_file.to_bytes;
Full Spec Compliance
use ;
let mut uf2_file = new;
// Add binary with full UF2 spec compliance
uf2_file.add_binary.unwrap;
// This creates blocks with:
// - Proper checksums (MD5)
// - Target page size extensions
// - Semantic version extensions
// - Full spec compliance
Module Structure
block- Core UF2 block types and parsinguf2file- UF2 file structure and manipulationreader- Stream-based reading functionality (no_std compatible)writer- Stream-based writing functionality (requires std feature)
License
This project is licensed under the MPL-2.0.