stm32: rename HSI16 -> HSI
This commit is contained in:
parent
e70c531d3d
commit
412bcad2d1
@ -58,7 +58,7 @@ rand_core = "0.6.3"
|
|||||||
sdio-host = "0.5.0"
|
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"
|
||||||
stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-296dd041cce492e3b2b7fb3b8a6c05c9a34a90a1" }
|
stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-ee64389697d9234af374a89788aa52bb93d59284" }
|
||||||
vcell = "0.1.3"
|
vcell = "0.1.3"
|
||||||
bxcan = "0.7.0"
|
bxcan = "0.7.0"
|
||||||
nb = "1.0.0"
|
nb = "1.0.0"
|
||||||
@ -76,7 +76,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-296dd041cce492e3b2b7fb3b8a6c05c9a34a90a1", default-features = false, features = ["metadata"]}
|
stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-ee64389697d9234af374a89788aa52bb93d59284", default-features = false, features = ["metadata"]}
|
||||||
|
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::pac::flash::vals::Latency;
|
use crate::pac::flash::vals::Latency;
|
||||||
use crate::pac::rcc::vals::{self, Sw};
|
use crate::pac::rcc::vals::{self, Sw};
|
||||||
pub use crate::pac::rcc::vals::{
|
pub use crate::pac::rcc::vals::{
|
||||||
Hpre as AHBPrescaler, Hsidiv as HSI16Prescaler, Pllm, Plln, Pllp, Pllq, Pllr, Ppre as APBPrescaler,
|
Hpre as AHBPrescaler, Hsidiv as HSIPrescaler, Pllm, Plln, Pllp, Pllq, Pllr, Ppre as APBPrescaler,
|
||||||
};
|
};
|
||||||
use crate::pac::{FLASH, PWR, RCC};
|
use crate::pac::{FLASH, PWR, RCC};
|
||||||
use crate::rcc::{set_freqs, Clocks};
|
use crate::rcc::{set_freqs, Clocks};
|
||||||
@ -14,7 +14,7 @@ pub const HSI_FREQ: Hertz = Hertz(16_000_000);
|
|||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
pub enum ClockSrc {
|
pub enum ClockSrc {
|
||||||
HSE(Hertz),
|
HSE(Hertz),
|
||||||
HSI16(HSI16Prescaler),
|
HSI(HSIPrescaler),
|
||||||
PLL(PllConfig),
|
PLL(PllConfig),
|
||||||
LSI,
|
LSI,
|
||||||
}
|
}
|
||||||
@ -46,9 +46,9 @@ pub struct PllConfig {
|
|||||||
impl Default for PllConfig {
|
impl Default for PllConfig {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn default() -> PllConfig {
|
fn default() -> PllConfig {
|
||||||
// HSI16 / 1 * 8 / 2 = 64 MHz
|
// HSI / 1 * 8 / 2 = 64 MHz
|
||||||
PllConfig {
|
PllConfig {
|
||||||
source: PllSrc::HSI16,
|
source: PllSrc::HSI,
|
||||||
m: Pllm::DIV1,
|
m: Pllm::DIV1,
|
||||||
n: Plln::MUL8,
|
n: Plln::MUL8,
|
||||||
r: Pllr::DIV2,
|
r: Pllr::DIV2,
|
||||||
@ -60,7 +60,7 @@ impl Default for PllConfig {
|
|||||||
|
|
||||||
#[derive(Clone, Copy, Eq, PartialEq)]
|
#[derive(Clone, Copy, Eq, PartialEq)]
|
||||||
pub enum PllSrc {
|
pub enum PllSrc {
|
||||||
HSI16,
|
HSI,
|
||||||
HSE(Hertz),
|
HSE(Hertz),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,7 +77,7 @@ impl Default for Config {
|
|||||||
#[inline]
|
#[inline]
|
||||||
fn default() -> Config {
|
fn default() -> Config {
|
||||||
Config {
|
Config {
|
||||||
mux: ClockSrc::HSI16(HSI16Prescaler::DIV1),
|
mux: ClockSrc::HSI(HSIPrescaler::DIV1),
|
||||||
ahb_pre: AHBPrescaler::DIV1,
|
ahb_pre: AHBPrescaler::DIV1,
|
||||||
apb_pre: APBPrescaler::DIV1,
|
apb_pre: APBPrescaler::DIV1,
|
||||||
low_power_run: false,
|
low_power_run: false,
|
||||||
@ -89,7 +89,7 @@ impl Default for Config {
|
|||||||
impl PllConfig {
|
impl PllConfig {
|
||||||
pub(crate) fn init(self) -> Hertz {
|
pub(crate) fn init(self) -> Hertz {
|
||||||
let (src, input_freq) = match self.source {
|
let (src, input_freq) = match self.source {
|
||||||
PllSrc::HSI16 => (vals::Pllsrc::HSI, HSI_FREQ),
|
PllSrc::HSI => (vals::Pllsrc::HSI, HSI_FREQ),
|
||||||
PllSrc::HSE(freq) => (vals::Pllsrc::HSE, freq),
|
PllSrc::HSE(freq) => (vals::Pllsrc::HSE, freq),
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -121,7 +121,7 @@ impl PllConfig {
|
|||||||
// > 3. Change the desired parameter.
|
// > 3. Change the desired parameter.
|
||||||
// Enable whichever clock source we're using, and wait for it to become ready
|
// Enable whichever clock source we're using, and wait for it to become ready
|
||||||
match self.source {
|
match self.source {
|
||||||
PllSrc::HSI16 => {
|
PllSrc::HSI => {
|
||||||
RCC.cr().write(|w| w.set_hsion(true));
|
RCC.cr().write(|w| w.set_hsion(true));
|
||||||
while !RCC.cr().read().hsirdy() {}
|
while !RCC.cr().read().hsirdy() {}
|
||||||
}
|
}
|
||||||
@ -167,8 +167,8 @@ impl PllConfig {
|
|||||||
|
|
||||||
pub(crate) unsafe fn init(config: Config) {
|
pub(crate) unsafe fn init(config: Config) {
|
||||||
let (sys_clk, sw) = match config.mux {
|
let (sys_clk, sw) = match config.mux {
|
||||||
ClockSrc::HSI16(div) => {
|
ClockSrc::HSI(div) => {
|
||||||
// Enable HSI16
|
// Enable HSI
|
||||||
RCC.cr().write(|w| {
|
RCC.cr().write(|w| {
|
||||||
w.set_hsidiv(div);
|
w.set_hsidiv(div);
|
||||||
w.set_hsion(true)
|
w.set_hsion(true)
|
||||||
|
@ -18,14 +18,14 @@ pub const HSI_FREQ: Hertz = Hertz(16_000_000);
|
|||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
pub enum ClockSrc {
|
pub enum ClockSrc {
|
||||||
HSE(Hertz),
|
HSE(Hertz),
|
||||||
HSI16,
|
HSI,
|
||||||
PLL,
|
PLL,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// PLL clock input source
|
/// PLL clock input source
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
pub enum PllSrc {
|
pub enum PllSrc {
|
||||||
HSI16,
|
HSI,
|
||||||
HSE(Hertz),
|
HSE(Hertz),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ impl Into<Pllsrc> for PllSrc {
|
|||||||
fn into(self) -> Pllsrc {
|
fn into(self) -> Pllsrc {
|
||||||
match self {
|
match self {
|
||||||
PllSrc::HSE(..) => Pllsrc::HSE,
|
PllSrc::HSE(..) => Pllsrc::HSE,
|
||||||
PllSrc::HSI16 => Pllsrc::HSI,
|
PllSrc::HSI => Pllsrc::HSI,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -112,7 +112,7 @@ impl Default for Config {
|
|||||||
#[inline]
|
#[inline]
|
||||||
fn default() -> Config {
|
fn default() -> Config {
|
||||||
Config {
|
Config {
|
||||||
mux: ClockSrc::HSI16,
|
mux: ClockSrc::HSI,
|
||||||
ahb_pre: AHBPrescaler::DIV1,
|
ahb_pre: AHBPrescaler::DIV1,
|
||||||
apb1_pre: APBPrescaler::DIV1,
|
apb1_pre: APBPrescaler::DIV1,
|
||||||
apb2_pre: APBPrescaler::DIV1,
|
apb2_pre: APBPrescaler::DIV1,
|
||||||
@ -135,7 +135,7 @@ pub struct PllFreq {
|
|||||||
pub(crate) unsafe fn init(config: Config) {
|
pub(crate) unsafe fn init(config: Config) {
|
||||||
let pll_freq = config.pll.map(|pll_config| {
|
let pll_freq = config.pll.map(|pll_config| {
|
||||||
let src_freq = match pll_config.source {
|
let src_freq = match pll_config.source {
|
||||||
PllSrc::HSI16 => {
|
PllSrc::HSI => {
|
||||||
RCC.cr().write(|w| w.set_hsion(true));
|
RCC.cr().write(|w| w.set_hsion(true));
|
||||||
while !RCC.cr().read().hsirdy() {}
|
while !RCC.cr().read().hsirdy() {}
|
||||||
|
|
||||||
@ -196,8 +196,8 @@ pub(crate) unsafe fn init(config: Config) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let (sys_clk, sw) = match config.mux {
|
let (sys_clk, sw) = match config.mux {
|
||||||
ClockSrc::HSI16 => {
|
ClockSrc::HSI => {
|
||||||
// Enable HSI16
|
// Enable HSI
|
||||||
RCC.cr().write(|w| w.set_hsion(true));
|
RCC.cr().write(|w| w.set_hsion(true));
|
||||||
while !RCC.cr().read().hsirdy() {}
|
while !RCC.cr().read().hsirdy() {}
|
||||||
|
|
||||||
|
@ -18,20 +18,20 @@ pub enum ClockSrc {
|
|||||||
MSI(MSIRange),
|
MSI(MSIRange),
|
||||||
PLL(PLLSource, PLLMul, PLLDiv),
|
PLL(PLLSource, PLLMul, PLLDiv),
|
||||||
HSE(Hertz),
|
HSE(Hertz),
|
||||||
HSI16,
|
HSI,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// PLL clock input source
|
/// PLL clock input source
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
pub enum PLLSource {
|
pub enum PLLSource {
|
||||||
HSI16,
|
HSI,
|
||||||
HSE(Hertz),
|
HSE(Hertz),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<PLLSource> for Pllsrc {
|
impl From<PLLSource> for Pllsrc {
|
||||||
fn from(val: PLLSource) -> Pllsrc {
|
fn from(val: PLLSource) -> Pllsrc {
|
||||||
match val {
|
match val {
|
||||||
PLLSource::HSI16 => Pllsrc::HSI,
|
PLLSource::HSI => Pllsrc::HSI,
|
||||||
PLLSource::HSE(_) => Pllsrc::HSE,
|
PLLSource::HSE(_) => Pllsrc::HSE,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -83,10 +83,10 @@ pub(crate) unsafe fn init(config: Config) {
|
|||||||
let freq = 32_768 * (1 << (range as u8 + 1));
|
let freq = 32_768 * (1 << (range as u8 + 1));
|
||||||
(Hertz(freq), Sw::MSI)
|
(Hertz(freq), Sw::MSI)
|
||||||
}
|
}
|
||||||
ClockSrc::HSI16 => {
|
ClockSrc::HSI => {
|
||||||
// Enable HSI16
|
// Enable HSI
|
||||||
RCC.cr().write(|w| w.set_hsi16on(true));
|
RCC.cr().write(|w| w.set_hsion(true));
|
||||||
while !RCC.cr().read().hsi16rdy() {}
|
while !RCC.cr().read().hsirdy() {}
|
||||||
|
|
||||||
(HSI_FREQ, Sw::HSI)
|
(HSI_FREQ, Sw::HSI)
|
||||||
}
|
}
|
||||||
@ -105,10 +105,10 @@ pub(crate) unsafe fn init(config: Config) {
|
|||||||
while !RCC.cr().read().hserdy() {}
|
while !RCC.cr().read().hserdy() {}
|
||||||
freq
|
freq
|
||||||
}
|
}
|
||||||
PLLSource::HSI16 => {
|
PLLSource::HSI => {
|
||||||
// Enable HSI
|
// Enable HSI
|
||||||
RCC.cr().write(|w| w.set_hsi16on(true));
|
RCC.cr().write(|w| w.set_hsion(true));
|
||||||
while !RCC.cr().read().hsi16rdy() {}
|
while !RCC.cr().read().hsirdy() {}
|
||||||
HSI_FREQ
|
HSI_FREQ
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -34,7 +34,7 @@ pub struct Pll {
|
|||||||
pub struct Config {
|
pub struct Config {
|
||||||
// base clock sources
|
// base clock sources
|
||||||
pub msi: Option<MSIRange>,
|
pub msi: Option<MSIRange>,
|
||||||
pub hsi16: bool,
|
pub hsi: bool,
|
||||||
pub hse: Option<Hertz>,
|
pub hse: Option<Hertz>,
|
||||||
#[cfg(not(any(stm32l47x, stm32l48x)))]
|
#[cfg(not(any(stm32l47x, stm32l48x)))]
|
||||||
pub hsi48: bool,
|
pub hsi48: bool,
|
||||||
@ -63,7 +63,7 @@ impl Default for Config {
|
|||||||
fn default() -> Config {
|
fn default() -> Config {
|
||||||
Config {
|
Config {
|
||||||
hse: None,
|
hse: None,
|
||||||
hsi16: false,
|
hsi: false,
|
||||||
msi: Some(MSIRange::RANGE4M),
|
msi: Some(MSIRange::RANGE4M),
|
||||||
mux: ClockSrc::MSI,
|
mux: ClockSrc::MSI,
|
||||||
ahb_pre: AHBPrescaler::DIV1,
|
ahb_pre: AHBPrescaler::DIV1,
|
||||||
@ -127,7 +127,7 @@ pub(crate) unsafe fn init(config: Config) {
|
|||||||
msirange_to_hertz(range)
|
msirange_to_hertz(range)
|
||||||
});
|
});
|
||||||
|
|
||||||
let hsi16 = config.hsi16.then(|| {
|
let hsi = config.hsi.then(|| {
|
||||||
RCC.cr().write(|w| w.set_hsion(true));
|
RCC.cr().write(|w| w.set_hsion(true));
|
||||||
while !RCC.cr().read().hsirdy() {}
|
while !RCC.cr().read().hsirdy() {}
|
||||||
|
|
||||||
@ -179,7 +179,7 @@ pub(crate) unsafe fn init(config: Config) {
|
|||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
let pll_input = PllInput { hse, hsi16, msi };
|
let pll_input = PllInput { hse, hsi, msi };
|
||||||
let pll = init_pll(PllInstance::Pll, config.pll, &pll_input);
|
let pll = init_pll(PllInstance::Pll, config.pll, &pll_input);
|
||||||
let pllsai1 = init_pll(PllInstance::Pllsai1, config.pllsai1, &pll_input);
|
let pllsai1 = init_pll(PllInstance::Pllsai1, config.pllsai1, &pll_input);
|
||||||
#[cfg(any(stm32l47x, stm32l48x, stm32l49x, stm32l4ax, rcc_l4plus, stm32l5))]
|
#[cfg(any(stm32l47x, stm32l48x, stm32l49x, stm32l4ax, rcc_l4plus, stm32l5))]
|
||||||
@ -187,7 +187,7 @@ pub(crate) unsafe fn init(config: Config) {
|
|||||||
|
|
||||||
let sys_clk = match config.mux {
|
let sys_clk = match config.mux {
|
||||||
ClockSrc::HSE => hse.unwrap(),
|
ClockSrc::HSE => hse.unwrap(),
|
||||||
ClockSrc::HSI => hsi16.unwrap(),
|
ClockSrc::HSI => hsi.unwrap(),
|
||||||
ClockSrc::MSI => msi.unwrap(),
|
ClockSrc::MSI => msi.unwrap(),
|
||||||
ClockSrc::PLL1_R => pll._r.unwrap(),
|
ClockSrc::PLL1_R => pll._r.unwrap(),
|
||||||
};
|
};
|
||||||
@ -315,7 +315,7 @@ fn get_equal<T: Eq>(mut iter: impl Iterator<Item = T>) -> Result<Option<T>, ()>
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct PllInput {
|
struct PllInput {
|
||||||
hsi16: Option<Hertz>,
|
hsi: Option<Hertz>,
|
||||||
hse: Option<Hertz>,
|
hse: Option<Hertz>,
|
||||||
msi: Option<Hertz>,
|
msi: Option<Hertz>,
|
||||||
}
|
}
|
||||||
@ -358,7 +358,7 @@ fn init_pll(instance: PllInstance, config: Option<Pll>, input: &PllInput) -> Pll
|
|||||||
let pll_src = match pll.source {
|
let pll_src = match pll.source {
|
||||||
PLLSource::NONE => panic!("must not select PLL source as NONE"),
|
PLLSource::NONE => panic!("must not select PLL source as NONE"),
|
||||||
PLLSource::HSE => input.hse,
|
PLLSource::HSE => input.hse,
|
||||||
PLLSource::HSI => input.hsi16,
|
PLLSource::HSI => input.hsi,
|
||||||
PLLSource::MSI => input.msi,
|
PLLSource::MSI => input.msi,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@ pub const HSI_FREQ: Hertz = Hertz(16_000_000);
|
|||||||
pub use crate::pac::pwr::vals::Vos as VoltageScale;
|
pub use crate::pac::pwr::vals::Vos as VoltageScale;
|
||||||
|
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
|
#[allow(non_camel_case_types)]
|
||||||
pub enum ClockSrc {
|
pub enum ClockSrc {
|
||||||
/// Use an internal medium speed oscillator (MSIS) as the system clock.
|
/// Use an internal medium speed oscillator (MSIS) as the system clock.
|
||||||
MSI(Msirange),
|
MSI(Msirange),
|
||||||
@ -19,9 +20,9 @@ pub enum ClockSrc {
|
|||||||
/// never exceed 50 MHz.
|
/// never exceed 50 MHz.
|
||||||
HSE(Hertz),
|
HSE(Hertz),
|
||||||
/// Use the 16 MHz internal high speed oscillator as the system clock.
|
/// Use the 16 MHz internal high speed oscillator as the system clock.
|
||||||
HSI16,
|
HSI,
|
||||||
/// Use PLL1 as the system clock.
|
/// Use PLL1 as the system clock.
|
||||||
PLL1R(PllConfig),
|
PLL1_R(PllConfig),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for ClockSrc {
|
impl Default for ClockSrc {
|
||||||
@ -53,10 +54,10 @@ pub struct PllConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl PllConfig {
|
impl PllConfig {
|
||||||
/// A configuration for HSI16 / 1 * 10 / 1 = 160 MHz
|
/// A configuration for HSI / 1 * 10 / 1 = 160 MHz
|
||||||
pub const fn hsi16_160mhz() -> Self {
|
pub const fn hsi_160mhz() -> Self {
|
||||||
PllConfig {
|
PllConfig {
|
||||||
source: PllSrc::HSI16,
|
source: PllSrc::HSI,
|
||||||
m: Pllm::DIV1,
|
m: Pllm::DIV1,
|
||||||
n: Plln::MUL10,
|
n: Plln::MUL10,
|
||||||
r: Plldiv::DIV1,
|
r: Plldiv::DIV1,
|
||||||
@ -84,7 +85,7 @@ pub enum PllSrc {
|
|||||||
/// never exceed 50 MHz.
|
/// never exceed 50 MHz.
|
||||||
HSE(Hertz),
|
HSE(Hertz),
|
||||||
/// Use the 16 MHz internal high speed oscillator as the PLL source.
|
/// Use the 16 MHz internal high speed oscillator as the PLL source.
|
||||||
HSI16,
|
HSI,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Into<Pllsrc> for PllSrc {
|
impl Into<Pllsrc> for PllSrc {
|
||||||
@ -92,7 +93,7 @@ impl Into<Pllsrc> for PllSrc {
|
|||||||
match self {
|
match self {
|
||||||
PllSrc::MSIS(..) => Pllsrc::MSIS,
|
PllSrc::MSIS(..) => Pllsrc::MSIS,
|
||||||
PllSrc::HSE(..) => Pllsrc::HSE,
|
PllSrc::HSE(..) => Pllsrc::HSE,
|
||||||
PllSrc::HSI16 => Pllsrc::HSI,
|
PllSrc::HSI => Pllsrc::HSI,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -102,8 +103,8 @@ impl Into<Sw> for ClockSrc {
|
|||||||
match self {
|
match self {
|
||||||
ClockSrc::MSI(..) => Sw::MSIS,
|
ClockSrc::MSI(..) => Sw::MSIS,
|
||||||
ClockSrc::HSE(..) => Sw::HSE,
|
ClockSrc::HSE(..) => Sw::HSE,
|
||||||
ClockSrc::HSI16 => Sw::HSI,
|
ClockSrc::HSI => Sw::HSI,
|
||||||
ClockSrc::PLL1R(..) => Sw::PLL1_R,
|
ClockSrc::PLL1_R(..) => Sw::PLL1_R,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -125,7 +126,7 @@ pub struct Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
unsafe fn init_hsi16(&self) -> Hertz {
|
unsafe fn init_hsi(&self) -> Hertz {
|
||||||
RCC.cr().write(|w| w.set_hsion(true));
|
RCC.cr().write(|w| w.set_hsion(true));
|
||||||
while !RCC.cr().read().hsirdy() {}
|
while !RCC.cr().read().hsirdy() {}
|
||||||
|
|
||||||
@ -211,13 +212,13 @@ pub(crate) unsafe fn init(config: Config) {
|
|||||||
let sys_clk = match config.mux {
|
let sys_clk = match config.mux {
|
||||||
ClockSrc::MSI(range) => config.init_msis(range),
|
ClockSrc::MSI(range) => config.init_msis(range),
|
||||||
ClockSrc::HSE(freq) => config.init_hse(freq),
|
ClockSrc::HSE(freq) => config.init_hse(freq),
|
||||||
ClockSrc::HSI16 => config.init_hsi16(),
|
ClockSrc::HSI => config.init_hsi(),
|
||||||
ClockSrc::PLL1R(pll) => {
|
ClockSrc::PLL1_R(pll) => {
|
||||||
// Configure the PLL source
|
// Configure the PLL source
|
||||||
let source_clk = match pll.source {
|
let source_clk = match pll.source {
|
||||||
PllSrc::MSIS(range) => config.init_msis(range),
|
PllSrc::MSIS(range) => config.init_msis(range),
|
||||||
PllSrc::HSE(hertz) => config.init_hse(hertz),
|
PllSrc::HSE(hertz) => config.init_hse(hertz),
|
||||||
PllSrc::HSI16 => config.init_hsi16(),
|
PllSrc::HSI => config.init_hsi(),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Calculate the reference clock, which is the source divided by m
|
// Calculate the reference clock, which is the source divided by m
|
||||||
@ -292,7 +293,7 @@ pub(crate) unsafe fn init(config: Config) {
|
|||||||
// Set the prescaler for PWR EPOD
|
// Set the prescaler for PWR EPOD
|
||||||
w.set_pllmboost(mboost);
|
w.set_pllmboost(mboost);
|
||||||
|
|
||||||
// Enable PLL1R output
|
// Enable PLL1_R output
|
||||||
w.set_pllren(true);
|
w.set_pllren(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -13,20 +13,20 @@ pub use crate::pac::rcc::vals::{Hpre as AHBPrescaler, Ppre as APBPrescaler};
|
|||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
pub enum ClockSrc {
|
pub enum ClockSrc {
|
||||||
HSE(Hertz),
|
HSE(Hertz),
|
||||||
HSI16,
|
HSI,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
pub enum PllSrc {
|
pub enum PllSrc {
|
||||||
HSE(Hertz),
|
HSE(Hertz),
|
||||||
HSI16,
|
HSI,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Into<Pllsrc> for PllSrc {
|
impl Into<Pllsrc> for PllSrc {
|
||||||
fn into(self) -> Pllsrc {
|
fn into(self) -> Pllsrc {
|
||||||
match self {
|
match self {
|
||||||
PllSrc::HSE(..) => Pllsrc::HSE,
|
PllSrc::HSE(..) => Pllsrc::HSE,
|
||||||
PllSrc::HSI16 => Pllsrc::HSI,
|
PllSrc::HSI => Pllsrc::HSI,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ impl Into<Sw> for ClockSrc {
|
|||||||
fn into(self) -> Sw {
|
fn into(self) -> Sw {
|
||||||
match self {
|
match self {
|
||||||
ClockSrc::HSE(..) => Sw::HSE,
|
ClockSrc::HSE(..) => Sw::HSE,
|
||||||
ClockSrc::HSI16 => Sw::HSI,
|
ClockSrc::HSI => Sw::HSI,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -52,7 +52,7 @@ pub struct Config {
|
|||||||
impl Default for Config {
|
impl Default for Config {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
mux: ClockSrc::HSI16,
|
mux: ClockSrc::HSI,
|
||||||
ahb_pre: AHBPrescaler::DIV1,
|
ahb_pre: AHBPrescaler::DIV1,
|
||||||
apb1_pre: APBPrescaler::DIV1,
|
apb1_pre: APBPrescaler::DIV1,
|
||||||
apb2_pre: APBPrescaler::DIV1,
|
apb2_pre: APBPrescaler::DIV1,
|
||||||
@ -70,7 +70,7 @@ pub(crate) unsafe fn init(config: Config) {
|
|||||||
|
|
||||||
freq
|
freq
|
||||||
}
|
}
|
||||||
ClockSrc::HSI16 => {
|
ClockSrc::HSI => {
|
||||||
RCC.cr().write(|w| w.set_hsion(true));
|
RCC.cr().write(|w| w.set_hsion(true));
|
||||||
while !RCC.cr().read().hsirdy() {}
|
while !RCC.cr().read().hsirdy() {}
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ pub const HSE_FREQ: Hertz = Hertz(32_000_000);
|
|||||||
pub enum ClockSrc {
|
pub enum ClockSrc {
|
||||||
MSI(MSIRange),
|
MSI(MSIRange),
|
||||||
HSE,
|
HSE,
|
||||||
HSI16,
|
HSI,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Clocks configutation
|
/// Clocks configutation
|
||||||
@ -50,7 +50,7 @@ impl Default for Config {
|
|||||||
|
|
||||||
pub(crate) unsafe fn init(config: Config) {
|
pub(crate) unsafe fn init(config: Config) {
|
||||||
let (sys_clk, sw, vos) = match config.mux {
|
let (sys_clk, sw, vos) = match config.mux {
|
||||||
ClockSrc::HSI16 => (HSI_FREQ, Sw::HSI, VoltageScale::RANGE2),
|
ClockSrc::HSI => (HSI_FREQ, Sw::HSI, VoltageScale::RANGE2),
|
||||||
ClockSrc::HSE => (HSE_FREQ, Sw::HSE, VoltageScale::RANGE1),
|
ClockSrc::HSE => (HSE_FREQ, Sw::HSE, VoltageScale::RANGE1),
|
||||||
ClockSrc::MSI(range) => (msirange_to_hertz(range), Sw::MSI, msirange_to_vos(range)),
|
ClockSrc::MSI(range) => (msirange_to_hertz(range), Sw::MSI, msirange_to_vos(range)),
|
||||||
};
|
};
|
||||||
@ -97,8 +97,8 @@ pub(crate) unsafe fn init(config: Config) {
|
|||||||
while FLASH.acr().read().latency() != ws {}
|
while FLASH.acr().read().latency() != ws {}
|
||||||
|
|
||||||
match config.mux {
|
match config.mux {
|
||||||
ClockSrc::HSI16 => {
|
ClockSrc::HSI => {
|
||||||
// Enable HSI16
|
// Enable HSI
|
||||||
RCC.cr().write(|w| w.set_hsion(true));
|
RCC.cr().write(|w| w.set_hsion(true));
|
||||||
while !RCC.cr().read().hsirdy() {}
|
while !RCC.cr().read().hsirdy() {}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ async fn main(_spawner: Spawner) {
|
|||||||
let mut config = Config::default();
|
let mut config = Config::default();
|
||||||
|
|
||||||
config.rcc.pll = Some(Pll {
|
config.rcc.pll = Some(Pll {
|
||||||
source: PllSrc::HSI16,
|
source: PllSrc::HSI,
|
||||||
prediv_m: PllM::DIV4,
|
prediv_m: PllM::DIV4,
|
||||||
mul_n: PllN::MUL85,
|
mul_n: PllN::MUL85,
|
||||||
div_p: None,
|
div_p: None,
|
||||||
|
@ -14,7 +14,7 @@ async fn main(_spawner: Spawner) {
|
|||||||
let mut config = Config::default();
|
let mut config = Config::default();
|
||||||
|
|
||||||
config.rcc.pll = Some(Pll {
|
config.rcc.pll = Some(Pll {
|
||||||
source: PllSrc::HSI16,
|
source: PllSrc::HSI,
|
||||||
prediv_m: PllM::DIV4,
|
prediv_m: PllM::DIV4,
|
||||||
mul_n: PllN::MUL85,
|
mul_n: PllN::MUL85,
|
||||||
div_p: None,
|
div_p: None,
|
||||||
|
@ -23,7 +23,7 @@ const LORA_FREQUENCY_IN_HZ: u32 = 903_900_000; // warning: set this appropriatel
|
|||||||
#[embassy_executor::main]
|
#[embassy_executor::main]
|
||||||
async fn main(_spawner: Spawner) {
|
async fn main(_spawner: Spawner) {
|
||||||
let mut config = embassy_stm32::Config::default();
|
let mut config = embassy_stm32::Config::default();
|
||||||
config.rcc.mux = embassy_stm32::rcc::ClockSrc::HSI16;
|
config.rcc.mux = embassy_stm32::rcc::ClockSrc::HSI;
|
||||||
config.rcc.enable_hsi48 = true;
|
config.rcc.enable_hsi48 = true;
|
||||||
let p = embassy_stm32::init(config);
|
let p = embassy_stm32::init(config);
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ const LORAWAN_REGION: region::Region = region::Region::EU868; // warning: set th
|
|||||||
#[embassy_executor::main]
|
#[embassy_executor::main]
|
||||||
async fn main(_spawner: Spawner) {
|
async fn main(_spawner: Spawner) {
|
||||||
let mut config = embassy_stm32::Config::default();
|
let mut config = embassy_stm32::Config::default();
|
||||||
config.rcc.mux = embassy_stm32::rcc::ClockSrc::HSI16;
|
config.rcc.mux = embassy_stm32::rcc::ClockSrc::HSI;
|
||||||
config.rcc.enable_hsi48 = true;
|
config.rcc.enable_hsi48 = true;
|
||||||
let p = embassy_stm32::init(config);
|
let p = embassy_stm32::init(config);
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ const LORA_FREQUENCY_IN_HZ: u32 = 903_900_000; // warning: set this appropriatel
|
|||||||
#[embassy_executor::main]
|
#[embassy_executor::main]
|
||||||
async fn main(_spawner: Spawner) {
|
async fn main(_spawner: Spawner) {
|
||||||
let mut config = embassy_stm32::Config::default();
|
let mut config = embassy_stm32::Config::default();
|
||||||
config.rcc.mux = embassy_stm32::rcc::ClockSrc::HSI16;
|
config.rcc.mux = embassy_stm32::rcc::ClockSrc::HSI;
|
||||||
config.rcc.enable_hsi48 = true;
|
config.rcc.enable_hsi48 = true;
|
||||||
let p = embassy_stm32::init(config);
|
let p = embassy_stm32::init(config);
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ const LORA_FREQUENCY_IN_HZ: u32 = 903_900_000; // warning: set this appropriatel
|
|||||||
#[embassy_executor::main]
|
#[embassy_executor::main]
|
||||||
async fn main(_spawner: Spawner) {
|
async fn main(_spawner: Spawner) {
|
||||||
let mut config = embassy_stm32::Config::default();
|
let mut config = embassy_stm32::Config::default();
|
||||||
config.rcc.mux = embassy_stm32::rcc::ClockSrc::HSI16;
|
config.rcc.mux = embassy_stm32::rcc::ClockSrc::HSI;
|
||||||
config.rcc.enable_hsi48 = true;
|
config.rcc.enable_hsi48 = true;
|
||||||
let p = embassy_stm32::init(config);
|
let p = embassy_stm32::init(config);
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ bind_interrupts!(struct Irqs {
|
|||||||
async fn main(_spawner: Spawner) {
|
async fn main(_spawner: Spawner) {
|
||||||
let mut config = Config::default();
|
let mut config = Config::default();
|
||||||
config.rcc.mux = ClockSrc::PLL1_R;
|
config.rcc.mux = ClockSrc::PLL1_R;
|
||||||
config.rcc.hsi16 = true;
|
config.rcc.hsi = true;
|
||||||
config.rcc.pll = Some(Pll {
|
config.rcc.pll = Some(Pll {
|
||||||
source: PLLSource::HSI,
|
source: PLLSource::HSI,
|
||||||
prediv: PllPreDiv::DIV1,
|
prediv: PllPreDiv::DIV1,
|
||||||
|
@ -25,7 +25,7 @@ async fn main(_spawner: Spawner) {
|
|||||||
let mut config = Config::default();
|
let mut config = Config::default();
|
||||||
config.rcc.hsi48 = true;
|
config.rcc.hsi48 = true;
|
||||||
config.rcc.mux = ClockSrc::PLL1_R;
|
config.rcc.mux = ClockSrc::PLL1_R;
|
||||||
config.rcc.hsi16 = true;
|
config.rcc.hsi = true;
|
||||||
config.rcc.pll = Some(Pll {
|
config.rcc.pll = Some(Pll {
|
||||||
source: PLLSource::HSI,
|
source: PLLSource::HSI,
|
||||||
prediv: PllPreDiv::DIV1,
|
prediv: PllPreDiv::DIV1,
|
||||||
|
@ -16,7 +16,7 @@ bind_interrupts!(struct Irqs {
|
|||||||
#[embassy_executor::main]
|
#[embassy_executor::main]
|
||||||
async fn main(_spawner: Spawner) {
|
async fn main(_spawner: Spawner) {
|
||||||
let mut config = Config::default();
|
let mut config = Config::default();
|
||||||
config.rcc.hsi16 = true;
|
config.rcc.hsi = true;
|
||||||
config.rcc.mux = ClockSrc::PLL1_R;
|
config.rcc.mux = ClockSrc::PLL1_R;
|
||||||
config.rcc.pll = Some(Pll {
|
config.rcc.pll = Some(Pll {
|
||||||
// 64Mhz clock (16 / 1 * 8 / 2)
|
// 64Mhz clock (16 / 1 * 8 / 2)
|
||||||
|
@ -45,7 +45,7 @@ async fn net_task(stack: &'static Stack<Device<'static, MTU>>) -> ! {
|
|||||||
#[embassy_executor::main]
|
#[embassy_executor::main]
|
||||||
async fn main(spawner: Spawner) {
|
async fn main(spawner: Spawner) {
|
||||||
let mut config = Config::default();
|
let mut config = Config::default();
|
||||||
config.rcc.hsi16 = true;
|
config.rcc.hsi = true;
|
||||||
config.rcc.mux = ClockSrc::PLL1_R;
|
config.rcc.mux = ClockSrc::PLL1_R;
|
||||||
config.rcc.pll = Some(Pll {
|
config.rcc.pll = Some(Pll {
|
||||||
// 80Mhz clock (16 / 1 * 10 / 2)
|
// 80Mhz clock (16 / 1 * 10 / 2)
|
||||||
|
@ -22,7 +22,7 @@ bind_interrupts!(struct Irqs {
|
|||||||
#[embassy_executor::main]
|
#[embassy_executor::main]
|
||||||
async fn main(_spawner: Spawner) {
|
async fn main(_spawner: Spawner) {
|
||||||
let mut config = Config::default();
|
let mut config = Config::default();
|
||||||
config.rcc.hsi16 = true;
|
config.rcc.hsi = true;
|
||||||
config.rcc.mux = ClockSrc::PLL1_R;
|
config.rcc.mux = ClockSrc::PLL1_R;
|
||||||
config.rcc.pll = Some(Pll {
|
config.rcc.pll = Some(Pll {
|
||||||
// 80Mhz clock (16 / 1 * 10 / 2)
|
// 80Mhz clock (16 / 1 * 10 / 2)
|
||||||
|
@ -20,7 +20,7 @@ bind_interrupts!(struct Irqs {
|
|||||||
#[embassy_executor::main]
|
#[embassy_executor::main]
|
||||||
async fn main(_spawner: Spawner) {
|
async fn main(_spawner: Spawner) {
|
||||||
let mut config = Config::default();
|
let mut config = Config::default();
|
||||||
config.rcc.hsi16 = true;
|
config.rcc.hsi = true;
|
||||||
config.rcc.mux = ClockSrc::PLL1_R;
|
config.rcc.mux = ClockSrc::PLL1_R;
|
||||||
config.rcc.pll = Some(Pll {
|
config.rcc.pll = Some(Pll {
|
||||||
// 80Mhz clock (16 / 1 * 10 / 2)
|
// 80Mhz clock (16 / 1 * 10 / 2)
|
||||||
|
@ -23,8 +23,8 @@ async fn main(_spawner: Spawner) {
|
|||||||
info!("Hello World!");
|
info!("Hello World!");
|
||||||
|
|
||||||
let mut config = Config::default();
|
let mut config = Config::default();
|
||||||
config.rcc.mux = ClockSrc::PLL1R(PllConfig {
|
config.rcc.mux = ClockSrc::PLL1_R(PllConfig {
|
||||||
source: PllSrc::HSI16,
|
source: PllSrc::HSI,
|
||||||
m: Pllm::DIV2,
|
m: Pllm::DIV2,
|
||||||
n: Plln::MUL10,
|
n: Plln::MUL10,
|
||||||
r: Plldiv::DIV1,
|
r: Plldiv::DIV1,
|
||||||
|
@ -365,7 +365,7 @@ pub fn config() -> Config {
|
|||||||
{
|
{
|
||||||
use embassy_stm32::rcc::*;
|
use embassy_stm32::rcc::*;
|
||||||
config.rcc.mux = ClockSrc::PLL1_R;
|
config.rcc.mux = ClockSrc::PLL1_R;
|
||||||
config.rcc.hsi16 = true;
|
config.rcc.hsi = true;
|
||||||
config.rcc.pll = Some(Pll {
|
config.rcc.pll = Some(Pll {
|
||||||
source: PLLSource::HSI,
|
source: PLLSource::HSI,
|
||||||
prediv: PllPreDiv::DIV1,
|
prediv: PllPreDiv::DIV1,
|
||||||
@ -388,7 +388,7 @@ pub fn config() -> Config {
|
|||||||
#[cfg(any(feature = "stm32l552ze"))]
|
#[cfg(any(feature = "stm32l552ze"))]
|
||||||
{
|
{
|
||||||
use embassy_stm32::rcc::*;
|
use embassy_stm32::rcc::*;
|
||||||
config.rcc.hsi16 = true;
|
config.rcc.hsi = true;
|
||||||
config.rcc.mux = ClockSrc::PLL1_R;
|
config.rcc.mux = ClockSrc::PLL1_R;
|
||||||
config.rcc.pll = Some(Pll {
|
config.rcc.pll = Some(Pll {
|
||||||
// 110Mhz clock (16 / 4 * 55 / 2)
|
// 110Mhz clock (16 / 4 * 55 / 2)
|
||||||
@ -412,7 +412,7 @@ pub fn config() -> Config {
|
|||||||
use embassy_stm32::rcc::*;
|
use embassy_stm32::rcc::*;
|
||||||
config.rcc.mux = ClockSrc::PLL(
|
config.rcc.mux = ClockSrc::PLL(
|
||||||
// 32Mhz clock (16 * 4 / 2)
|
// 32Mhz clock (16 * 4 / 2)
|
||||||
PLLSource::HSI16,
|
PLLSource::HSI,
|
||||||
PLLMul::MUL4,
|
PLLMul::MUL4,
|
||||||
PLLDiv::DIV2,
|
PLLDiv::DIV2,
|
||||||
);
|
);
|
||||||
@ -423,7 +423,7 @@ pub fn config() -> Config {
|
|||||||
use embassy_stm32::rcc::*;
|
use embassy_stm32::rcc::*;
|
||||||
config.rcc.mux = ClockSrc::PLL(
|
config.rcc.mux = ClockSrc::PLL(
|
||||||
// 32Mhz clock (16 * 4 / 2)
|
// 32Mhz clock (16 * 4 / 2)
|
||||||
PLLSource::HSI16,
|
PLLSource::HSI,
|
||||||
PLLMul::MUL4,
|
PLLMul::MUL4,
|
||||||
PLLDiv::DIV2,
|
PLLDiv::DIV2,
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user