dfu-core 0.11.0

Sans IO core library (traits and tools) for DFU
Documentation

Rust Latest Version License Docs.rs Keep a Changelog Dependency Status

dfu-core

A sans-IO, no_std-compatible core library implementing the DFU protocol state machine.

The library drives the full DFU protocol logic — including DFU 1.1 and the STM32 DfuSe extension — but never touches USB directly. Instead, you supply a transport by implementing DfuIo (or DfuAsyncIo), and the library tells you exactly which control transfers to perform and in what order. This makes it runtime-agnostic and usable in no_std environments.

If you are looking for a ready-to-use CLI tool or a higher-level crate that already has a USB backend wired up, see:

Feature Flags

Feature Description
(none) no_std core: state machine, DfuIo, DfuSansIo, FunctionalDescriptor, MemoryPage, mem
std Adds MemoryLayout, std::error::Error impls, DfuProtocol::new(), and DfuSync
async Adds DfuAsyncIo and DfuAsync (implies std)

API Overview

Implement one of these traits to provide the USB transport:

  • trait DfuIo — synchronous transport (control reads, control writes, USB reset)
  • trait DfuAsyncIo — async transport, same operations plus a sleep method (requires feature async)

Choose your level of abstraction for the protocol logic:

  • struct DfuSync — high-level synchronous wrapper; call download(), download_all(), or download_from_slice() and it handles the rest (requires feature std)
  • struct DfuAsync — high-level async wrapper, mirrors DfuSync (requires feature async)
  • struct DfuSansIo — low-level sans-IO state machine for no_std or when you need explicit control over each USB transaction; returns typed command objects (UsbWriteControl, UsbReadControl) that you execute yourself

Supporting types:

  • enum DfuProtocol — selects between DFU 1.1 (Dfu) and STM32 DfuSe (Dfuse)
  • struct FunctionalDescriptor — parsed from the extra bytes of a USB DFU functional descriptor; drives protocol decisions (transfer size, detach behaviour, manifestation tolerance)
  • type MemoryPage and type mem — primitives representing the memory layout of the device (analogous to char and str)
  • struct MemoryLayout — owned, heap-allocated memory layout that can parse the STM32 memory layout interface string (requires feature std)

Features

  • no_std compatible
  • sync and async compatible
  • write a firmware into a device (DFU download)
  • read a firmware from a device (DFU upload)
  • minimal dependencies
  • uses a state machine to ensure implementations are correct

DFU Specifications

This crate is based on the following specifications:

License

MIT OR Apache-2.0