diff options
| -rwxr-xr-x | ci.sh | 7 | ||||
| -rw-r--r-- | embassy-stm32/Cargo.toml | 4 | ||||
| -rw-r--r-- | embassy-stm32/src/rcc/f0.rs | 332 | ||||
| -rw-r--r-- | embassy-stm32/src/rcc/mco.rs | 6 | ||||
| -rw-r--r-- | embassy-stm32/src/rcc/mod.rs | 16 |
5 files changed, 204 insertions, 161 deletions
| @@ -88,6 +88,13 @@ cargo batch \ | |||
| 88 | --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features stm32l552ze,defmt,exti \ | 88 | --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features stm32l552ze,defmt,exti \ |
| 89 | --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features stm32l552ze,defmt \ | 89 | --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv8m.main-none-eabihf --features stm32l552ze,defmt \ |
| 90 | --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f038f6,defmt,exti,time-driver-any,time \ | 90 | --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f038f6,defmt,exti,time-driver-any,time \ |
| 91 | --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f030c6,defmt,exti,time-driver-any,time \ | ||
| 92 | --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f058t8,defmt,exti,time-driver-any,time \ | ||
| 93 | --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f030r8,defmt,exti,time-driver-any,time \ | ||
| 94 | --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f031k6,defmt,exti,time-driver-any,time \ | ||
| 95 | --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f030rc,defmt,exti,time-driver-any,time \ | ||
| 96 | --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f070f6,defmt,exti,time-driver-any,time \ | ||
| 97 | --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f078vb,defmt,exti,time-driver-any,time \ | ||
| 91 | --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f042g4,defmt,exti,time-driver-any,time \ | 98 | --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f042g4,defmt,exti,time-driver-any,time \ |
| 92 | --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f072c8,defmt,exti,time-driver-any,time \ | 99 | --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f072c8,defmt,exti,time-driver-any,time \ |
| 93 | --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f401ve,defmt,exti,time-driver-any \ | 100 | --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features stm32f401ve,defmt,exti,time-driver-any \ |
diff --git a/embassy-stm32/Cargo.toml b/embassy-stm32/Cargo.toml index cc76408f3..4c27164ce 100644 --- a/embassy-stm32/Cargo.toml +++ b/embassy-stm32/Cargo.toml | |||
| @@ -68,7 +68,7 @@ rand_core = "0.6.3" | |||
| 68 | sdio-host = "0.5.0" | 68 | sdio-host = "0.5.0" |
| 69 | critical-section = "1.1" | 69 | critical-section = "1.1" |
| 70 | #stm32-metapac = { version = "15" } | 70 | #stm32-metapac = { version = "15" } |
| 71 | stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-8a3ad0b738292ae40af201d79b28db60fe876e11" } | 71 | stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-7734584b2007766b1c5a6a7f2654fdb442fa211a" } |
| 72 | vcell = "0.1.3" | 72 | vcell = "0.1.3" |
| 73 | bxcan = "0.7.0" | 73 | bxcan = "0.7.0" |
| 74 | nb = "1.0.0" | 74 | nb = "1.0.0" |
| @@ -89,7 +89,7 @@ critical-section = { version = "1.1", features = ["std"] } | |||
| 89 | proc-macro2 = "1.0.36" | 89 | proc-macro2 = "1.0.36" |
| 90 | quote = "1.0.15" | 90 | quote = "1.0.15" |
| 91 | #stm32-metapac = { version = "15", default-features = false, features = ["metadata"]} | 91 | #stm32-metapac = { version = "15", default-features = false, features = ["metadata"]} |
| 92 | stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-8a3ad0b738292ae40af201d79b28db60fe876e11", default-features = false, features = ["metadata"]} | 92 | stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-7734584b2007766b1c5a6a7f2654fdb442fa211a", default-features = false, features = ["metadata"]} |
| 93 | 93 | ||
| 94 | 94 | ||
| 95 | [features] | 95 | [features] |
diff --git a/embassy-stm32/src/rcc/f0.rs b/embassy-stm32/src/rcc/f0.rs index 1042a1cb2..d6f995e45 100644 --- a/embassy-stm32/src/rcc/f0.rs +++ b/embassy-stm32/src/rcc/f0.rs | |||
| @@ -1,27 +1,64 @@ | |||
| 1 | use stm32_metapac::flash::vals::Latency; | 1 | use crate::pac::flash::vals::Latency; |
| 2 | 2 | use crate::pac::rcc::vals::Pllsrc; | |
| 3 | use crate::pac::rcc::vals::{Hpre, Pllmul, Pllsrc, Ppre, Sw, Usbsw}; | 3 | pub use crate::pac::rcc::vals::{ |
| 4 | Hpre as AHBPrescaler, Pllmul as PllMul, Ppre as APBPrescaler, Prediv as PllPreDiv, Sw as Sysclk, | ||
| 5 | }; | ||
| 4 | use crate::pac::{FLASH, RCC}; | 6 | use crate::pac::{FLASH, RCC}; |
| 5 | use crate::time::Hertz; | 7 | use crate::time::Hertz; |
| 6 | 8 | ||
| 7 | /// HSI speed | 9 | /// HSI speed |
| 8 | pub const HSI_FREQ: Hertz = Hertz(8_000_000); | 10 | pub const HSI_FREQ: Hertz = Hertz(8_000_000); |
| 9 | 11 | ||
| 10 | /// Configuration of the clocks | 12 | #[derive(Clone, Copy, Eq, PartialEq)] |
| 11 | /// | 13 | pub enum HseMode { |
| 12 | /// hse takes precedence over hsi48 if both are enabled | 14 | /// crystal/ceramic oscillator (HSEBYP=0) |
| 15 | Oscillator, | ||
| 16 | /// external analog clock (low swing) (HSEBYP=1) | ||
| 17 | Bypass, | ||
| 18 | } | ||
| 19 | |||
| 20 | #[derive(Clone, Copy, Eq, PartialEq)] | ||
| 21 | pub struct Hse { | ||
| 22 | /// HSE frequency. | ||
| 23 | pub freq: Hertz, | ||
| 24 | /// HSE mode. | ||
| 25 | pub mode: HseMode, | ||
| 26 | } | ||
| 27 | |||
| 28 | #[derive(Clone, Copy, Eq, PartialEq)] | ||
| 29 | pub enum PllSource { | ||
| 30 | HSE, | ||
| 31 | HSI, | ||
| 32 | #[cfg(rcc_f0v4)] | ||
| 33 | HSI48, | ||
| 34 | } | ||
| 35 | |||
| 36 | #[derive(Clone, Copy)] | ||
| 37 | pub struct Pll { | ||
| 38 | pub src: PllSource, | ||
| 39 | |||
| 40 | /// PLL pre-divider. | ||
| 41 | /// | ||
| 42 | /// On some chips, this must be 2 if `src == HSI`. Init will panic if this is not the case. | ||
| 43 | pub prediv: PllPreDiv, | ||
| 44 | |||
| 45 | /// PLL multiplication factor. | ||
| 46 | pub mul: PllMul, | ||
| 47 | } | ||
| 48 | |||
| 49 | /// Clocks configutation | ||
| 13 | #[non_exhaustive] | 50 | #[non_exhaustive] |
| 14 | pub struct Config { | 51 | pub struct Config { |
| 15 | pub hse: Option<Hertz>, | 52 | pub hsi: bool, |
| 16 | pub bypass_hse: bool, | 53 | pub hse: Option<Hse>, |
| 17 | pub usb_pll: bool, | ||
| 18 | |||
| 19 | #[cfg(crs)] | 54 | #[cfg(crs)] |
| 20 | pub hsi48: Option<super::Hsi48Config>, | 55 | pub hsi48: Option<super::Hsi48Config>, |
| 56 | pub sys: Sysclk, | ||
| 21 | 57 | ||
| 22 | pub sys_ck: Option<Hertz>, | 58 | pub pll: Option<Pll>, |
| 23 | pub hclk: Option<Hertz>, | 59 | |
| 24 | pub pclk: Option<Hertz>, | 60 | pub ahb_pre: AHBPrescaler, |
| 61 | pub apb1_pre: APBPrescaler, | ||
| 25 | 62 | ||
| 26 | pub ls: super::LsConfig, | 63 | pub ls: super::LsConfig, |
| 27 | } | 64 | } |
| @@ -29,168 +66,167 @@ pub struct Config { | |||
| 29 | impl Default for Config { | 66 | impl Default for Config { |
| 30 | fn default() -> Self { | 67 | fn default() -> Self { |
| 31 | Self { | 68 | Self { |
| 32 | hse: Default::default(), | 69 | hsi: true, |
| 33 | bypass_hse: Default::default(), | 70 | hse: None, |
| 34 | usb_pll: Default::default(), | ||
| 35 | #[cfg(crs)] | 71 | #[cfg(crs)] |
| 36 | hsi48: Some(Default::default()), | 72 | hsi48: Some(Default::default()), |
| 37 | sys_ck: Default::default(), | 73 | sys: Sysclk::HSI, |
| 38 | hclk: Default::default(), | 74 | pll: None, |
| 39 | pclk: Default::default(), | 75 | ahb_pre: AHBPrescaler::DIV1, |
| 76 | apb1_pre: APBPrescaler::DIV1, | ||
| 40 | ls: Default::default(), | 77 | ls: Default::default(), |
| 41 | } | 78 | } |
| 42 | } | 79 | } |
| 43 | } | 80 | } |
| 44 | 81 | ||
| 82 | /// Initialize and Set the clock frequencies | ||
| 45 | pub(crate) unsafe fn init(config: Config) { | 83 | pub(crate) unsafe fn init(config: Config) { |
| 46 | let sysclk = config.sys_ck.map(|v| v.0).unwrap_or(HSI_FREQ.0); | 84 | // Configure HSI |
| 85 | let hsi = match config.hsi { | ||
| 86 | false => { | ||
| 87 | RCC.cr().modify(|w| w.set_hsion(false)); | ||
| 88 | None | ||
| 89 | } | ||
| 90 | true => { | ||
| 91 | RCC.cr().modify(|w| w.set_hsion(true)); | ||
| 92 | while !RCC.cr().read().hsirdy() {} | ||
| 93 | Some(HSI_FREQ) | ||
| 94 | } | ||
| 95 | }; | ||
| 47 | 96 | ||
| 97 | // Configure HSE | ||
| 98 | let hse = match config.hse { | ||
| 99 | None => { | ||
| 100 | RCC.cr().modify(|w| w.set_hseon(false)); | ||
| 101 | None | ||
| 102 | } | ||
| 103 | Some(hse) => { | ||
| 104 | match hse.mode { | ||
| 105 | HseMode::Bypass => assert!(max::HSE_BYP.contains(&hse.freq)), | ||
| 106 | HseMode::Oscillator => assert!(max::HSE_OSC.contains(&hse.freq)), | ||
| 107 | } | ||
| 108 | |||
| 109 | RCC.cr().modify(|w| w.set_hsebyp(hse.mode != HseMode::Oscillator)); | ||
| 110 | RCC.cr().modify(|w| w.set_hseon(true)); | ||
| 111 | while !RCC.cr().read().hserdy() {} | ||
| 112 | Some(hse.freq) | ||
| 113 | } | ||
| 114 | }; | ||
| 115 | |||
| 116 | // configure HSI48 | ||
| 48 | #[cfg(crs)] | 117 | #[cfg(crs)] |
| 49 | let hsi48 = config.hsi48.map(|config| super::init_hsi48(config)); | 118 | let hsi48 = config.hsi48.map(|config| super::init_hsi48(config)); |
| 50 | #[cfg(not(crs))] | 119 | #[cfg(not(crs))] |
| 51 | let hsi48: Option<Hertz> = None; | 120 | let hsi48: Option<Hertz> = None; |
| 52 | 121 | ||
| 53 | let (src_clk, use_hsi48) = config.hse.map(|v| (v.0, false)).unwrap_or_else(|| { | 122 | // Enable PLL |
| 54 | if hsi48.is_some() { | 123 | let pll = config.pll.map(|pll| { |
| 55 | return (48_000_000, true); | 124 | let (src_val, src_freq) = match pll.src { |
| 56 | } | 125 | #[cfg(not(any(rcc_f0v1, rcc_f0v2)))] |
| 57 | (HSI_FREQ.0, false) | 126 | PllSource::HSI => (Pllsrc::HSI_DIV_PREDIV, unwrap!(hsi)), |
| 58 | }); | 127 | #[cfg(any(rcc_f0v1, rcc_f0v2))] |
| 59 | 128 | PllSource::HSI => { | |
| 60 | let (pllmul_bits, real_sysclk) = if sysclk == src_clk { | 129 | if pll.prediv != PllPreDiv::DIV2 { |
| 61 | (None, sysclk) | 130 | panic!("if PLL source is HSI, PLL prediv must be 2."); |
| 62 | } else { | 131 | } |
| 63 | let prediv = if config.hse.is_some() { 1 } else { 2 }; | 132 | (Pllsrc::HSI_DIV2, unwrap!(hsi)) |
| 64 | let pllmul = (2 * prediv * sysclk + src_clk) / src_clk / 2; | 133 | } |
| 65 | let pllmul = pllmul.max(2).min(16); | 134 | PllSource::HSE => (Pllsrc::HSE_DIV_PREDIV, unwrap!(hse)), |
| 66 | 135 | #[cfg(rcc_f0v4)] | |
| 67 | let pllmul_bits = pllmul as u8 - 2; | 136 | PllSource::HSI48 => (Pllsrc::HSI48_DIV_PREDIV, unwrap!(hsi48)), |
| 68 | let real_sysclk = pllmul * src_clk / prediv; | 137 | }; |
| 69 | (Some(pllmul_bits), real_sysclk) | 138 | let in_freq = src_freq / pll.prediv; |
| 70 | }; | 139 | assert!(max::PLL_IN.contains(&in_freq)); |
| 71 | 140 | let out_freq = in_freq * pll.mul; | |
| 72 | let hpre_bits = config | 141 | assert!(max::PLL_OUT.contains(&out_freq)); |
| 73 | .hclk | 142 | |
| 74 | .map(|hclk| match real_sysclk / hclk.0 { | 143 | RCC.cfgr2().modify(|w| w.set_prediv(pll.prediv)); |
| 75 | 0 => unreachable!(), | 144 | RCC.cfgr().modify(|w| { |
| 76 | 1 => 0b0111, | 145 | w.set_pllmul(pll.mul); |
| 77 | 2 => 0b1000, | 146 | w.set_pllsrc(src_val); |
| 78 | 3..=5 => 0b1001, | ||
| 79 | 6..=11 => 0b1010, | ||
| 80 | 12..=39 => 0b1011, | ||
| 81 | 40..=95 => 0b1100, | ||
| 82 | 96..=191 => 0b1101, | ||
| 83 | 192..=383 => 0b1110, | ||
| 84 | _ => 0b1111, | ||
| 85 | }) | ||
| 86 | .unwrap_or(0b0111); | ||
| 87 | let hclk = real_sysclk / (1 << (hpre_bits - 0b0111)); | ||
| 88 | |||
| 89 | let ppre_bits = config | ||
| 90 | .pclk | ||
| 91 | .map(|pclk| match hclk / pclk.0 { | ||
| 92 | 0 => unreachable!(), | ||
| 93 | 1 => 0b011, | ||
| 94 | 2 => 0b100, | ||
| 95 | 3..=5 => 0b101, | ||
| 96 | 6..=11 => 0b110, | ||
| 97 | _ => 0b111, | ||
| 98 | }) | ||
| 99 | .unwrap_or(0b011); | ||
| 100 | |||
| 101 | let ppre: u8 = 1 << (ppre_bits - 0b011); | ||
| 102 | let pclk = hclk / u32::from(ppre); | ||
| 103 | |||
| 104 | let timer_mul = if ppre == 1 { 1 } else { 2 }; | ||
| 105 | |||
| 106 | FLASH.acr().write(|w| { | ||
| 107 | w.set_latency(if real_sysclk <= 24_000_000 { | ||
| 108 | Latency::WS0 | ||
| 109 | } else { | ||
| 110 | Latency::WS1 | ||
| 111 | }); | 147 | }); |
| 148 | RCC.cr().modify(|w| w.set_pllon(true)); | ||
| 149 | while !RCC.cr().read().pllrdy() {} | ||
| 150 | |||
| 151 | out_freq | ||
| 112 | }); | 152 | }); |
| 113 | 153 | ||
| 114 | match (config.hse.is_some(), use_hsi48) { | 154 | // Configure sysclk |
| 115 | (true, _) => { | 155 | let sys = match config.sys { |
| 116 | RCC.cr().modify(|w| { | 156 | Sysclk::HSI => unwrap!(hsi), |
| 117 | w.set_csson(true); | 157 | Sysclk::HSE => unwrap!(hse), |
| 118 | w.set_hseon(true); | 158 | Sysclk::PLL1_P => unwrap!(pll), |
| 119 | w.set_hsebyp(config.bypass_hse); | 159 | #[cfg(rcc_f0v4)] |
| 120 | }); | 160 | Sysclk::HSI48 => unwrap!(hsi48), |
| 121 | while !RCC.cr().read().hserdy() {} | 161 | #[allow(unreachable_patterns)] |
| 162 | _ => unreachable!(), | ||
| 163 | }; | ||
| 122 | 164 | ||
| 123 | if pllmul_bits.is_some() { | 165 | let hclk = sys / config.ahb_pre; |
| 124 | RCC.cfgr().modify(|w| w.set_pllsrc(Pllsrc::HSE_DIV_PREDIV)) | 166 | let (pclk1, pclk1_tim) = super::util::calc_pclk(hclk, config.apb1_pre); |
| 125 | } | ||
| 126 | } | ||
| 127 | // use_hsi48 will always be false for stm32f0x0 | ||
| 128 | #[cfg(not(stm32f0x0))] | ||
| 129 | (false, true) => { | ||
| 130 | RCC.cr2().modify(|w| w.set_hsi48on(true)); | ||
| 131 | while !RCC.cr2().read().hsi48rdy() {} | ||
| 132 | |||
| 133 | if pllmul_bits.is_some() { | ||
| 134 | RCC.cfgr().modify(|w| w.set_pllsrc(Pllsrc::HSI48_DIV_PREDIV)) | ||
| 135 | } | ||
| 136 | } | ||
| 137 | _ => { | ||
| 138 | RCC.cr().modify(|w| w.set_hsion(true)); | ||
| 139 | while !RCC.cr().read().hsirdy() {} | ||
| 140 | 167 | ||
| 141 | if pllmul_bits.is_some() { | 168 | assert!(max::HCLK.contains(&hclk)); |
| 142 | RCC.cfgr().modify(|w| w.set_pllsrc(Pllsrc::HSI_DIV2)) | 169 | assert!(max::PCLK1.contains(&pclk1)); |
| 143 | } | ||
| 144 | } | ||
| 145 | } | ||
| 146 | 170 | ||
| 147 | if config.usb_pll { | 171 | // Set latency based on HCLK frquency |
| 148 | RCC.cfgr3().modify(|w| w.set_usbsw(Usbsw::PLL1_P)); | 172 | let latency = match hclk.0 { |
| 149 | } | 173 | ..=24_000_000 => Latency::WS0, |
| 150 | // TODO: Option to use CRS (Clock Recovery) | 174 | _ => Latency::WS1, |
| 175 | }; | ||
| 176 | FLASH.acr().modify(|w| { | ||
| 177 | w.set_latency(latency); | ||
| 178 | w.set_prftbe(true); | ||
| 179 | }); | ||
| 151 | 180 | ||
| 152 | if let Some(pllmul_bits) = pllmul_bits { | 181 | // Set prescalers |
| 153 | RCC.cfgr().modify(|w| w.set_pllmul(Pllmul::from_bits(pllmul_bits))); | 182 | // CFGR has been written before (PLL, PLL48) don't overwrite these settings |
| 183 | RCC.cfgr().modify(|w| { | ||
| 184 | w.set_ppre(config.apb1_pre); | ||
| 185 | w.set_hpre(config.ahb_pre); | ||
| 186 | }); | ||
| 154 | 187 | ||
| 155 | RCC.cr().modify(|w| w.set_pllon(true)); | 188 | // Wait for the new prescalers to kick in |
| 156 | while !RCC.cr().read().pllrdy() {} | 189 | // "The clocks are divided with the new prescaler factor from |
| 190 | // 1 to 16 AHB cycles after write" | ||
| 191 | cortex_m::asm::delay(16); | ||
| 157 | 192 | ||
| 158 | RCC.cfgr().modify(|w| { | 193 | // CFGR has been written before (PLL, PLL48, clock divider) don't overwrite these settings |
| 159 | w.set_ppre(Ppre::from_bits(ppre_bits)); | 194 | RCC.cfgr().modify(|w| w.set_sw(config.sys)); |
| 160 | w.set_hpre(Hpre::from_bits(hpre_bits)); | 195 | while RCC.cfgr().read().sws() != config.sys {} |
| 161 | w.set_sw(Sw::PLL1_P) | ||
| 162 | }); | ||
| 163 | } else { | ||
| 164 | RCC.cfgr().modify(|w| { | ||
| 165 | w.set_ppre(Ppre::from_bits(ppre_bits)); | ||
| 166 | w.set_hpre(Hpre::from_bits(hpre_bits)); | ||
| 167 | |||
| 168 | if config.hse.is_some() { | ||
| 169 | w.set_sw(Sw::HSE); | ||
| 170 | } else if use_hsi48 { | ||
| 171 | #[cfg(not(stm32f0x0))] | ||
| 172 | w.set_sw(Sw::HSI48); | ||
| 173 | } else { | ||
| 174 | w.set_sw(Sw::HSI) | ||
| 175 | } | ||
| 176 | }) | ||
| 177 | } | ||
| 178 | 196 | ||
| 179 | let rtc = config.ls.init(); | 197 | let rtc = config.ls.init(); |
| 180 | 198 | ||
| 181 | set_clocks!( | 199 | set_clocks!( |
| 182 | hsi: None, | 200 | hsi: hsi, |
| 183 | lse: None, | 201 | hse: hse, |
| 184 | sys: Some(Hertz(real_sysclk)), | 202 | pll1_p: pll, |
| 185 | pclk1: Some(Hertz(pclk)), | 203 | sys: Some(sys), |
| 186 | pclk2: Some(Hertz(pclk)), | 204 | pclk1: Some(pclk1), |
| 187 | pclk1_tim: Some(Hertz(pclk * timer_mul)), | 205 | pclk2: Some(pclk1), |
| 188 | pclk2_tim: Some(Hertz(pclk * timer_mul)), | 206 | pclk1_tim: Some(pclk1_tim), |
| 189 | hclk1: Some(Hertz(hclk)), | 207 | pclk2_tim: Some(pclk1_tim), |
| 190 | rtc: rtc, | 208 | hclk1: Some(hclk), |
| 209 | #[cfg(all(not(rcc_f37), adc3_common))] | ||
| 210 | adc34: Some(adc34), | ||
| 211 | #[cfg(stm32f334)] | ||
| 212 | hrtim: hrtim, | ||
| 191 | hsi48: hsi48, | 213 | hsi48: hsi48, |
| 192 | 214 | rtc: rtc, | |
| 193 | // TODO: | 215 | lse: None, |
| 194 | pll1_p: None, | ||
| 195 | ); | 216 | ); |
| 196 | } | 217 | } |
| 218 | |||
| 219 | mod max { | ||
| 220 | use core::ops::RangeInclusive; | ||
| 221 | |||
| 222 | use crate::time::Hertz; | ||
| 223 | |||
| 224 | pub(crate) const HSE_OSC: RangeInclusive<Hertz> = Hertz(4_000_000)..=Hertz(32_000_000); | ||
| 225 | pub(crate) const HSE_BYP: RangeInclusive<Hertz> = Hertz(1_000_000)..=Hertz(32_000_000); | ||
| 226 | |||
| 227 | pub(crate) const HCLK: RangeInclusive<Hertz> = Hertz(0)..=Hertz(48_000_000); | ||
| 228 | pub(crate) const PCLK1: RangeInclusive<Hertz> = Hertz(0)..=Hertz(48_000_000); | ||
| 229 | |||
| 230 | pub(crate) const PLL_IN: RangeInclusive<Hertz> = Hertz(1_000_000)..=Hertz(24_000_000); | ||
| 231 | pub(crate) const PLL_OUT: RangeInclusive<Hertz> = Hertz(16_000_000)..=Hertz(48_000_000); | ||
| 232 | } | ||
diff --git a/embassy-stm32/src/rcc/mco.rs b/embassy-stm32/src/rcc/mco.rs index db0df9fac..654943bc1 100644 --- a/embassy-stm32/src/rcc/mco.rs +++ b/embassy-stm32/src/rcc/mco.rs | |||
| @@ -4,7 +4,7 @@ use embassy_hal_internal::into_ref; | |||
| 4 | 4 | ||
| 5 | use crate::gpio::sealed::AFType; | 5 | use crate::gpio::sealed::AFType; |
| 6 | use crate::gpio::Speed; | 6 | use crate::gpio::Speed; |
| 7 | #[cfg(not(any(stm32f1, rcc_f3v1, rcc_f37)))] | 7 | #[cfg(not(any(stm32f1, rcc_f0v1, rcc_f3v1, rcc_f37)))] |
| 8 | pub use crate::pac::rcc::vals::Mcopre as McoPrescaler; | 8 | pub use crate::pac::rcc::vals::Mcopre as McoPrescaler; |
| 9 | #[cfg(not(any(rcc_f2, rcc_f410, rcc_f4, rcc_f7, rcc_h50, rcc_h5, rcc_h7ab, rcc_h7rm0433, rcc_h7)))] | 9 | #[cfg(not(any(rcc_f2, rcc_f410, rcc_f4, rcc_f7, rcc_h50, rcc_h5, rcc_h7ab, rcc_h7rm0433, rcc_h7)))] |
| 10 | pub use crate::pac::rcc::vals::Mcosel as McoSource; | 10 | pub use crate::pac::rcc::vals::Mcosel as McoSource; |
| @@ -13,7 +13,7 @@ pub use crate::pac::rcc::vals::{Mco1sel as Mco1Source, Mco2sel as Mco2Source}; | |||
| 13 | use crate::pac::RCC; | 13 | use crate::pac::RCC; |
| 14 | use crate::{peripherals, Peripheral}; | 14 | use crate::{peripherals, Peripheral}; |
| 15 | 15 | ||
| 16 | #[cfg(any(stm32f1, rcc_f3v1, rcc_f37))] | 16 | #[cfg(any(stm32f1, rcc_f0v1, rcc_f3v1, rcc_f37))] |
| 17 | #[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd)] | 17 | #[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd)] |
| 18 | pub enum McoPrescaler { | 18 | pub enum McoPrescaler { |
| 19 | DIV1, | 19 | DIV1, |
| @@ -43,7 +43,7 @@ macro_rules! impl_peri { | |||
| 43 | 43 | ||
| 44 | r.modify(|w| { | 44 | r.modify(|w| { |
| 45 | w.$set_source(source); | 45 | w.$set_source(source); |
| 46 | #[cfg(not(any(stm32f1, rcc_f3v1, rcc_f37)))] | 46 | #[cfg(not(any(stm32f1, rcc_f0v1, rcc_f3v1, rcc_f37)))] |
| 47 | w.$set_prescaler(_prescaler); | 47 | w.$set_prescaler(_prescaler); |
| 48 | }); | 48 | }); |
| 49 | } | 49 | } |
diff --git a/embassy-stm32/src/rcc/mod.rs b/embassy-stm32/src/rcc/mod.rs index 05937cc5d..b7eca0615 100644 --- a/embassy-stm32/src/rcc/mod.rs +++ b/embassy-stm32/src/rcc/mod.rs | |||
| @@ -18,17 +18,17 @@ mod hsi48; | |||
| 18 | #[cfg(crs)] | 18 | #[cfg(crs)] |
| 19 | pub use hsi48::*; | 19 | pub use hsi48::*; |
| 20 | 20 | ||
| 21 | #[cfg_attr(rcc_f0, path = "f0.rs")] | 21 | #[cfg_attr(stm32f0, path = "f0.rs")] |
| 22 | #[cfg_attr(any(stm32f1), path = "f1.rs")] | 22 | #[cfg_attr(stm32f1, path = "f1.rs")] |
| 23 | #[cfg_attr(any(stm32f3), path = "f3.rs")] | 23 | #[cfg_attr(stm32f3, path = "f3.rs")] |
| 24 | #[cfg_attr(any(stm32f2, stm32f4, stm32f7), path = "f.rs")] | 24 | #[cfg_attr(any(stm32f2, stm32f4, stm32f7), path = "f.rs")] |
| 25 | #[cfg_attr(rcc_c0, path = "c0.rs")] | 25 | #[cfg_attr(stm32c0, path = "c0.rs")] |
| 26 | #[cfg_attr(rcc_g0, path = "g0.rs")] | 26 | #[cfg_attr(stm32g0, path = "g0.rs")] |
| 27 | #[cfg_attr(rcc_g4, path = "g4.rs")] | 27 | #[cfg_attr(stm32g4, path = "g4.rs")] |
| 28 | #[cfg_attr(any(stm32h5, stm32h7), path = "h.rs")] | 28 | #[cfg_attr(any(stm32h5, stm32h7), path = "h.rs")] |
| 29 | #[cfg_attr(any(stm32l0, stm32l1, stm32l4, stm32l5, stm32wb, stm32wl), path = "l.rs")] | 29 | #[cfg_attr(any(stm32l0, stm32l1, stm32l4, stm32l5, stm32wb, stm32wl), path = "l.rs")] |
| 30 | #[cfg_attr(rcc_u5, path = "u5.rs")] | 30 | #[cfg_attr(stm32u5, path = "u5.rs")] |
| 31 | #[cfg_attr(rcc_wba, path = "wba.rs")] | 31 | #[cfg_attr(stm32wba, path = "wba.rs")] |
| 32 | mod _version; | 32 | mod _version; |
| 33 | 33 | ||
| 34 | pub use _version::*; | 34 | pub use _version::*; |
