diff options
| author | Martin Algesten <[email protected]> | 2025-01-24 09:08:11 +0100 |
|---|---|---|
| committer | Martin Algesten <[email protected]> | 2025-01-24 09:16:24 +0100 |
| commit | c72d9ec8599e3474344f8daf8c2e5a7236201e03 (patch) | |
| tree | 6a3521b9fd01147f6f16611ff495eacdaa9b972a | |
| parent | 9a159a8db0638ea2971eed130a2ae34743da640a (diff) | |
Review fixes
| -rw-r--r-- | embassy-stm32/build.rs | 2 | ||||
| -rw-r--r-- | embassy-stm32/src/rcc/f013.rs | 77 |
2 files changed, 29 insertions, 50 deletions
diff --git a/embassy-stm32/build.rs b/embassy-stm32/build.rs index 4abbf8d69..09fcc0d03 100644 --- a/embassy-stm32/build.rs +++ b/embassy-stm32/build.rs | |||
| @@ -1383,7 +1383,7 @@ fn main() { | |||
| 1383 | for e in rcc_registers.ir.enums { | 1383 | for e in rcc_registers.ir.enums { |
| 1384 | fn is_rcc_name(e: &str) -> bool { | 1384 | fn is_rcc_name(e: &str) -> bool { |
| 1385 | match e { | 1385 | match e { |
| 1386 | "Pllp" | "Pllq" | "Pllr" | "Pllm" | "Plln" => true, | 1386 | "Pllp" | "Pllq" | "Pllr" | "Pllm" | "Plln" | "Prediv1" | "Prediv2" => true, |
| 1387 | "Timpre" | "Pllrclkpre" => false, | 1387 | "Timpre" | "Pllrclkpre" => false, |
| 1388 | e if e.ends_with("pre") || e.ends_with("pres") || e.ends_with("div") || e.ends_with("mul") => true, | 1388 | e if e.ends_with("pre") || e.ends_with("pres") || e.ends_with("div") || e.ends_with("mul") => true, |
| 1389 | _ => false, | 1389 | _ => false, |
diff --git a/embassy-stm32/src/rcc/f013.rs b/embassy-stm32/src/rcc/f013.rs index 27e43fa56..d256ace8f 100644 --- a/embassy-stm32/src/rcc/f013.rs +++ b/embassy-stm32/src/rcc/f013.rs | |||
| @@ -41,6 +41,8 @@ pub enum PllSource { | |||
| 41 | HSI, | 41 | HSI, |
| 42 | #[cfg(rcc_f0v4)] | 42 | #[cfg(rcc_f0v4)] |
| 43 | HSI48, | 43 | HSI48, |
| 44 | #[cfg(stm32f107)] | ||
| 45 | PLL2, | ||
| 44 | } | 46 | } |
| 45 | 47 | ||
| 46 | #[derive(Clone, Copy)] | 48 | #[derive(Clone, Copy)] |
| @@ -100,9 +102,7 @@ pub struct Config { | |||
| 100 | #[cfg(stm32f107)] | 102 | #[cfg(stm32f107)] |
| 101 | pub pll3: Option<Pll2Or3>, | 103 | pub pll3: Option<Pll2Or3>, |
| 102 | #[cfg(stm32f107)] | 104 | #[cfg(stm32f107)] |
| 103 | pub prediv1_src: Option<PreDiv1Src>, | 105 | pub prediv2: PllPreDiv, |
| 104 | #[cfg(stm32f107)] | ||
| 105 | pub prediv2: Option<PllPreDiv>, | ||
| 106 | 106 | ||
| 107 | pub ahb_pre: AHBPrescaler, | 107 | pub ahb_pre: AHBPrescaler, |
| 108 | pub apb1_pre: APBPrescaler, | 108 | pub apb1_pre: APBPrescaler, |
| @@ -118,9 +118,9 @@ pub struct Config { | |||
| 118 | pub adc34: AdcClockSource, | 118 | pub adc34: AdcClockSource, |
| 119 | 119 | ||
| 120 | #[cfg(stm32f107)] | 120 | #[cfg(stm32f107)] |
| 121 | pub i2s2_src: Option<I2s2src>, | 121 | pub i2s2_src: I2s2src, |
| 122 | #[cfg(stm32f107)] | 122 | #[cfg(stm32f107)] |
| 123 | pub i2s3_src: Option<I2s2src>, | 123 | pub i2s3_src: I2s2src, |
| 124 | 124 | ||
| 125 | /// Per-peripheral kernel clock selection muxes | 125 | /// Per-peripheral kernel clock selection muxes |
| 126 | pub mux: super::mux::ClockMux, | 126 | pub mux: super::mux::ClockMux, |
| @@ -143,9 +143,7 @@ impl Default for Config { | |||
| 143 | #[cfg(stm32f107)] | 143 | #[cfg(stm32f107)] |
| 144 | pll3: None, | 144 | pll3: None, |
| 145 | #[cfg(stm32f107)] | 145 | #[cfg(stm32f107)] |
| 146 | prediv1_src: None, | 146 | prediv2: PllPreDiv::DIV1, |
| 147 | #[cfg(stm32f107)] | ||
| 148 | prediv2: None, | ||
| 149 | 147 | ||
| 150 | ahb_pre: AHBPrescaler::DIV1, | 148 | ahb_pre: AHBPrescaler::DIV1, |
| 151 | apb1_pre: APBPrescaler::DIV1, | 149 | apb1_pre: APBPrescaler::DIV1, |
| @@ -163,9 +161,9 @@ impl Default for Config { | |||
| 163 | adc34: AdcClockSource::Hclk(AdcHclkPrescaler::Div1), | 161 | adc34: AdcClockSource::Hclk(AdcHclkPrescaler::Div1), |
| 164 | 162 | ||
| 165 | #[cfg(stm32f107)] | 163 | #[cfg(stm32f107)] |
| 166 | i2s2_src: None, | 164 | i2s2_src: I2s2src::SYS, |
| 167 | #[cfg(stm32f107)] | 165 | #[cfg(stm32f107)] |
| 168 | i2s3_src: None, | 166 | i2s3_src: I2s2src::SYS, |
| 169 | 167 | ||
| 170 | mux: Default::default(), | 168 | mux: Default::default(), |
| 171 | } | 169 | } |
| @@ -207,13 +205,6 @@ pub(crate) unsafe fn init(config: Config) { | |||
| 207 | } | 205 | } |
| 208 | }; | 206 | }; |
| 209 | 207 | ||
| 210 | #[cfg(stm32f107)] | ||
| 211 | let pll2freq = config.pll2.map(|pll2| { | ||
| 212 | let prediv2 = config.prediv2.unwrap_or(PllPreDiv::DIV1); | ||
| 213 | let in_freq = hse.unwrap() / (prediv2.to_bits() + 1); | ||
| 214 | in_freq * pll2.mul | ||
| 215 | }); | ||
| 216 | |||
| 217 | // configure HSI48 | 208 | // configure HSI48 |
| 218 | #[cfg(crs)] | 209 | #[cfg(crs)] |
| 219 | let hsi48 = config.hsi48.map(|config| super::init_hsi48(config)); | 210 | let hsi48 = config.hsi48.map(|config| super::init_hsi48(config)); |
| @@ -222,8 +213,6 @@ pub(crate) unsafe fn init(config: Config) { | |||
| 222 | 213 | ||
| 223 | // Enable PLL | 214 | // Enable PLL |
| 224 | let pll = config.pll.map(|pll| { | 215 | let pll = config.pll.map(|pll| { |
| 225 | #[cfg(stm32f107)] | ||
| 226 | let prediv1_src = config.prediv1_src.unwrap_or(PreDiv1Src::HSE); | ||
| 227 | let (src_val, src_freq) = match pll.src { | 216 | let (src_val, src_freq) = match pll.src { |
| 228 | #[cfg(any(rcc_f0v3, rcc_f0v4, rcc_f3v3))] | 217 | #[cfg(any(rcc_f0v3, rcc_f0v4, rcc_f3v3))] |
| 229 | PllSource::HSI => (Pllsrc::HSI_DIV_PREDIV, unwrap!(hsi)), | 218 | PllSource::HSI => (Pllsrc::HSI_DIV_PREDIV, unwrap!(hsi)), |
| @@ -234,25 +223,28 @@ pub(crate) unsafe fn init(config: Config) { | |||
| 234 | } | 223 | } |
| 235 | (Pllsrc::HSI_DIV2, unwrap!(hsi)) | 224 | (Pllsrc::HSI_DIV2, unwrap!(hsi)) |
| 236 | } | 225 | } |
| 237 | #[cfg(not(stm32f107))] | 226 | PllSource::HSE => { |
| 238 | PllSource::HSE => (Pllsrc::HSE_DIV_PREDIV, unwrap!(hse)), | 227 | #[cfg(stm32f107)] |
| 239 | #[cfg(stm32f107)] | 228 | RCC.cfgr2().modify(|w| w.set_prediv1src(PreDiv1Src::HSE)); |
| 240 | PllSource::HSE => ( | 229 | |
| 241 | Pllsrc::HSE_DIV_PREDIV, | 230 | (Pllsrc::HSE_DIV_PREDIV, unwrap!(hse)) |
| 242 | match prediv1_src { | 231 | } |
| 243 | PreDiv1Src::HSE => unwrap!(hse), | ||
| 244 | PreDiv1Src::PLL2 => unwrap!(pll2freq), | ||
| 245 | }, | ||
| 246 | ), | ||
| 247 | #[cfg(rcc_f0v4)] | 232 | #[cfg(rcc_f0v4)] |
| 248 | PllSource::HSI48 => (Pllsrc::HSI48_DIV_PREDIV, unwrap!(hsi48)), | 233 | PllSource::HSI48 => (Pllsrc::HSI48_DIV_PREDIV, unwrap!(hsi48)), |
| 234 | #[cfg(stm32f107)] | ||
| 235 | PllSource::PLL2 => { | ||
| 236 | if config.pll2.is_none() { | ||
| 237 | panic!("if PLL source is PLL2, Config::pll2 must also be set."); | ||
| 238 | } | ||
| 239 | let pll2 = unwrap!(config.pll2); | ||
| 240 | let in_freq = hse.unwrap() / config.prediv2; | ||
| 241 | let pll2freq = in_freq * pll2.mul; | ||
| 242 | RCC.cfgr2().modify(|w| w.set_prediv1src(PreDiv1Src::PLL2)); | ||
| 243 | (Pllsrc::HSE_DIV_PREDIV, pll2freq) | ||
| 244 | } | ||
| 249 | }; | 245 | }; |
| 250 | #[cfg(not(stm32f107))] | ||
| 251 | let in_freq = src_freq / pll.prediv; | 246 | let in_freq = src_freq / pll.prediv; |
| 252 | 247 | ||
| 253 | #[cfg(stm32f107)] | ||
| 254 | let in_freq = src_freq / (pll.prediv.to_bits() + 1); | ||
| 255 | |||
| 256 | rcc_assert!(max::PLL_IN.contains(&in_freq)); | 248 | rcc_assert!(max::PLL_IN.contains(&in_freq)); |
| 257 | let out_freq = in_freq * pll.mul; | 249 | let out_freq = in_freq * pll.mul; |
| 258 | rcc_assert!(max::PLL_OUT.contains(&out_freq)); | 250 | rcc_assert!(max::PLL_OUT.contains(&out_freq)); |
| @@ -275,19 +267,11 @@ pub(crate) unsafe fn init(config: Config) { | |||
| 275 | out_freq | 267 | out_freq |
| 276 | }); | 268 | }); |
| 277 | 269 | ||
| 278 | // Prediv1 Source Mux (HSE or PLL2) | ||
| 279 | #[cfg(stm32f107)] | ||
| 280 | if let Some(prediv1_src) = config.prediv1_src { | ||
| 281 | RCC.cfgr2().modify(|w| w.set_prediv1src(prediv1_src)); | ||
| 282 | } | ||
| 283 | |||
| 284 | // pll2 and pll3 | 270 | // pll2 and pll3 |
| 285 | #[cfg(stm32f107)] | 271 | #[cfg(stm32f107)] |
| 286 | { | 272 | { |
| 287 | // Common prediv for PLL2 and PLL3 | 273 | // Common prediv for PLL2 and PLL3 |
| 288 | if let Some(prediv) = config.prediv2 { | 274 | RCC.cfgr2().modify(|w| w.set_prediv2(config.prediv2)); |
| 289 | RCC.cfgr2().modify(|w| w.set_prediv2(prediv)); | ||
| 290 | } | ||
| 291 | 275 | ||
| 292 | // Configure PLL2 | 276 | // Configure PLL2 |
| 293 | if let Some(pll2) = config.pll2 { | 277 | if let Some(pll2) = config.pll2 { |
| @@ -390,13 +374,8 @@ pub(crate) unsafe fn init(config: Config) { | |||
| 390 | // I2S2 and I2S3 | 374 | // I2S2 and I2S3 |
| 391 | #[cfg(stm32f107)] | 375 | #[cfg(stm32f107)] |
| 392 | { | 376 | { |
| 393 | if let Some(i2s2_src) = config.i2s2_src { | 377 | RCC.cfgr2().modify(|w| w.set_i2s2src(config.i2s2_src)); |
| 394 | RCC.cfgr2().modify(|w| w.set_i2s2src(i2s2_src)); | 378 | RCC.cfgr2().modify(|w| w.set_i2s3src(config.i2s3_src)); |
| 395 | } | ||
| 396 | |||
| 397 | if let Some(i2s3_src) = config.i2s3_src { | ||
| 398 | RCC.cfgr2().modify(|w| w.set_i2s3src(i2s3_src)); | ||
| 399 | } | ||
| 400 | } | 379 | } |
| 401 | 380 | ||
| 402 | // Wait for the new prescalers to kick in | 381 | // Wait for the new prescalers to kick in |
