{"record":{"id":"e30df3e83723dd55","repo":"embassy-rs/embassy","slug":"incorrect-vrs-setting","errorCode":null,"errorMessage":"Incorrect Vrs setting!","messagePattern":"Incorrect Vrs setting!","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"embassy-stm32/src/vrefbuf/mod.rs","lineNumber":21,"sourceCode":"\nuse embassy_hal_internal::PeripheralType;\nuse stm32_metapac::vrefbuf::vals::*;\n\nuse crate::Peri;\n\n/// Voltage Reference (VREFBUF) driver.\npub struct VoltageReferenceBuffer<'d, T: Instance> {\n    vrefbuf: PhantomData<&'d mut T>,\n}\n\n#[cfg(rcc_wba)]\nfn get_refbuf_trim(voltage_scale: Vrs) -> usize {\n    match voltage_scale {\n        Vrs::Vref0 => 0x0BFA_07ABusize,\n        Vrs::Vref1 => 0x0BFA_07AAusize,\n        Vrs::Vref2 => 0x0BFA_07A9usize,\n        Vrs::Vref3 => 0x0BFA_07A8usize,\n        _ => panic!(\"Incorrect Vrs setting!\"),\n    }\n}\n\nimpl<'d, T: Instance> VoltageReferenceBuffer<'d, T> {\n    /// Creates an VREFBUF (Voltage Reference) instance with a voltage scale and impedance mode.\n    ///\n    /// [Self] has to be started with [Self::new()].\n    pub fn new(_instance: Peri<'d, T>, voltage_scale: Vrs, impedance_mode: Hiz) -> Self {\n        #[cfg(rcc_wba)]\n        {\n            use crate::pac::RCC;\n            RCC.apb7enr().modify(|w| w.set_vrefen(true));\n            // This is an errata for WBA6 devices. VREFBUF_TRIM value isn't set correctly\n            // [Link explaining it](https://www.st.com/resource/en/errata_sheet/es0644-stm32wba6xxx-device-errata-stmicroelectronics.pdf)\n            unsafe {\n                use crate::pac::VREFBUF;\n                let addr = get_refbuf_trim(voltage_scale);\n                let buf_trim_ptr = core::ptr::with_exposed_provenance::<u32>(addr);","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/embassy-rs/embassy/blob/463a07b963419a1bfe61d5d597c44acb810afb8b/embassy-stm32/src/vrefbuf/mod.rs#L3-L39","documentation":"The VREFBUF (voltage reference buffer) driver panics in get_refbuf_trim when the requested Vrs voltage scale is not one of the four supported Vref0..Vref3 settings. The trim value is looked up from a fixed table, and any other Vrs variant has no trim constant, so the driver refuses to construct rather than program wrong calibration data.","triggerScenarios":"Calling VoltageReferenceBuffer::new with a voltage_scale value outside Vrs::Vref0, Vrs::Vref1, Vrs::Vref2, or Vrs::Vref3 — typically a non-exhaustive Vrs variant (e.g. a newer/scaled enum value) unsupported by the current HAL.","commonSituations":"Targeting a newer STM32 family whose Vrs enum has extra variants while using an embassy-stm32 version whose trim table predates them; copying example code that used Vrs for another chip; typo'ing or casting an arbitrary integer into Vrs.","solutions":["Pass only Vrs::Vref0 through Vrs::Vref3 to VoltageReferenceBuffer::new.","Update embassy-stm32 to the latest version so newer Vrs variants have trim values.","If you need an unsupported scale, disable the VREFBUF (bypass mode) instead of constructing the driver."],"exampleFix":"// before\nlet vref = VoltageReferenceBuffer::new(p.VREFBUF, Vrs::Vref5, Impedance::High);\n// after\nlet vref = VoltageReferenceBuffer::new(p.VREFBUF, Vrs::Vref2, Impedance::High);","handlingStrategy":"validation","validationCode":"use embassy_stm32::vrefbuf::Vrs;\nfn is_supported_vrs(v: Vrs) -> bool {\n    matches!(v, Vrs::Vref0 | Vrs::Vref1 | Vrs::Vref2 | Vrs::Vref3)\n}\nassert!(is_supported_vrs(scale), \"Vrs not supported by this HAL trim table\");","typeGuard":"fn is_supported_vrs(v: Vrs) -> bool {\n    matches!(v, Vrs::Vref0 | Vrs::Vref1 | Vrs::Vref2 | Vrs::Vref3)\n}","tryCatchPattern":null,"preventionTips":["Only pass Vrs variants from the HAL's own enum that map to Vref0..Vref3","Pin your embassy-stm32 version to one tested against your target MCU family","Prefer bypass/disabling VREFBUF when an exotic scale is needed"],"tags":["embedded","stm32","panic","config"],"backgroundTag":"invalid-enum-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"}