Skip to main content

Crate dfu_core

Crate dfu_core 

Source
Expand description

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

FeatureDescription
(none)no_std core: state machine, DfuIo, DfuSansIo, FunctionalDescriptor, MemoryPage, mem
stdAdds MemoryLayout, std::error::Error impls, DfuProtocol::new(), and DfuSync
asyncAdds 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

Modules§

asynchronousasync
Generic asynchronous implementation.
detach
Commands to detach the device.
download
Commands to download a firmware into the device.
functional_descriptor
Functional descriptor.
get_status
Commands to get the status of the device.
memory_layout
Memory layout.
synchronousstd
Generic synchronous implementation.

Structs§

DfuSansIo
Use this struct to create state machines to make operations on the device.
UsbReadControl
Usb read request
UsbWriteControl
Usb write request

Enums§

DfuProtocol
The DFU protocol variant in use
Error
State
DFU State.
Status
DFU Status.

Traits§

ChainedCommand
A trait for commands that be chained into another.
DfuIo
Trait to implement lower level communication with a USB device.