{"record":{"id":"715a8e26224b8c7d","repo":"embassy-rs/embassy","slug":"init-called-more-than-once","errorCode":null,"errorMessage":"init called more than once!","messagePattern":"init called more than once!","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"embassy-hal-internal/src/macros.rs","lineNumber":67,"sourceCode":"        }\n\n        impl Peripherals {\n            ///Returns all the peripherals *once*\n            #[inline]\n            pub(crate) fn take() -> Self {\n                critical_section::with(Self::take_with_cs)\n            }\n\n            ///Returns all the peripherals *once*\n            #[inline]\n            pub(crate) fn take_with_cs(_cs: critical_section::CriticalSection) -> Self {\n                #[unsafe(no_mangle)]\n                static mut _EMBASSY_DEVICE_PERIPHERALS: bool = false;\n\n                // safety: OK because we're inside a CS.\n                unsafe {\n                    if _EMBASSY_DEVICE_PERIPHERALS {\n                        panic!(\"init called more than once!\")\n                    }\n                    _EMBASSY_DEVICE_PERIPHERALS = true;\n                    Self::steal()\n                }\n            }\n        }\n\n        impl Peripherals {\n            /// Unsafely create an instance of this peripheral out of thin air.\n            ///\n            /// # Safety\n            ///\n            /// You must ensure that you're only using one instance of this type at a time.\n            #[inline]\n            pub unsafe fn steal() -> Self {\n                Self {\n                    $(\n                        $(#[$cfg])?","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/embassy-rs/embassy/blob/463a07b963419a1bfe61d5d597c44acb810afb8b/embassy-hal-internal/src/macros.rs#L49-L85","documentation":"Panic inside the peripheral-take helper generated by embassy's init macro: a static flag (_EMBASSY_DEVICE_PERIPHERALS) marks whether embassy::init has already handed out the Peripherals struct. A second init attempt finds the flag true and panics, because Peripherals is a singleton that grants exclusive, non-Clone ownership of all device peripherals — handing them out twice would create aliasing mutable hardware access. This is a generic one-time-initialization sentinel guard; the offending input is a second call to embassy::init (directly or via two call sites) on the same device.","triggerScenarios":"Thrown at embassy-hal-internal/src/macros.rs:67 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Call embassy::init exactly once, early in main, and pass the resulting Peripherals down to the rest of the program","Remove duplicate init calls in library/board support crates or examples copied into the project","Structure the code so only main constructs Peripherals and everything else receives them as parameters","If init must be re-runnable (e.g. soft reset), perform a real device reset rather than re-invoking embassy::init"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}