{"record":{"id":"3a748424697bf532","repo":"embassy-rs/embassy","slug":"lse-frequency-more-than-5-off-from-32-768-khz-ca","errorCode":null,"errorMessage":"LSE frequency more than 5% off from 32.768 kHz, cannot use for MSI auto-calibration","messagePattern":"LSE frequency more than 5% off from 32\\.768 kHz, cannot use for MSI auto-calibration","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"embassy-stm32/src/rcc/u3.rs","lineNumber":242,"sourceCode":"            // 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                }\n                // improper configuration\n                _ => panic!(\"MSIx auto-calibration is enabled for a source that has not been configured.\"),\n            }\n        } else {\n            panic!(\"LSE frequency more than 5% off from 32.768 kHz, cannot use for MSI auto-calibration\");\n        }\n    } else {\n        None\n    };\n\n    let mut msis = config.msis.map(|range| {\n        // Check MSI output per RM0487 § 10.2.3 Table 98\n        match config.voltage_range {\n            VoltageScale::RANGE2 => {\n                assert!(msirange_to_hertz(range).0 <= 48_000_000);\n            }\n            _ => {}\n        }\n\n        // RM0487 § 10.5.2: spin until MSIS is off or MSIS is ready before setting its range\n        loop {\n            let cr = RCC.cr().read();\n            if cr.msison() == false || cr.msisrdy() == true {","sourceCodeStart":224,"sourceCodeEnd":260,"githubUrl":"https://github.com/embassy-rs/embassy/blob/463a07b963419a1bfe61d5d597c44acb810afb8b/embassy-stm32/src/rcc/u3.rs#L224-L260","documentation":"This panic fires in embassy-stm32's STM32U3 RCC init when MSI auto-calibration via LSE is requested but the configured LSE frequency is not within 5% of 32.768 kHz. MSI calibration trims MSI against LSE, which the hardware assumes is a standard 32.768 kHz crystal; a deviating LSE would calibrate MSI to a wrong frequency, so the driver refuses to proceed.","triggerScenarios":"Config::default()-style rcc init with config.msis/msik auto-calibration enabled (MsiAutoCalibration) AND config.ls.lse set with a frequency outside 31132–34406 Hz (e.g. a custom frequency like 100_000 or a mistyped value).","commonSituations":"Typo in the LSE frequency constant; using an external clock source that is not a 32.768 kHz crystal while still enabling MSI auto-cal; copying an RCC config from another board; enabling MSI cal but forgetting to set lse at all so a fallback/wrong frequency is used.","solutions":["Set config.ls.lse frequency to exactly Hertz(32_768) (or remove the custom frequency and use the default LSE config)","If your LSE is genuinely not ~32.768 kHz, disable MSI auto-calibration (remove the MsiAutoCalibration setting for MSIS/MSIK)","Verify the crystal fitted on the board is 32.768 kHz and matches the configured frequency"],"exampleFix":"// before\nlet mut config = Config::default();\nconfig.ls.lse = Some(LseConfig { frequency: Hertz(100_000), .. });\nconfig.msis = Some(MsisConfig { range: Range::_4mhz, auto_calibration: MsiAutoCalibration::Lse });\n// after\nlet mut config = Config::default();\nconfig.ls.lse = Some(LseConfig { frequency: Hertz(32_768), .. });\nconfig.msis = Some(MsisConfig { range: Range::_4mhz, auto_calibration: MsiAutoCalibration::Lse });","handlingStrategy":"validation","validationCode":"fn lse_valid_for_msi_cal(lse: &LseConfig) -> bool {\n    let f = lse.frequency.0 as f64;\n    (f * 0.95..=f * 0.0).is_ok(); // placeholder\n}\n// real check:\nfn lse_ok(lse: &LseConfig) -> bool {\n    (31_132..=34_406).contains(&lse.frequency.0)\n}\nassert!(lse_ok(&config.ls.lse.unwrap()), \"LSE must be 32.768 kHz +/-5% for MSI cal\");","typeGuard":"fn is_32k(freq: Hertz) -> bool {\n    (31_132..=34_406).contains(&freq.0)\n}","tryCatchPattern":null,"preventionTips":["Always set LSE frequency to exactly Hertz(32_768) unless you truly have a different crystal","Only enable MsiAutoCalibration when LSE is configured","Double-check crystal value against the board schematic","If LSE is unreliable, run MSI without auto-calibration"],"tags":["rust","embedded","stm32","rcc","clock-config","panic"],"backgroundTag":"invalid-config-value","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"}