Merge pull request #1952 from embassy-rs/stm32-test-cleanup
stm32 rcc fixes.
This commit is contained in:
commit
624f786203
3 changed files with 27 additions and 8 deletions
|
@ -59,7 +59,7 @@ sdio-host = "0.5.0"
|
||||||
embedded-sdmmc = { git = "https://github.com/embassy-rs/embedded-sdmmc-rs", rev = "a4f293d3a6f72158385f79c98634cb8a14d0d2fc", optional = true }
|
embedded-sdmmc = { git = "https://github.com/embassy-rs/embedded-sdmmc-rs", rev = "a4f293d3a6f72158385f79c98634cb8a14d0d2fc", optional = true }
|
||||||
critical-section = "1.1"
|
critical-section = "1.1"
|
||||||
atomic-polyfill = "1.0.1"
|
atomic-polyfill = "1.0.1"
|
||||||
stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-1551a1c01a993bb5ffc603311f80097c14e03f85" }
|
stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-bdbf126746919e1c07730d80f9345b1a494c72a6" }
|
||||||
vcell = "0.1.3"
|
vcell = "0.1.3"
|
||||||
bxcan = "0.7.0"
|
bxcan = "0.7.0"
|
||||||
nb = "1.0.0"
|
nb = "1.0.0"
|
||||||
|
@ -78,7 +78,7 @@ critical-section = { version = "1.1", features = ["std"] }
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
proc-macro2 = "1.0.36"
|
proc-macro2 = "1.0.36"
|
||||||
quote = "1.0.15"
|
quote = "1.0.15"
|
||||||
stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-1551a1c01a993bb5ffc603311f80097c14e03f85", default-features = false, features = ["metadata"]}
|
stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-bdbf126746919e1c07730d80f9345b1a494c72a6", default-features = false, features = ["metadata"]}
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["rt"]
|
default = ["rt"]
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
use super::bd::BackupDomain;
|
use super::bd::BackupDomain;
|
||||||
pub use super::bus::{AHBPrescaler, APBPrescaler};
|
pub use super::bus::{AHBPrescaler, APBPrescaler};
|
||||||
use super::RtcClockSource;
|
use super::RtcClockSource;
|
||||||
|
pub use crate::pac::pwr::vals::Vos as VoltageScale;
|
||||||
use crate::pac::rcc::vals::{Hpre, Msirange, Plldiv, Pllmul, Pllsrc, Ppre, Sw};
|
use crate::pac::rcc::vals::{Hpre, Msirange, Plldiv, Pllmul, Pllsrc, Ppre, Sw};
|
||||||
use crate::pac::RCC;
|
|
||||||
#[cfg(crs)]
|
#[cfg(crs)]
|
||||||
use crate::pac::{crs, CRS, SYSCFG};
|
use crate::pac::{crs, CRS, SYSCFG};
|
||||||
|
use crate::pac::{FLASH, PWR, RCC};
|
||||||
use crate::rcc::{set_freqs, Clocks};
|
use crate::rcc::{set_freqs, Clocks};
|
||||||
use crate::time::Hertz;
|
use crate::time::Hertz;
|
||||||
|
|
||||||
|
@ -140,6 +141,7 @@ pub struct Config {
|
||||||
pub rtc: Option<RtcClockSource>,
|
pub rtc: Option<RtcClockSource>,
|
||||||
pub lse: Option<Hertz>,
|
pub lse: Option<Hertz>,
|
||||||
pub lsi: bool,
|
pub lsi: bool,
|
||||||
|
pub voltage_scale: VoltageScale,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Config {
|
impl Default for Config {
|
||||||
|
@ -155,11 +157,17 @@ impl Default for Config {
|
||||||
rtc: None,
|
rtc: None,
|
||||||
lse: None,
|
lse: None,
|
||||||
lsi: false,
|
lsi: false,
|
||||||
|
voltage_scale: VoltageScale::RANGE1,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) unsafe fn init(config: Config) {
|
pub(crate) unsafe fn init(config: Config) {
|
||||||
|
// Set voltage scale
|
||||||
|
while PWR.csr().read().vosf() {}
|
||||||
|
PWR.cr().write(|w| w.set_vos(config.voltage_scale));
|
||||||
|
while PWR.csr().read().vosf() {}
|
||||||
|
|
||||||
let (sys_clk, sw) = match config.mux {
|
let (sys_clk, sw) = match config.mux {
|
||||||
ClockSrc::MSI(range) => {
|
ClockSrc::MSI(range) => {
|
||||||
// Set MSI range
|
// Set MSI range
|
||||||
|
@ -245,6 +253,22 @@ pub(crate) unsafe fn init(config: Config) {
|
||||||
config.lse.map(|_| Default::default()),
|
config.lse.map(|_| Default::default()),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let wait_states = match config.voltage_scale {
|
||||||
|
VoltageScale::RANGE1 => match sys_clk {
|
||||||
|
..=16_000_000 => 0,
|
||||||
|
_ => 1,
|
||||||
|
},
|
||||||
|
VoltageScale::RANGE2 => match sys_clk {
|
||||||
|
..=8_000_000 => 0,
|
||||||
|
_ => 1,
|
||||||
|
},
|
||||||
|
VoltageScale::RANGE3 => 0,
|
||||||
|
_ => unreachable!(),
|
||||||
|
};
|
||||||
|
FLASH.acr().modify(|w| {
|
||||||
|
w.set_latency(wait_states != 0);
|
||||||
|
});
|
||||||
|
|
||||||
RCC.cfgr().modify(|w| {
|
RCC.cfgr().modify(|w| {
|
||||||
w.set_sw(sw);
|
w.set_sw(sw);
|
||||||
w.set_hpre(config.ahb_pre.into());
|
w.set_hpre(config.ahb_pre.into());
|
||||||
|
|
|
@ -317,11 +317,6 @@ pub(crate) unsafe fn init(config: Config) {
|
||||||
|
|
||||||
let freq = (src_freq / prediv.to_div() * mul.to_mul()) / div.to_div();
|
let freq = (src_freq / prediv.to_div() * mul.to_mul()) / div.to_div();
|
||||||
|
|
||||||
#[cfg(any(stm32l4px, stm32l4qx, stm32l4rx, stm32l4sx))]
|
|
||||||
assert!(freq <= 120_000_000);
|
|
||||||
#[cfg(not(any(stm32l4px, stm32l4qx, stm32l4rx, stm32l4sx)))]
|
|
||||||
assert!(freq <= 80_000_000);
|
|
||||||
|
|
||||||
RCC.pllcfgr().write(move |w| {
|
RCC.pllcfgr().write(move |w| {
|
||||||
w.set_plln(mul.into());
|
w.set_plln(mul.into());
|
||||||
w.set_pllm(prediv.into());
|
w.set_pllm(prediv.into());
|
||||||
|
|
Loading…
Reference in a new issue