{"record":{"id":"b6322aaaa11112e5","repo":"embassy-rs/embassy","slug":"lse-must-be-configured-for-msi-auto-calibration","errorCode":null,"errorMessage":"LSE must be configured for MSI auto-calibration","messagePattern":"LSE must be configured for MSI auto-calibration","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"embassy-stm32/src/rcc/u3.rs","lineNumber":219,"sourceCode":"        VoltageScale::RANGE2 => {\n            if PWR.vosr().read().r1en() {\n                while !PWR.vosr().read().r1rdy() {}\n            }\n            PWR.vosr().modify(|w| {\n                w.set_r2en(true);\n                w.set_r1en(false);\n            });\n            while !PWR.vosr().read().r2rdy() {}\n        }\n    }\n\n    let lse_calibration_freq = if config.auto_calibration != MsiAutoCalibration::Disabled {\n        // LSE must be configured and peripherals clocked for MSI auto-calibration\n        let lse_config = config\n            .ls\n            .lse\n            .clone()\n            .expect(\"LSE must be configured for MSI auto-calibration\");\n        assert!(lse_config.peripherals_clocked);\n\n        // Expect less than +/- 5% deviation for LSE frequency\n        if (31_100..=34_400).contains(&lse_config.frequency.0) {\n            // Check that the calibration is applied to an active clock\n            match (\n                config.auto_calibration.base_mode(),\n                config.msis.is_some(),\n                config.msik.is_some(),\n            ) {\n                (MsiAutoCalibration::MSIS, true, _) => {\n                    // MSIS is active and using LSE for auto-calibration\n                    Some(lse_config.frequency)\n                }\n                (MsiAutoCalibration::MSIK, _, true) => {\n                    // MSIK is active and using LSE for auto-calibration\n                    Some(lse_config.frequency)\n                }","sourceCodeStart":201,"sourceCodeEnd":237,"githubUrl":"https://github.com/embassy-rs/embassy/blob/463a07b963419a1bfe61d5d597c44acb810afb8b/embassy-stm32/src/rcc/u3.rs#L201-L237","documentation":"On STM32 U3 series, enabling MSI auto-calibration (MSIRC calibration against LSE) requires a configured LSE clock. The rcc `init` unwraps `config.ls.lse` with `.expect`, panicking if it is `None`. Auto-calibration works by measuring MSI against the 32.768 kHz LSE, so LSE must exist and be routed to peripherals.","triggerScenarios":"Calling `rcc::init` with a `Config` where `auto_calibration` is not `MsiAutoCalibration::Disabled` but `ls.lse` is `None`.","commonSituations":"Enabling MSI auto-calibration on a chip/board without an LSE crystal (or with LSE not configured in RCC config); forgetting that LSE must also have `peripherals_clocked: true` (enforced by the following assert).","solutions":["Add an LSE configuration to the RCC config, e.g. `ls: DefaultLse { lse: Some(LseConfig { frequency: Hertz(32_768), peripherals_clocked: true, .. }) }`","Or explicitly disable auto-calibration: `auto_calibration: MsiAutoCalibration::Disabled`","Ensure `peripherals_clocked` is true on the LSE config so calibration has an active clock"],"exampleFix":"// before\nrcc::init(rcc::Config { auto_calibration: MsiAutoCalibration::Lse, ..Default::default() });\n// after\nrcc::init(rcc::Config {\n    auto_calibration: MsiAutoCalibration::Lse,\n    ls: rcc::LsConfig::default_lse(Some(rcc::LseConfig { peripherals_clocked: true, ..Default::default() })),\n    ..Default::default()\n});","handlingStrategy":"validation","validationCode":"assert!(\n    config.auto_calibration == MsiAutoCalibration::Disabled\n        || config.ls.lse.is_some(),\n    \"MSI auto-calibration requires an LSE config\"\n);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Enable auto-calibration only on boards with a 32.768 kHz LSE crystal","Set peripherals_clocked: true on the LSE config when auto-calibrating","Default auto_calibration to Disabled unless LSE is verified"],"tags":["embedded","rcc","msi","lse","panic"],"backgroundTag":"missing-required-config-field","analyzedSha":"463a07b963419a1bfe61d5d597c44acb810afb8b","analyzedAt":"2026-09-10T13:38:26.660Z","contentChangedAt":"2026-09-10T13:38:26.660Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}