uf-crsf

A no_std Rust library for parsing the TBS Crossfire protocol, designed for embedded environments without an allocator.
CRSF is widely used in FPV drones and other RC aircraft, connecting radios (like EdgeTX based), TBS Crossfire and ExpressLRS radio links,
receivers, and flight controllers. It carries RC channel data and telemetry such as battery voltage, GPS position, and link statistics.
This library provides a two-layer API:
- A low-level layer for raw packet parsing from a byte stream.
- A higher-level layer that converts raw packets into idiomatic Rust structs.
Features
no_std and allocator-free for embedded systems.
- Two-layer API for flexible parsing.
- Most complete crossfire protocol implementation in Rust.
- Zero copy with spill over buffer, when packet divided between two reads.
- Supports a wide range of CRSF packets.
- IO and MCU agnostic.
- Minimal dependencies.
Note
Library is under active development and testing, API might change at any time.
Installation
Add uf-crsf to your Cargo.toml:
[dependencies]
uf-crsf = "0.6"
Or use the command line:
cargo add uf-crsf
Usage
Here is a basic example of how to parse a CRSF packet from a byte array:
use uf_crsf::CrsfParser;
fn main() {
let mut parser = CrsfParser::new();
// A complete CRSF frame containing RC channels
let buf: [u8; 26] = [
0xC8, // Address
0x18, // Length of type, payload, and CRC
0x16, // Type (RC Channels)
// Payload (22 bytes)
0x03, 0x1F, 0x58, 0xC0, 0x07, 0x16, 0xB0, 0x80, 0x05, 0x2C, 0x60, 0x01, 0x0B, 0xF8, 0xC0,
0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC,
0x42, // CRC
];
let mut input = buf.as_slice();
for item in parser.iter_packets(&mut input) {
match item {
Ok(p) => println!("{:?}", p),
Err(e) => eprintln!("Error parsing packet: {:?}", e),
}
}
}
Keep the same parser across input chunks. Exhaust iter_packets for each chunk
so it can retain a trailing partial frame for the next chunk. Errors are yielded
as items; continue iterating after an error to resume scanning for valid frames.
If you stop early, keep the updated input cursor to resume unread bytes later.
Use next_raw_packet to inspect validated frames without decoding their payloads:
use uf_crsf::CrsfParser;
fn main() {
let bytes = [
0xC8, 0x0C, 0x14, 0x10, 0x13, 0x63, 0x97,
0x01, 0x02, 0x03, 0x08, 0x58, 0x94, 0xFC,
];
let mut parser = CrsfParser::new();
// Chunk boundaries need not align with frame boundaries.
for chunk in bytes.chunks(5) {
let mut input = chunk;
while let Some(result) = parser.next_raw_packet(&mut input) {
match result {
Ok(frame) => println!(
"type={:#04X}, payload={:?}",
frame.raw_packet_type(),
frame.payload(),
),
Err(error) => eprintln!("Framing error: {:?}", error),
}
}
}
}
Complete frames borrow directly from the input when contiguous; split frames
borrow from the parser’s internal buffer. Release each raw frame before calling
next_raw_packet again. Keep calling until it returns None, even if the input
cursor is empty: recovery can yield frames or errors from retained bytes.
See the examples for desktop serial readers, including
blocking and async wrappers and their required feature flags.
License
This project is licensed under the Apache 2.0. See the LICENSE file for details.
Protocol Specification
评论