aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGerzain Mata <[email protected]>2025-08-08 03:10:35 -0700
committerGerzain Mata <[email protected]>2025-08-08 03:10:35 -0700
commit556ae0106bba66e49f62f45aa3cc458e31094dc7 (patch)
tree093284c4b15c275fa39c913db5a7c75825d80bdb
parentf2be66a5f94a655696407e2e7bc81c322aab3ea1 (diff)
Working draft of VREFBUF driver
-rw-r--r--embassy-stm32/Cargo.toml4
-rw-r--r--embassy-stm32/src/lib.rs2
-rw-r--r--embassy-stm32/src/vrefbuf/mod.rs69
3 files changed, 73 insertions, 2 deletions
diff --git a/embassy-stm32/Cargo.toml b/embassy-stm32/Cargo.toml
index 145a89b77..590216c21 100644
--- a/embassy-stm32/Cargo.toml
+++ b/embassy-stm32/Cargo.toml
@@ -81,7 +81,7 @@ futures-util = { version = "0.3.30", default-features = false }
81sdio-host = "0.9.0" 81sdio-host = "0.9.0"
82critical-section = "1.1" 82critical-section = "1.1"
83#stm32-metapac = { version = "16" } 83#stm32-metapac = { version = "16" }
84stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-cad609e02a866422ffdbb8e07be26311cfdd07d9" } 84stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-f0ef9106642ed869e7cfbf82d891d364c98ebb43" }
85 85
86vcell = "0.1.3" 86vcell = "0.1.3"
87nb = "1.0.0" 87nb = "1.0.0"
@@ -110,7 +110,7 @@ proc-macro2 = "1.0.36"
110quote = "1.0.15" 110quote = "1.0.15"
111 111
112#stm32-metapac = { version = "16", default-features = false, features = ["metadata"]} 112#stm32-metapac = { version = "16", default-features = false, features = ["metadata"]}
113stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-cad609e02a866422ffdbb8e07be26311cfdd07d9", default-features = false, features = ["metadata"] } 113stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-f0ef9106642ed869e7cfbf82d891d364c98ebb43", default-features = false, features = ["metadata"] }
114 114
115[features] 115[features]
116default = ["rt"] 116default = ["rt"]
diff --git a/embassy-stm32/src/lib.rs b/embassy-stm32/src/lib.rs
index a676677e1..e4a8ff0ab 100644
--- a/embassy-stm32/src/lib.rs
+++ b/embassy-stm32/src/lib.rs
@@ -125,6 +125,8 @@ pub mod uid;
125pub mod usart; 125pub mod usart;
126#[cfg(any(usb, otg))] 126#[cfg(any(usb, otg))]
127pub mod usb; 127pub mod usb;
128#[cfg(vrefbuf)]
129pub mod vrefbuf;
128#[cfg(iwdg)] 130#[cfg(iwdg)]
129pub mod wdg; 131pub mod wdg;
130#[cfg(xspi)] 132#[cfg(xspi)]
diff --git a/embassy-stm32/src/vrefbuf/mod.rs b/embassy-stm32/src/vrefbuf/mod.rs
new file mode 100644
index 000000000..2546ccfed
--- /dev/null
+++ b/embassy-stm32/src/vrefbuf/mod.rs
@@ -0,0 +1,69 @@
1//! Voltage Reference Buffer (VREFBUF)
2// use core::ptr::{read_volatile, write_volatile};
3use core::marker::PhantomData;
4
5use embassy_hal_internal::PeripheralType;
6use stm32_metapac::vrefbuf::vals::*;
7
8use crate::pac::RCC;
9use crate::Peri;
10
11/// Voltage Reference (VREFBUF) driver.
12pub struct VoltageReferenceBuffer<'d, T: Instance> {
13 vrefbuf: PhantomData<&'d mut T>,
14}
15
16impl<'d, T: Instance> VoltageReferenceBuffer<'d, T> {
17 /// Creates an VREFBUF (Voltage Reference) instance with a voltage scale and impedance mode.
18 ///
19 /// [Self] has to be started with [Self::new()].
20 pub fn new(_instance: Peri<'d, T>, voltage_scale: Vrs, impedance_mode: Hiz) -> Self {
21 #[cfg(rcc_wba)]
22 {
23 RCC.apb7enr().modify(|w| w.set_vrefen(true));
24 }
25 #[cfg(any(rcc_u5, rcc_h50, rcc_h5))]
26 {
27 RCC.apb3enr().modify(|w| w.set_vrefen(true));
28 }
29 #[cfg(any(rcc_h7rs, rcc_h7rm0433, rcc_h7ab, rcc_h7))]
30 {
31 RCC.apb4enr().modify(|w| w.set_vrefen(true));
32 }
33 let vrefbuf = T::regs();
34 vrefbuf.csr().modify(|w| {
35 w.set_hiz(impedance_mode);
36 w.set_envr(true);
37 w.set_vrs(voltage_scale);
38 });
39 while vrefbuf.csr().read().vrr() != false {
40 // wait...
41 }
42 trace!(
43 "Vrefbuf configured with voltage scale {} and impedance mode {}",
44 voltage_scale,
45 impedance_mode
46 );
47 VoltageReferenceBuffer { vrefbuf: PhantomData }
48 }
49}
50
51trait SealedInstance {
52 fn regs() -> crate::pac::vrefbuf::Vrefbuf;
53}
54
55/// VREFBUF instance trait.
56#[allow(private_bounds)]
57pub trait Instance: SealedInstance + PeripheralType {}
58
59foreach_peripheral!(
60 (vrefbuf, $inst:ident) => {
61 impl SealedInstance for crate::peripherals::$inst {
62 fn regs() -> crate::pac::vrefbuf::Vrefbuf {
63 crate::pac::$inst
64 }
65 }
66
67 impl Instance for crate::peripherals::$inst {}
68 };
69);