aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-stm32/Cargo.toml4
-rw-r--r--embassy-stm32/src/rcc/l0.rs26
2 files changed, 27 insertions, 3 deletions
diff --git a/embassy-stm32/Cargo.toml b/embassy-stm32/Cargo.toml
index 660ab0532..08b9b3a38 100644
--- a/embassy-stm32/Cargo.toml
+++ b/embassy-stm32/Cargo.toml
@@ -59,7 +59,7 @@ sdio-host = "0.5.0"
59embedded-sdmmc = { git = "https://github.com/embassy-rs/embedded-sdmmc-rs", rev = "a4f293d3a6f72158385f79c98634cb8a14d0d2fc", optional = true } 59embedded-sdmmc = { git = "https://github.com/embassy-rs/embedded-sdmmc-rs", rev = "a4f293d3a6f72158385f79c98634cb8a14d0d2fc", optional = true }
60critical-section = "1.1" 60critical-section = "1.1"
61atomic-polyfill = "1.0.1" 61atomic-polyfill = "1.0.1"
62stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-1551a1c01a993bb5ffc603311f80097c14e03f85" } 62stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-bdbf126746919e1c07730d80f9345b1a494c72a6" }
63vcell = "0.1.3" 63vcell = "0.1.3"
64bxcan = "0.7.0" 64bxcan = "0.7.0"
65nb = "1.0.0" 65nb = "1.0.0"
@@ -78,7 +78,7 @@ critical-section = { version = "1.1", features = ["std"] }
78[build-dependencies] 78[build-dependencies]
79proc-macro2 = "1.0.36" 79proc-macro2 = "1.0.36"
80quote = "1.0.15" 80quote = "1.0.15"
81stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-1551a1c01a993bb5ffc603311f80097c14e03f85", default-features = false, features = ["metadata"]} 81stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-bdbf126746919e1c07730d80f9345b1a494c72a6", default-features = false, features = ["metadata"]}
82 82
83[features] 83[features]
84default = ["rt"] 84default = ["rt"]
diff --git a/embassy-stm32/src/rcc/l0.rs b/embassy-stm32/src/rcc/l0.rs
index 67355afbe..7358be31b 100644
--- a/embassy-stm32/src/rcc/l0.rs
+++ b/embassy-stm32/src/rcc/l0.rs
@@ -1,10 +1,11 @@
1use super::bd::BackupDomain; 1use super::bd::BackupDomain;
2pub use super::bus::{AHBPrescaler, APBPrescaler}; 2pub use super::bus::{AHBPrescaler, APBPrescaler};
3use super::RtcClockSource; 3use super::RtcClockSource;
4pub use crate::pac::pwr::vals::Vos as VoltageScale;
4use crate::pac::rcc::vals::{Hpre, Msirange, Plldiv, Pllmul, Pllsrc, Ppre, Sw}; 5use crate::pac::rcc::vals::{Hpre, Msirange, Plldiv, Pllmul, Pllsrc, Ppre, Sw};
5use crate::pac::RCC;
6#[cfg(crs)] 6#[cfg(crs)]
7use crate::pac::{crs, CRS, SYSCFG}; 7use crate::pac::{crs, CRS, SYSCFG};
8use crate::pac::{FLASH, PWR, RCC};
8use crate::rcc::{set_freqs, Clocks}; 9use crate::rcc::{set_freqs, Clocks};
9use crate::time::Hertz; 10use crate::time::Hertz;
10 11
@@ -140,6 +141,7 @@ pub struct Config {
140 pub rtc: Option<RtcClockSource>, 141 pub rtc: Option<RtcClockSource>,
141 pub lse: Option<Hertz>, 142 pub lse: Option<Hertz>,
142 pub lsi: bool, 143 pub lsi: bool,
144 pub voltage_scale: VoltageScale,
143} 145}
144 146
145impl Default for Config { 147impl Default for Config {
@@ -155,11 +157,17 @@ impl Default for Config {
155 rtc: None, 157 rtc: None,
156 lse: None, 158 lse: None,
157 lsi: false, 159 lsi: false,
160 voltage_scale: VoltageScale::RANGE1,
158 } 161 }
159 } 162 }
160} 163}
161 164
162pub(crate) unsafe fn init(config: Config) { 165pub(crate) unsafe fn init(config: Config) {
166 // Set voltage scale
167 while PWR.csr().read().vosf() {}
168 PWR.cr().write(|w| w.set_vos(config.voltage_scale));
169 while PWR.csr().read().vosf() {}
170
163 let (sys_clk, sw) = match config.mux { 171 let (sys_clk, sw) = match config.mux {
164 ClockSrc::MSI(range) => { 172 ClockSrc::MSI(range) => {
165 // Set MSI range 173 // Set MSI range
@@ -245,6 +253,22 @@ pub(crate) unsafe fn init(config: Config) {
245 config.lse.map(|_| Default::default()), 253 config.lse.map(|_| Default::default()),
246 ); 254 );
247 255
256 let wait_states = match config.voltage_scale {
257 VoltageScale::RANGE1 => match sys_clk {
258 ..=16_000_000 => 0,
259 _ => 1,
260 },
261 VoltageScale::RANGE2 => match sys_clk {
262 ..=8_000_000 => 0,
263 _ => 1,
264 },
265 VoltageScale::RANGE3 => 0,
266 _ => unreachable!(),
267 };
268 FLASH.acr().modify(|w| {
269 w.set_latency(wait_states != 0);
270 });
271
248 RCC.cfgr().modify(|w| { 272 RCC.cfgr().modify(|w| {
249 w.set_sw(sw); 273 w.set_sw(sw);
250 w.set_hpre(config.ahb_pre.into()); 274 w.set_hpre(config.ahb_pre.into());