diff options
| author | antonello.contini <[email protected]> | 2025-02-25 21:21:23 +0100 |
|---|---|---|
| committer | antonello.contini <[email protected]> | 2025-02-25 21:21:23 +0100 |
| commit | 51085a5e949317a578e5253d8eaccf247ccc47cc (patch) | |
| tree | 4ea7abf7b379503cd33377a0e4c438795f04436a | |
| parent | f1c7e388e61bd9ba2362032dd45c9ab91cf3882f (diff) | |
let user set external i2s clock frequency
| -rw-r--r-- | embassy-stm32/src/rcc/f247.rs | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/embassy-stm32/src/rcc/f247.rs b/embassy-stm32/src/rcc/f247.rs index 7426b6792..52d093609 100644 --- a/embassy-stm32/src/rcc/f247.rs +++ b/embassy-stm32/src/rcc/f247.rs | |||
| @@ -89,6 +89,8 @@ pub struct Config { | |||
| 89 | pub pll_src: PllSource, | 89 | pub pll_src: PllSource, |
| 90 | #[cfg(any(stm32f413, stm32f423, stm32f412))] | 90 | #[cfg(any(stm32f413, stm32f423, stm32f412))] |
| 91 | pub plli2s_src: Plli2sSource, | 91 | pub plli2s_src: Plli2sSource, |
| 92 | #[cfg(any(stm32f412, stm32f413, stm32f423))] | ||
| 93 | pub external_clock: Option<Hertz>, | ||
| 92 | 94 | ||
| 93 | pub pll: Option<Pll>, | 95 | pub pll: Option<Pll>, |
| 94 | #[cfg(any(stm32f2, all(stm32f4, not(stm32f410)), stm32f7))] | 96 | #[cfg(any(stm32f2, all(stm32f4, not(stm32f410)), stm32f7))] |
| @@ -118,6 +120,8 @@ impl Default for Config { | |||
| 118 | pll_src: PllSource::HSI, | 120 | pll_src: PllSource::HSI, |
| 119 | #[cfg(any(stm32f413, stm32f423, stm32f412))] | 121 | #[cfg(any(stm32f413, stm32f423, stm32f412))] |
| 120 | plli2s_src: Plli2sSource::HSE_HSI, | 122 | plli2s_src: Plli2sSource::HSE_HSI, |
| 123 | #[cfg(any(stm32f412, stm32f413, stm32f423))] | ||
| 124 | external_clock: None, | ||
| 121 | pll: None, | 125 | pll: None, |
| 122 | #[cfg(any(stm32f2, all(stm32f4, not(stm32f410)), stm32f7))] | 126 | #[cfg(any(stm32f2, all(stm32f4, not(stm32f410)), stm32f7))] |
| 123 | plli2s: None, | 127 | plli2s: None, |
| @@ -192,6 +196,8 @@ pub(crate) unsafe fn init(config: Config) { | |||
| 192 | let pll_input = PllInput { | 196 | let pll_input = PllInput { |
| 193 | hse, | 197 | hse, |
| 194 | hsi, | 198 | hsi, |
| 199 | #[cfg(any(stm32f412, stm32f413, stm32f423))] | ||
| 200 | external: config.external_clock, | ||
| 195 | source: config.pll_src, | 201 | source: config.pll_src, |
| 196 | }; | 202 | }; |
| 197 | let pll = init_pll(PllInstance::Pll, config.pll, &pll_input); | 203 | let pll = init_pll(PllInstance::Pll, config.pll, &pll_input); |
| @@ -325,6 +331,8 @@ struct PllInput { | |||
| 325 | source: PllSource, | 331 | source: PllSource, |
| 326 | hsi: Option<Hertz>, | 332 | hsi: Option<Hertz>, |
| 327 | hse: Option<Hertz>, | 333 | hse: Option<Hertz>, |
| 334 | #[cfg(any(stm32f412, stm32f413, stm32f423))] | ||
| 335 | external: Option<Hertz>, | ||
| 328 | } | 336 | } |
| 329 | 337 | ||
| 330 | #[derive(Default)] | 338 | #[derive(Default)] |
| @@ -369,10 +377,17 @@ fn init_pll(instance: PllInstance, config: Option<Pll>, input: &PllInput) -> Pll | |||
| 369 | 377 | ||
| 370 | let Some(pll) = config else { return PllOutput::default() }; | 378 | let Some(pll) = config else { return PllOutput::default() }; |
| 371 | 379 | ||
| 380 | #[cfg(not(any(stm32f412, stm32f413, stm32f423)))] | ||
| 372 | let pll_src = match input.source { | 381 | let pll_src = match input.source { |
| 373 | PllSource::HSE => input.hse, | 382 | PllSource::HSE => input.hse, |
| 374 | PllSource::HSI => input.hsi, | 383 | PllSource::HSI => input.hsi, |
| 375 | }; | 384 | }; |
| 385 | #[cfg(any(stm32f412, stm32f413, stm32f423))] | ||
| 386 | let pll_src = match (input.source, input.external) { | ||
| 387 | (PllSource::HSE, None) => input.hse, | ||
| 388 | (PllSource::HSI, None) => input.hsi, | ||
| 389 | (_, Some(ext)) => Some(ext), | ||
| 390 | }; | ||
| 376 | 391 | ||
| 377 | let pll_src = pll_src.unwrap(); | 392 | let pll_src = pll_src.unwrap(); |
| 378 | 393 | ||
| @@ -424,7 +439,13 @@ fn init_pll(instance: PllInstance, config: Option<Pll>, input: &PllInput) -> Pll | |||
| 424 | #[cfg(any(stm32f411, stm32f412, stm32f413, stm32f423, stm32f446))] | 439 | #[cfg(any(stm32f411, stm32f412, stm32f413, stm32f423, stm32f446))] |
| 425 | w.set_pllm(pll.prediv); | 440 | w.set_pllm(pll.prediv); |
| 426 | #[cfg(any(stm32f412, stm32f413, stm32f423))] | 441 | #[cfg(any(stm32f412, stm32f413, stm32f423))] |
| 427 | w.set_plli2ssrc(Plli2sSource::HSE_HSI); | 442 | { |
| 443 | let plli2ssource = match input.external { | ||
| 444 | Some(_) => Plli2sSource::EXTERNAL, | ||
| 445 | None => Plli2sSource::HSE_HSI, | ||
| 446 | }; | ||
| 447 | w.set_plli2ssrc(plli2ssource); | ||
| 448 | } | ||
| 428 | 449 | ||
| 429 | write_fields!(w); | 450 | write_fields!(w); |
| 430 | }), | 451 | }), |
