embassy-rs/embassy · error

invalid burst size

Error message

invalid burst size

What it means

This panic is raised by the From<Burst> for vals::Burst conversion in the STM32 DMA (bDMA) driver when a Burst value outside the supported Single/Incr4/Incr8/Incr16 set is converted for writing into the DMA channel's CR register. It is a compile-time-enumerated enum so in practice this arm is unreachable with the current public enum; the library throws it defensively because the hardware field only supports those four burst configurations. Any Burst variant added later or constructed via transmute from an invalid discriminant lands here.

Solutions

  1. Use only Burst::Single, Burst::Incr4, Burst::Incr8 or Burst::Incr16 when configuring the DMA channel
  2. Check the embassy-stm32 version/chip support matrix; burst INCR16 etc. may not be supported for your DMA instance
  3. If you patched the enum, extend this match to map the new variant to vals::Burst
  4. File/update an embassy issue for the chip if the hardware supports the variant but the driver does not

Example fix

// before
let burst = Burst::Incr16; // custom-added variant
// after
let burst = Burst::Incr8; // supported: Single | Incr4 | Incr8 | Incr16
Defensive patterns

Strategy: validation

Validate before calling

fn burst_supported(b: Burst) -> bool {
    matches!(b, Burst::Single | Burst::Incr4 | Burst::Incr8 | Burst::Incr16)
}
assert!(burst_supported(cfg.burst), "burst size not supported by bDMA");

Type guard

fn is_supported_burst(b: Burst) -> Option<vals::Burst> {
    match b {
        Burst::Single | Burst::Incr4 | Burst::Incr8 | Burst::Incr16 => Some(b.into()),
        _ => None,
    }
}

Try / catch

// unimplemented!() panics; catch via panic hook only in tests
std::panic::catch_unwind(|| dma.configure(...))

Prevention

When it happens

Trigger: Calling any DMA configure/start API (e.g. dma_bdma channel start) while the channel's configured Burst enum value is a non-exhaustive/unfitted variant other than Single, Incr4, Incr8, or Incr16 — typically only reachable via trait-object/non_exhaustive future variants or transmuted discriminants.

Common situations: Patching the Burst enum to add a new burst size (e.g. Incr32) on newer chip families without updating this conversion; compiling for an MCU where the driver is partially supported; cargo feature or embassy-stm32 version changes that expose more variants.

Related errors


AI-assisted analysis of embassy-rs/embassy@463a07b963 (2026-09-10). Data as JSON: /api/errors/a496e9fa47b9b1b2. Report an issue: GitHub.

Appendix: source

Thrown at embassy-stm32/src/dma/dma_bdma.rs:317

        Incr16,
        /// Incremental burst of 32 beats
        Incr32,
        /// Incremental burst of 64 beats
        Incr64,
        /// Incremental burst of 128 beats
        Incr128,
        /// Incremental burst of 256 beats
        Incr256,
    }

    impl From<Burst> for vals::Burst {
        fn from(burst: Burst) -> Self {
            match burst {
                Burst::Single => vals::Burst::Single,
                Burst::Incr4 => vals::Burst::Incr4,
                Burst::Incr8 => vals::Burst::Incr8,
                Burst::Incr16 => vals::Burst::Incr16,
                _ => unimplemented!("invalid burst size"),
            }
        }
    }

    /// DMA flow control setting.
    #[derive(Debug, Copy, Clone, PartialEq, Eq)]
    #[cfg_attr(feature = "defmt", derive(defmt::Format))]
    pub enum FlowControl {
        /// Flow control by DMA
        Dma,
        /// Flow control by peripheral
        Peripheral,
    }

    impl From<FlowControl> for vals::Pfctrl {
        fn from(flow: FlowControl) -> Self {
            match flow {
                FlowControl::Dma => vals::Pfctrl::Dma,

View on GitHub (pinned to 463a07b963)