aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarco Pastrello <[email protected]>2023-05-04 22:59:52 +0200
committerMarco Pastrello <[email protected]>2023-05-04 22:59:52 +0200
commit5158014f3f77b20db34dd398633fc26e8e7d2e60 (patch)
tree7cae4065e9482c0fc7d573095f9754b7d8112283
parent1cc61dc68a64398159214018296c6a6141e760c5 (diff)
PPLXTPRE is a bool.
This flag for example permits the following clock tree configuration on stm32f103r8 let mut config = Config::default(); config.rcc.hse = Some(Hertz(16_000_000)); config.rcc.sys_ck = Some(Hertz(72_000_000)); config.rcc.pclk1 = Some(Hertz(36_000_000)); config.rcc.pclk2 = Some(Hertz(72_000_000)); config.rcc.pllxtpre = true; Init fails if pllxtpre is false.
-rw-r--r--embassy-stm32/src/rcc/f1.rs9
1 files changed, 3 insertions, 6 deletions
diff --git a/embassy-stm32/src/rcc/f1.rs b/embassy-stm32/src/rcc/f1.rs
index 1c14429fc..620638abd 100644
--- a/embassy-stm32/src/rcc/f1.rs
+++ b/embassy-stm32/src/rcc/f1.rs
@@ -24,14 +24,11 @@ pub struct Config {
24 pub pclk1: Option<Hertz>, 24 pub pclk1: Option<Hertz>,
25 pub pclk2: Option<Hertz>, 25 pub pclk2: Option<Hertz>,
26 pub adcclk: Option<Hertz>, 26 pub adcclk: Option<Hertz>,
27 pub pllxtpre: Option<bool>, 27 pub pllxtpre: bool,
28} 28}
29 29
30pub(crate) unsafe fn init(config: Config) { 30pub(crate) unsafe fn init(config: Config) {
31 let pllsrcclk = config.hse.map(|hse| hse.0 / match config.pllxtpre { 31 let pllsrcclk = config.hse.map(|hse| hse.0 / if config.pllxtpre {2} else {1}).unwrap_or(HSI_FREQ.0 / 2);
32 Some(b) => if b {2} else {1},
33 None => {1},
34 }).unwrap_or(HSI_FREQ.0 / 2);
35 32
36 let sysclk = config.sys_ck.map(|sys| sys.0).unwrap_or(pllsrcclk); 33 let sysclk = config.sys_ck.map(|sys| sys.0).unwrap_or(pllsrcclk);
37 let pllmul = sysclk / pllsrcclk; 34 let pllmul = sysclk / pllsrcclk;
@@ -148,7 +145,7 @@ pub(crate) unsafe fn init(config: Config) {
148 } 145 }
149 146
150 if let Some(pllmul_bits) = pllmul_bits { 147 if let Some(pllmul_bits) = pllmul_bits {
151 RCC.cfgr().modify(|w| w.set_pllxtpre(Pllxtpre(config.pllxtpre.is_some() as u8))); 148 RCC.cfgr().modify(|w| w.set_pllxtpre(Pllxtpre(if config.pllxtpre {1u8} else {0u8})));
152 // enable PLL and wait for it to be ready 149 // enable PLL and wait for it to be ready
153 RCC.cfgr().modify(|w| { 150 RCC.cfgr().modify(|w| {
154 w.set_pllmul(Pllmul(pllmul_bits)); 151 w.set_pllmul(Pllmul(pllmul_bits));