diff options
| author | Gerzain Mata <[email protected]> | 2025-08-12 19:00:38 -0700 |
|---|---|---|
| committer | Gerzain Mata <[email protected]> | 2025-08-12 23:24:08 -0700 |
| commit | ba5201c44f1adf7769d18017db5a3d40b0bd9bce (patch) | |
| tree | 7ebe399e56583b63741d6ca699ccab99aa18261a /embassy-stm32/src | |
| parent | 39e75bb02f0c566b08ba75133c9e67c8d71b5b01 (diff) | |
Added VREFBUF-TRIM manual write. Known errata
Diffstat (limited to 'embassy-stm32/src')
| -rw-r--r-- | embassy-stm32/src/vrefbuf/mod.rs | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/embassy-stm32/src/vrefbuf/mod.rs b/embassy-stm32/src/vrefbuf/mod.rs index f614fcf99..5c7dbfa50 100644 --- a/embassy-stm32/src/vrefbuf/mod.rs +++ b/embassy-stm32/src/vrefbuf/mod.rs | |||
| @@ -1,5 +1,4 @@ | |||
| 1 | //! Voltage Reference Buffer (VREFBUF) | 1 | //! Voltage Reference Buffer (VREFBUF) |
| 2 | // use core::ptr::{read_volatile, write_volatile}; | ||
| 3 | use core::marker::PhantomData; | 2 | use core::marker::PhantomData; |
| 4 | 3 | ||
| 5 | use embassy_hal_internal::PeripheralType; | 4 | use embassy_hal_internal::PeripheralType; |
| @@ -12,6 +11,26 @@ pub struct VoltageReferenceBuffer<'d, T: Instance> { | |||
| 12 | vrefbuf: PhantomData<&'d mut T>, | 11 | vrefbuf: PhantomData<&'d mut T>, |
| 13 | } | 12 | } |
| 14 | 13 | ||
| 14 | #[cfg(rcc_wba)] | ||
| 15 | #[repr(usize)] | ||
| 16 | enum VRefBufTrim { | ||
| 17 | VRefBuf3Trim = 0x0BFA_07A8, | ||
| 18 | VRefBuf2Trim = 0x0BFA_07A9, | ||
| 19 | VRefBuf1Trim = 0x0BFA_07AA, | ||
| 20 | VRefBuf0Trim = 0x0BFA_07AB, | ||
| 21 | } | ||
| 22 | |||
| 23 | #[cfg(rcc_wba)] | ||
| 24 | fn get_refbuf_trim(voltage_scale: Vrs) -> VRefBufTrim { | ||
| 25 | match voltage_scale { | ||
| 26 | Vrs::VREF0 => VRefBufTrim::VRefBuf0Trim, | ||
| 27 | Vrs::VREF1 => VRefBufTrim::VRefBuf1Trim, | ||
| 28 | Vrs::VREF2 => VRefBufTrim::VRefBuf2Trim, | ||
| 29 | Vrs::VREF3 => VRefBufTrim::VRefBuf3Trim, | ||
| 30 | _ => panic!("Incorrect Vrs setting!"), | ||
| 31 | } | ||
| 32 | } | ||
| 33 | |||
| 15 | impl<'d, T: Instance> VoltageReferenceBuffer<'d, T> { | 34 | impl<'d, T: Instance> VoltageReferenceBuffer<'d, T> { |
| 16 | /// Creates an VREFBUF (Voltage Reference) instance with a voltage scale and impedance mode. | 35 | /// Creates an VREFBUF (Voltage Reference) instance with a voltage scale and impedance mode. |
| 17 | /// | 36 | /// |
| @@ -21,6 +40,15 @@ impl<'d, T: Instance> VoltageReferenceBuffer<'d, T> { | |||
| 21 | { | 40 | { |
| 22 | use crate::pac::RCC; | 41 | use crate::pac::RCC; |
| 23 | RCC.apb7enr().modify(|w| w.set_vrefen(true)); | 42 | RCC.apb7enr().modify(|w| w.set_vrefen(true)); |
| 43 | // This is an errata for WBA6 devices. VREFBUF_TRIM value isn't set correctly | ||
| 44 | // [Link explaining it](https://www.st.com/resource/en/errata_sheet/es0644-stm32wba6xxx-device-errata-stmicroelectronics.pdf) | ||
| 45 | unsafe { | ||
| 46 | use crate::pac::VREFBUF; | ||
| 47 | let addr = get_refbuf_trim(voltage_scale) as usize; | ||
| 48 | let buf_trim_ptr = core::ptr::with_exposed_provenance::<u32>(addr); | ||
| 49 | let trim_val = core::ptr::read_volatile(buf_trim_ptr); | ||
| 50 | VREFBUF.ccr().write(|w| w.set_trim((trim_val & 0xFF) as u8)); | ||
| 51 | } | ||
| 24 | } | 52 | } |
| 25 | #[cfg(any(rcc_u5, rcc_h50, rcc_h5))] | 53 | #[cfg(any(rcc_u5, rcc_h50, rcc_h5))] |
| 26 | { | 54 | { |
