embassy-rs/embassy · error
DataLength > 64
Error message
DataLength > 64
What it means
`DataLength::new` panics when an FDCAN frame is given a payload length greater than 64 bytes. The CAN-FD protocol allows at most 64 data bytes, so lengths above 64 are rejected as invalid rather than truncated.
Solutions
- Slice the payload into chunks of at most 64 bytes and send multiple frames.
- Validate `len <= 64` before calling DataLength::new with FrameFormat::Fdcan.
- Clamp with `len.min(64)` if truncation is acceptable.
Example fix
// before let dl = DataLength::new(buffer.len() as u8, FrameFormat::Fdcan); // after assert!(buffer.len() <= 64, "FD frame payload exceeds 64 bytes"); let dl = DataLength::new(buffer.len() as u8, FrameFormat::Fdcan);
Defensive patterns
Strategy: validation
Validate before calling
fn valid_fd_len(len: u8) -> bool { len <= 64 } Prevention
- Chunk payloads larger than 64 bytes into multiple FD frames.
- Assert buffer lengths at the boundary where user data meets the CAN driver.
- Remember CAN-FD max payload is 64 bytes, not more.
When it happens
Trigger: Calling `DataLength::new(len, FrameFormat::Fdcan)` with `len > 64`; typically while constructing a transmit frame whose source buffer exceeds 64 bytes.
Common situations: Passing a whole application buffer instead of slicing it into CAN-sized chunks; confused protocol limits (thinking FD allows 128 bytes); chunking loop with wrong stride.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.
Related errors
AI-assisted analysis of embassy-rs/embassy@463a07b963 (2026-09-10).
Data as JSON: /api/errors/9f168c8ebf05b4d1.
Report an issue: GitHub.
Appendix: source
Thrown at embassy-stm32/src/can/fd/message_ram/enums.rs:23
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum DataLength {
Classic(u8),
Fdcan(u8),
}
impl DataLength {
/// Creates a DataLength type
///
/// Uses the byte length and Type of frame as input
pub fn new(len: u8, ff: FrameFormat) -> DataLength {
match ff {
FrameFormat::Classic => match len {
0..=8 => DataLength::Classic(len),
_ => panic!("DataLength > 8"),
},
FrameFormat::Fdcan => match len {
0..=64 => DataLength::Fdcan(len),
_ => panic!("DataLength > 64"),
},
}
}
/// Specialised function to create classic frames
pub fn new_classic(len: u8) -> DataLength {
Self::new(len, FrameFormat::Classic)
}
/// Specialised function to create FDCAN frames
pub fn new_fdcan(len: u8) -> DataLength {
Self::new(len, FrameFormat::Fdcan)
}
/// returns the length in bytes
pub fn len(&self) -> u8 {
match self {
DataLength::Classic(l) | DataLength::Fdcan(l) => *l,
}
}View on GitHub (pinned to 463a07b963)