diff options
Diffstat (limited to 'embassy-stm32/src')
| -rw-r--r-- | embassy-stm32/src/vrefbuf/mod.rs | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/embassy-stm32/src/vrefbuf/mod.rs b/embassy-stm32/src/vrefbuf/mod.rs index f614fcf99..54b4f8903 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,17 @@ 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 | fn get_refbuf_trim(voltage_scale: Vrs) -> usize { | ||
| 16 | match voltage_scale { | ||
| 17 | Vrs::VREF0 => 0x0BFA_07A8usize, | ||
| 18 | Vrs::VREF1 => 0x0BFA_07A9usize, | ||
| 19 | Vrs::VREF2 => 0x0BFA_07AAusize, | ||
| 20 | Vrs::VREF3 => 0x0BFA_07ABusize, | ||
| 21 | _ => panic!("Incorrect Vrs setting!"), | ||
| 22 | } | ||
| 23 | } | ||
| 24 | |||
| 15 | impl<'d, T: Instance> VoltageReferenceBuffer<'d, T> { | 25 | impl<'d, T: Instance> VoltageReferenceBuffer<'d, T> { |
| 16 | /// Creates an VREFBUF (Voltage Reference) instance with a voltage scale and impedance mode. | 26 | /// Creates an VREFBUF (Voltage Reference) instance with a voltage scale and impedance mode. |
| 17 | /// | 27 | /// |
| @@ -21,6 +31,15 @@ impl<'d, T: Instance> VoltageReferenceBuffer<'d, T> { | |||
| 21 | { | 31 | { |
| 22 | use crate::pac::RCC; | 32 | use crate::pac::RCC; |
| 23 | RCC.apb7enr().modify(|w| w.set_vrefen(true)); | 33 | RCC.apb7enr().modify(|w| w.set_vrefen(true)); |
| 34 | // This is an errata for WBA6 devices. VREFBUF_TRIM value isn't set correctly | ||
| 35 | // [Link explaining it](https://www.st.com/resource/en/errata_sheet/es0644-stm32wba6xxx-device-errata-stmicroelectronics.pdf) | ||
| 36 | unsafe { | ||
| 37 | use crate::pac::VREFBUF; | ||
| 38 | let addr = get_refbuf_trim(voltage_scale); | ||
| 39 | let buf_trim_ptr = core::ptr::with_exposed_provenance::<u32>(addr); | ||
| 40 | let trim_val = core::ptr::read_volatile(buf_trim_ptr); | ||
| 41 | VREFBUF.ccr().write(|w| w.set_trim((trim_val & 0x3F) as u8)); | ||
| 42 | } | ||
| 24 | } | 43 | } |
| 25 | #[cfg(any(rcc_u5, rcc_h50, rcc_h5))] | 44 | #[cfg(any(rcc_u5, rcc_h50, rcc_h5))] |
| 26 | { | 45 | { |
