{"record":{"id":"7c12610bd6efc69b","repo":"embassy-rs/embassy","slug":"bad-mode-7c1261","errorCode":null,"errorMessage":"Bad mode","messagePattern":"Bad mode","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"embassy-stm32/src/can/bxcan/mod.rs","lineNumber":1130,"sourceCode":"                                _ = Registers(T::regs()).transmit(&frame);\n                            }\n                            Err(_) => {\n                                break;\n                            }\n                        }\n                    }\n                }\n            }\n        });\n    }\n\n    fn register(&self, arg: &core::task::Waker) {\n        match self {\n            TxMode::NonBuffered(waker) => {\n                waker.register(arg);\n            }\n            _ => {\n                panic!(\"Bad mode\");\n            }\n        }\n    }\n}\n\npub(crate) struct State {\n    pub(crate) rx_mode: RxMode,\n    pub(crate) tx_mode: TxMode,\n    pub err_waker: AtomicWaker,\n    receiver_instance_count: usize,\n    sender_instance_count: usize,\n}\n\nimpl State {\n    pub const fn new() -> Self {\n        Self {\n            rx_mode: RxMode::NonBuffered(AtomicWaker::new()),\n            tx_mode: TxMode::NonBuffered(AtomicWaker::new()),","sourceCodeStart":1112,"sourceCodeEnd":1148,"githubUrl":"https://github.com/embassy-rs/embassy/blob/463a07b963419a1bfe61d5d597c44acb810afb8b/embassy-stm32/src/can/bxcan/mod.rs#L1112-L1148","documentation":"TxMode::register only supports the NonBuffered(waker) variant; when the transmit mode is Buffered or AnyId, registering a waker panics with 'Bad mode'. It surfaces when an async send on a bxCAN transmitter polls while the TX mode is not NonBuffered — the transmit state machine variant does not match the API used.","triggerScenarios":"Polling/awaiting an async transmit whose TxMode::register is called while state.tx_mode is a Buffered/AnyId variant, typically after mode reconfiguration or mixing buffered transmitter APIs with non-buffered async sends.","commonSituations":"Holding a Transmitter handle across a runtime reconfiguration; using async send on a transmitter created in buffered mode; task races where one task re-splits the CAN while another transmits.","solutions":["Match the transmit API to the configured mode: use queue-based send for Buffered mode, async send only for NonBuffered","Drop all Transmitter handles before changing CAN configuration; never reconfigure while transmissions are in flight","If reproducing with a single fixed configuration and current embassy-stm32, file a driver bug — this is an internal invariant violation"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Rust: use the buffered transmitter's queue send API when split in buffered mode; reserve async send for NonBuffered transmitters.","typeGuard":null,"tryCatchPattern":"// Rust: panics are not recoverable in no_std firmware; ensure transmit tasks are terminated before reconfiguration via structured concurrency or explicit abort.","preventionTips":["Match transmit API to configured TX mode","Drop transmitters before re-splitting or changing mode","Single owner for all CAN reconfiguration"],"tags":["embedded","stm32","can","async","panic","concurrency"],"backgroundTag":"invalid-state-transition","analyzedSha":"463a07b963419a1bfe61d5d597c44acb810afb8b","analyzedAt":"2026-09-10T13:38:26.660Z","contentChangedAt":"2026-09-10T13:38:26.660Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}