{"record":{"id":"ee0497c65cd60ff5","repo":"embassy-rs/embassy","slug":"pka-initialization-failed","errorCode":null,"errorMessage":"PKA initialization failed","messagePattern":"PKA initialization failed","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"embassy-stm32/src/pka/mod.rs","lineNumber":840,"sourceCode":"    const RAM_ERASE_TIMEOUT: u32 = 100_000;\n\n    /// The value the engine leaves in a result or error word to report success.\n    #[cfg(not(pka_v1c))]\n    const SUCCESS: u32 = 0xD60D;\n    #[cfg(pka_v1c)]\n    const SUCCESS: u32 = 0;\n\n    fn new_inner(peripheral: Peri<'d, T>) -> Self {\n        rcc::enable_and_reset::<T>();\n\n        T::Interrupt::unpend();\n        unsafe { T::Interrupt::enable() };\n\n        let mut s = Self {\n            _peripheral: peripheral,\n            _marker: PhantomData,\n        };\n        s.ensure_init_blocking().expect(\"PKA initialization failed\");\n        s\n    }\n\n    // ========================================================================\n    // ECDSA Operations\n    // ========================================================================\n\n    fn prepare_ecdsa_verify(\n        &mut self,\n        curve: &EcdsaCurveParams,\n        public_key: &EcdsaPublicKey,\n        signature: &EcdsaSignature,\n        message_hash: &[u8],\n    ) -> Result<(), Error> {\n        let modulus_size = curve.p_modulus.len();\n        let order_size = curve.order.len();\n\n        // Validate sizes","sourceCodeStart":822,"sourceCodeEnd":858,"githubUrl":"https://github.com/embassy-rs/embassy/blob/463a07b963419a1bfe61d5d597c44acb810afb8b/embassy-stm32/src/pka/mod.rs#L822-L858","documentation":"Pka::new_inner (the blocking constructor path) runs ensure_init_blocking() and unwraps the Result with expect(\"PKA initialization failed\"). Init includes enabling clocks, resetting the accelerator, enabling the interrupt, and checking the PKA's mode; failure (Err from hardware init) is escalated to a panic at construction time instead of being returned to the caller.","triggerScenarios":"Constructing the PKA (via new/new_blocking leading to new_inner) when the underlying hardware init returns Err — e.g. PKA IP in an unexpected state, restricted/limited mode detected where unsupported, or reset/enable sequence failing on the given chip revision.","commonSituations":"Using a chip variant whose PKA is limited-mode (ECDSA-verify only) with a driver build expecting full mode; enabling the peripheral before its kernel clock is configured; silicon in a bad state after a warm reset without a proper PKA reset sequence.","solutions":["Check the returned error by calling ensure_init_blocking-style init yourself or use a constructor variant returning Result, so you can log the real cause.","Verify the PKA kernel clock is enabled in RCC before constructing the driver.","Confirm the chip's PKA mode is supported by the driver (limited-mode chips are rejected by an assert in with_pka); use a supported variant or software crypto for unsupported ops.","Perform a full peripheral reset (RCC reset + power-up sequence) before init if the hardware was left in a bad state."],"exampleFix":"// before\nlet pka = Pka::new_blocking(p.PKA, Irqs); // panics on init failure\n\n// after\nmatch pka_init(&mut p.PKA, Irqs) { // API that surfaces the Result\n    Ok(pka) => info!(\"PKA ready\"),\n    Err(e) => defmt::error!(\"PKA init failed: {:?}\", e),\n}","handlingStrategy":"validation","validationCode":"// Before constructing PKA, ensure clocks and supported mode:\n// RCC: enable PKA kernel clock; check chip variant is not limited-mode-only\n// If a Result-returning init exists, use it instead of the panicking constructor.","typeGuard":null,"tryCatchPattern":"// Prefer an API variant that returns Result over new_inner's expect, when available:\nmatch pka.ensure_init_blocking() {\n    Ok(_) => info!(\"pka init ok\"),\n    Err(e) => defmt::error!(\"pka init failed: {:?}\", e),\n}","preventionTips":["Enable the PKA kernel clock in RCC before constructing the driver.","Verify your chip variant's PKA mode is fully supported by the driver.","Prefer Result-returning constructors over panicking ones in production firmware."],"tags":["embedded","stm32","pka","crypto","initialization","panic"],"backgroundTag":"module-init-failed","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"}