aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-stm32/src/rcc/f247.rs25
1 files changed, 24 insertions, 1 deletions
diff --git a/embassy-stm32/src/rcc/f247.rs b/embassy-stm32/src/rcc/f247.rs
index 79d793dcc..8ce9d5f5b 100644
--- a/embassy-stm32/src/rcc/f247.rs
+++ b/embassy-stm32/src/rcc/f247.rs
@@ -1,5 +1,7 @@
1use stm32_metapac::flash::vals::Latency; 1use stm32_metapac::flash::vals::Latency;
2 2
3#[cfg(any(stm32f413, stm32f423, stm32f412))]
4pub use crate::pac::rcc::vals::Plli2ssrc as Plli2sSource;
3pub use crate::pac::rcc::vals::{ 5pub use crate::pac::rcc::vals::{
4 Hpre as AHBPrescaler, Pllm as PllPreDiv, Plln as PllMul, Pllp as PllPDiv, Pllq as PllQDiv, Pllr as PllRDiv, 6 Hpre as AHBPrescaler, Pllm as PllPreDiv, Plln as PllMul, Pllp as PllPDiv, Pllq as PllQDiv, Pllr as PllRDiv,
5 Pllsrc as PllSource, Ppre as APBPrescaler, Sw as Sysclk, 7 Pllsrc as PllSource, Ppre as APBPrescaler, Sw as Sysclk,
@@ -84,6 +86,8 @@ pub struct Config {
84 pub sys: Sysclk, 86 pub sys: Sysclk,
85 87
86 pub pll_src: PllSource, 88 pub pll_src: PllSource,
89 #[cfg(any(stm32f412, stm32f413, stm32f423))]
90 pub external_i2s_clock: Option<Hertz>,
87 91
88 pub pll: Option<Pll>, 92 pub pll: Option<Pll>,
89 #[cfg(any(stm32f2, all(stm32f4, not(stm32f410)), stm32f7))] 93 #[cfg(any(stm32f2, all(stm32f4, not(stm32f410)), stm32f7))]
@@ -111,6 +115,8 @@ impl Default for Config {
111 hse: None, 115 hse: None,
112 sys: Sysclk::HSI, 116 sys: Sysclk::HSI,
113 pll_src: PllSource::HSI, 117 pll_src: PllSource::HSI,
118 #[cfg(any(stm32f412, stm32f413, stm32f423))]
119 external_i2s_clock: None,
114 pll: None, 120 pll: None,
115 #[cfg(any(stm32f2, all(stm32f4, not(stm32f410)), stm32f7))] 121 #[cfg(any(stm32f2, all(stm32f4, not(stm32f410)), stm32f7))]
116 plli2s: None, 122 plli2s: None,
@@ -185,6 +191,8 @@ pub(crate) unsafe fn init(config: Config) {
185 let pll_input = PllInput { 191 let pll_input = PllInput {
186 hse, 192 hse,
187 hsi, 193 hsi,
194 #[cfg(any(stm32f412, stm32f413, stm32f423))]
195 external: config.external_i2s_clock,
188 source: config.pll_src, 196 source: config.pll_src,
189 }; 197 };
190 let pll = init_pll(PllInstance::Pll, config.pll, &pll_input); 198 let pll = init_pll(PllInstance::Pll, config.pll, &pll_input);
@@ -318,6 +326,8 @@ struct PllInput {
318 source: PllSource, 326 source: PllSource,
319 hsi: Option<Hertz>, 327 hsi: Option<Hertz>,
320 hse: Option<Hertz>, 328 hse: Option<Hertz>,
329 #[cfg(any(stm32f412, stm32f413, stm32f423))]
330 external: Option<Hertz>,
321} 331}
322 332
323#[derive(Default)] 333#[derive(Default)]
@@ -362,10 +372,17 @@ fn init_pll(instance: PllInstance, config: Option<Pll>, input: &PllInput) -> Pll
362 372
363 let Some(pll) = config else { return PllOutput::default() }; 373 let Some(pll) = config else { return PllOutput::default() };
364 374
375 #[cfg(not(any(stm32f412, stm32f413, stm32f423)))]
365 let pll_src = match input.source { 376 let pll_src = match input.source {
366 PllSource::HSE => input.hse, 377 PllSource::HSE => input.hse,
367 PllSource::HSI => input.hsi, 378 PllSource::HSI => input.hsi,
368 }; 379 };
380 #[cfg(any(stm32f412, stm32f413, stm32f423))]
381 let pll_src = match (input.source, input.external) {
382 (PllSource::HSE, None) => input.hse,
383 (PllSource::HSI, None) => input.hsi,
384 (_, Some(ext)) => Some(ext),
385 };
369 386
370 let pll_src = pll_src.unwrap(); 387 let pll_src = pll_src.unwrap();
371 388
@@ -417,7 +434,13 @@ fn init_pll(instance: PllInstance, config: Option<Pll>, input: &PllInput) -> Pll
417 #[cfg(any(stm32f411, stm32f412, stm32f413, stm32f423, stm32f446))] 434 #[cfg(any(stm32f411, stm32f412, stm32f413, stm32f423, stm32f446))]
418 w.set_pllm(pll.prediv); 435 w.set_pllm(pll.prediv);
419 #[cfg(any(stm32f412, stm32f413, stm32f423))] 436 #[cfg(any(stm32f412, stm32f413, stm32f423))]
420 w.set_pllsrc(input.source); 437 {
438 let plli2ssource = match input.external {
439 Some(_) => Plli2sSource::EXTERNAL,
440 None => Plli2sSource::HSE_HSI,
441 };
442 w.set_plli2ssrc(plli2ssource);
443 }
421 444
422 write_fields!(w); 445 write_fields!(w);
423 }), 446 }),