diff options
| author | Dario Nieuwenhuis <[email protected]> | 2023-09-26 05:14:05 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2023-09-26 05:15:09 +0200 |
| commit | c604d8a8f1b633874117fcf01018121f4fe05867 (patch) | |
| tree | e633bc36f4542b22526c6f6b444b575e2a349dcc /embassy-stm32 | |
| parent | be0c52bf5e60f29b2b3f0c2ca05e169d4ccc15fb (diff) | |
stm32/rcc: add voltage_scale, flash waitstates.
Diffstat (limited to 'embassy-stm32')
| -rw-r--r-- | embassy-stm32/Cargo.toml | 4 | ||||
| -rw-r--r-- | embassy-stm32/src/rcc/l0.rs | 26 |
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" | |||
| 59 | embedded-sdmmc = { git = "https://github.com/embassy-rs/embedded-sdmmc-rs", rev = "a4f293d3a6f72158385f79c98634cb8a14d0d2fc", optional = true } | 59 | embedded-sdmmc = { git = "https://github.com/embassy-rs/embedded-sdmmc-rs", rev = "a4f293d3a6f72158385f79c98634cb8a14d0d2fc", optional = true } |
| 60 | critical-section = "1.1" | 60 | critical-section = "1.1" |
| 61 | atomic-polyfill = "1.0.1" | 61 | atomic-polyfill = "1.0.1" |
| 62 | stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-1551a1c01a993bb5ffc603311f80097c14e03f85" } | 62 | stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-bdbf126746919e1c07730d80f9345b1a494c72a6" } |
| 63 | vcell = "0.1.3" | 63 | vcell = "0.1.3" |
| 64 | bxcan = "0.7.0" | 64 | bxcan = "0.7.0" |
| 65 | nb = "1.0.0" | 65 | nb = "1.0.0" |
| @@ -78,7 +78,7 @@ critical-section = { version = "1.1", features = ["std"] } | |||
| 78 | [build-dependencies] | 78 | [build-dependencies] |
| 79 | proc-macro2 = "1.0.36" | 79 | proc-macro2 = "1.0.36" |
| 80 | quote = "1.0.15" | 80 | quote = "1.0.15" |
| 81 | stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-1551a1c01a993bb5ffc603311f80097c14e03f85", default-features = false, features = ["metadata"]} | 81 | stm32-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] |
| 84 | default = ["rt"] | 84 | default = ["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 @@ | |||
| 1 | use super::bd::BackupDomain; | 1 | use super::bd::BackupDomain; |
| 2 | pub use super::bus::{AHBPrescaler, APBPrescaler}; | 2 | pub use super::bus::{AHBPrescaler, APBPrescaler}; |
| 3 | use super::RtcClockSource; | 3 | use super::RtcClockSource; |
| 4 | pub use crate::pac::pwr::vals::Vos as VoltageScale; | ||
| 4 | use crate::pac::rcc::vals::{Hpre, Msirange, Plldiv, Pllmul, Pllsrc, Ppre, Sw}; | 5 | use crate::pac::rcc::vals::{Hpre, Msirange, Plldiv, Pllmul, Pllsrc, Ppre, Sw}; |
| 5 | use crate::pac::RCC; | ||
| 6 | #[cfg(crs)] | 6 | #[cfg(crs)] |
| 7 | use crate::pac::{crs, CRS, SYSCFG}; | 7 | use crate::pac::{crs, CRS, SYSCFG}; |
| 8 | use crate::pac::{FLASH, PWR, RCC}; | ||
| 8 | use crate::rcc::{set_freqs, Clocks}; | 9 | use crate::rcc::{set_freqs, Clocks}; |
| 9 | use crate::time::Hertz; | 10 | use 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 | ||
| 145 | impl Default for Config { | 147 | impl 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 | ||
| 162 | pub(crate) unsafe fn init(config: Config) { | 165 | pub(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()); |
