diff options
| author | Ulf Lilleengen <[email protected]> | 2021-06-07 12:03:31 +0200 |
|---|---|---|
| committer | Ulf Lilleengen <[email protected]> | 2021-06-07 12:03:31 +0200 |
| commit | f5e2fb9a5a62f90d83ec9d312d6c471a21fbe7c6 (patch) | |
| tree | 7c4c7a54e908384ff63562ed0c691910bc8e6ef2 | |
| parent | f752700df5a20703a3b4d746a524137ef0972b52 (diff) | |
Update to new api
| -rw-r--r-- | embassy-stm32/src/pwr/h7.rs | 5 | ||||
| -rw-r--r-- | embassy-stm32/src/rcc/h7/mod.rs | 47 | ||||
| -rw-r--r-- | embassy-stm32/src/rcc/h7/pll.rs | 22 | ||||
| m--------- | stm32-data | 0 |
4 files changed, 31 insertions, 43 deletions
diff --git a/embassy-stm32/src/pwr/h7.rs b/embassy-stm32/src/pwr/h7.rs index 3d83b5e85..b298408a4 100644 --- a/embassy-stm32/src/pwr/h7.rs +++ b/embassy-stm32/src/pwr/h7.rs | |||
| @@ -28,8 +28,6 @@ pub struct Power { | |||
| 28 | 28 | ||
| 29 | impl Power { | 29 | impl Power { |
| 30 | pub fn new(_peri: peripherals::PWR, enable_overdrive: bool) -> Self { | 30 | pub fn new(_peri: peripherals::PWR, enable_overdrive: bool) -> Self { |
| 31 | use crate::pac::rcc::vals::Apb4enrSyscfgen; | ||
| 32 | |||
| 33 | // NOTE(unsafe) we have the PWR singleton | 31 | // NOTE(unsafe) we have the PWR singleton |
| 34 | unsafe { | 32 | unsafe { |
| 35 | // NB. The lower bytes of CR3 can only be written once after | 33 | // NB. The lower bytes of CR3 can only be written once after |
| @@ -57,8 +55,7 @@ impl Power { | |||
| 57 | VoltageScale::Scale1 | 55 | VoltageScale::Scale1 |
| 58 | } else { | 56 | } else { |
| 59 | critical_section::with(|_| { | 57 | critical_section::with(|_| { |
| 60 | RCC.apb4enr() | 58 | RCC.apb4enr().modify(|w| w.set_syscfgen(true)); |
| 61 | .modify(|w| w.set_syscfgen(Apb4enrSyscfgen::ENABLED)); | ||
| 62 | 59 | ||
| 63 | SYSCFG.pwrcr().modify(|w| w.set_oden(1)); | 60 | SYSCFG.pwrcr().modify(|w| w.set_oden(1)); |
| 64 | }); | 61 | }); |
diff --git a/embassy-stm32/src/rcc/h7/mod.rs b/embassy-stm32/src/rcc/h7/mod.rs index 57cdd5470..f15dbe075 100644 --- a/embassy-stm32/src/rcc/h7/mod.rs +++ b/embassy-stm32/src/rcc/h7/mod.rs | |||
| @@ -101,10 +101,7 @@ impl<'d> Rcc<'d> { | |||
| 101 | /// achieved, but the mechanism for doing so is not yet | 101 | /// achieved, but the mechanism for doing so is not yet |
| 102 | /// implemented here. | 102 | /// implemented here. |
| 103 | pub fn freeze(mut self, pwr: &Power) -> CoreClocks { | 103 | pub fn freeze(mut self, pwr: &Power) -> CoreClocks { |
| 104 | use crate::pac::rcc::vals::{ | 104 | use crate::pac::rcc::vals::{Ckpersel, Dppre, Hpre, Hsebyp, Hsidiv, Pllsrc, Sw}; |
| 105 | Apb4enrSyscfgen, Ckpersel, D1ppre, D2ppre1, D3ppre, Hpre, Hsebyp, Hsidiv, Hsion, Lsion, | ||
| 106 | Pllsrc, Sw, | ||
| 107 | }; | ||
| 108 | 105 | ||
| 109 | let srcclk = self.config.hse.unwrap_or(HSI); // Available clocks | 106 | let srcclk = self.config.hse.unwrap_or(HSI); // Available clocks |
| 110 | let (sys_ck, sys_use_pll1_p) = self.sys_ck_setup(srcclk); | 107 | let (sys_ck, sys_use_pll1_p) = self.sys_ck_setup(srcclk); |
| @@ -132,10 +129,10 @@ impl<'d> Rcc<'d> { | |||
| 132 | // do so it would need to ensure all PLLxON bits are clear | 129 | // do so it would need to ensure all PLLxON bits are clear |
| 133 | // before changing the value of HSIDIV | 130 | // before changing the value of HSIDIV |
| 134 | let cr = RCC.cr().read(); | 131 | let cr = RCC.cr().read(); |
| 135 | assert!(cr.hsion() == Hsion::ON); | 132 | assert!(cr.hsion()); |
| 136 | assert!(cr.hsidiv() == Hsidiv::DIV1); | 133 | assert!(cr.hsidiv() == Hsidiv::DIV1); |
| 137 | 134 | ||
| 138 | RCC.csr().modify(|w| w.set_lsion(Lsion::ON)); | 135 | RCC.csr().modify(|w| w.set_lsion(true)); |
| 139 | while !RCC.csr().read().lsirdy() {} | 136 | while !RCC.csr().read().lsirdy() {} |
| 140 | } | 137 | } |
| 141 | 138 | ||
| @@ -228,12 +225,12 @@ impl<'d> Rcc<'d> { | |||
| 228 | // NOTE(unsafe) We have the RCC singleton | 225 | // NOTE(unsafe) We have the RCC singleton |
| 229 | unsafe { | 226 | unsafe { |
| 230 | // Ensure CSI is on and stable | 227 | // Ensure CSI is on and stable |
| 231 | RCC.cr().modify(|w| w.set_csion(Hsion::ON)); | 228 | RCC.cr().modify(|w| w.set_csion(true)); |
| 232 | while !RCC.cr().read().csirdy() {} | 229 | while !RCC.cr().read().csirdy() {} |
| 233 | 230 | ||
| 234 | // Ensure HSI48 is on and stable | 231 | // Ensure HSI48 is on and stable |
| 235 | RCC.cr().modify(|w| w.set_hsi48on(Hsion::ON)); | 232 | RCC.cr().modify(|w| w.set_hsi48on(true)); |
| 236 | while RCC.cr().read().hsi48on() == Hsion::OFF {} | 233 | while !RCC.cr().read().hsi48on() {} |
| 237 | 234 | ||
| 238 | // XXX: support MCO ? | 235 | // XXX: support MCO ? |
| 239 | 236 | ||
| @@ -241,7 +238,7 @@ impl<'d> Rcc<'d> { | |||
| 241 | Some(hse) => { | 238 | Some(hse) => { |
| 242 | // Ensure HSE is on and stable | 239 | // Ensure HSE is on and stable |
| 243 | RCC.cr().modify(|w| { | 240 | RCC.cr().modify(|w| { |
| 244 | w.set_hseon(Hsion::ON); | 241 | w.set_hseon(true); |
| 245 | w.set_hsebyp(if self.config.bypass_hse { | 242 | w.set_hsebyp(if self.config.bypass_hse { |
| 246 | Hsebyp::BYPASSED | 243 | Hsebyp::BYPASSED |
| 247 | } else { | 244 | } else { |
| @@ -261,25 +258,27 @@ impl<'d> Rcc<'d> { | |||
| 261 | }; | 258 | }; |
| 262 | RCC.pllckselr().modify(|w| w.set_pllsrc(pllsrc)); | 259 | RCC.pllckselr().modify(|w| w.set_pllsrc(pllsrc)); |
| 263 | 260 | ||
| 261 | let enable_pll = |pll| { | ||
| 262 | RCC.cr().modify(|w| w.set_pllon(pll, true)); | ||
| 263 | while !RCC.cr().read().pllrdy(pll) {} | ||
| 264 | }; | ||
| 265 | |||
| 264 | if pll1_p_ck.is_some() { | 266 | if pll1_p_ck.is_some() { |
| 265 | RCC.cr().modify(|w| w.set_pll1on(Hsion::ON)); | 267 | enable_pll(0); |
| 266 | while !RCC.cr().read().pll1rdy() {} | ||
| 267 | } | 268 | } |
| 268 | 269 | ||
| 269 | if pll2_p_ck.is_some() { | 270 | if pll2_p_ck.is_some() { |
| 270 | RCC.cr().modify(|w| w.set_pll2on(Hsion::ON)); | 271 | enable_pll(1); |
| 271 | while !RCC.cr().read().pll2rdy() {} | ||
| 272 | } | 272 | } |
| 273 | 273 | ||
| 274 | if pll3_p_ck.is_some() { | 274 | if pll3_p_ck.is_some() { |
| 275 | RCC.cr().modify(|w| w.set_pll3on(Hsion::ON)); | 275 | enable_pll(2); |
| 276 | while !RCC.cr().read().pll3rdy() {} | ||
| 277 | } | 276 | } |
| 278 | 277 | ||
| 279 | // Core Prescaler / AHB Prescaler / APB3 Prescaler | 278 | // Core Prescaler / AHB Prescaler / APB3 Prescaler |
| 280 | RCC.d1cfgr().modify(|w| { | 279 | RCC.d1cfgr().modify(|w| { |
| 281 | w.set_d1cpre(Hpre(d1cpre_bits)); | 280 | w.set_d1cpre(Hpre(d1cpre_bits)); |
| 282 | w.set_d1ppre(D1ppre(ppre3_bits)); | 281 | w.set_d1ppre(Dppre(ppre3_bits)); |
| 283 | w.set_hpre(hpre_bits) | 282 | w.set_hpre(hpre_bits) |
| 284 | }); | 283 | }); |
| 285 | // Ensure core prescaler value is valid before future lower | 284 | // Ensure core prescaler value is valid before future lower |
| @@ -288,12 +287,12 @@ impl<'d> Rcc<'d> { | |||
| 288 | 287 | ||
| 289 | // APB1 / APB2 Prescaler | 288 | // APB1 / APB2 Prescaler |
| 290 | RCC.d2cfgr().modify(|w| { | 289 | RCC.d2cfgr().modify(|w| { |
| 291 | w.set_d2ppre1(D2ppre1(ppre1_bits)); | 290 | w.set_d2ppre1(Dppre(ppre1_bits)); |
| 292 | w.set_d2ppre2(D2ppre1(ppre2_bits)); | 291 | w.set_d2ppre2(Dppre(ppre2_bits)); |
| 293 | }); | 292 | }); |
| 294 | 293 | ||
| 295 | // APB4 Prescaler | 294 | // APB4 Prescaler |
| 296 | RCC.d3cfgr().modify(|w| w.set_d3ppre(D3ppre(ppre4_bits))); | 295 | RCC.d3cfgr().modify(|w| w.set_d3ppre(Dppre(ppre4_bits))); |
| 297 | 296 | ||
| 298 | // Peripheral Clock (per_ck) | 297 | // Peripheral Clock (per_ck) |
| 299 | RCC.d1ccipr().modify(|w| w.set_ckpersel(ckpersel)); | 298 | RCC.d1ccipr().modify(|w| w.set_ckpersel(ckpersel)); |
| @@ -312,8 +311,7 @@ impl<'d> Rcc<'d> { | |||
| 312 | 311 | ||
| 313 | // IO compensation cell - Requires CSI clock and SYSCFG | 312 | // IO compensation cell - Requires CSI clock and SYSCFG |
| 314 | assert!(RCC.cr().read().csirdy()); | 313 | assert!(RCC.cr().read().csirdy()); |
| 315 | RCC.apb4enr() | 314 | RCC.apb4enr().modify(|w| w.set_syscfgen(true)); |
| 316 | .modify(|w| w.set_syscfgen(Apb4enrSyscfgen::ENABLED)); | ||
| 317 | 315 | ||
| 318 | // Enable the compensation cell, using back-bias voltage code | 316 | // Enable the compensation cell, using back-bias voltage code |
| 319 | // provide by the cell. | 317 | // provide by the cell. |
| @@ -364,13 +362,10 @@ impl<'d> Rcc<'d> { | |||
| 364 | /// Set `enable_dma1` to true if you do not have at least one bus master (other than the CPU) | 362 | /// Set `enable_dma1` to true if you do not have at least one bus master (other than the CPU) |
| 365 | /// enable during WFI/WFE | 363 | /// enable during WFI/WFE |
| 366 | pub fn enable_debug_wfe(&mut self, _dbg: &mut peripherals::DBGMCU, enable_dma1: bool) { | 364 | pub fn enable_debug_wfe(&mut self, _dbg: &mut peripherals::DBGMCU, enable_dma1: bool) { |
| 367 | use crate::pac::rcc::vals::Ahb1enrDma1en; | ||
| 368 | |||
| 369 | // NOTE(unsafe) We have exclusive access to the RCC and DBGMCU | 365 | // NOTE(unsafe) We have exclusive access to the RCC and DBGMCU |
| 370 | unsafe { | 366 | unsafe { |
| 371 | if enable_dma1 { | 367 | if enable_dma1 { |
| 372 | RCC.ahb1enr() | 368 | RCC.ahb1enr().modify(|w| w.set_dma1en(true)); |
| 373 | .modify(|w| w.set_dma1en(Ahb1enrDma1en::ENABLED)); | ||
| 374 | } | 369 | } |
| 375 | 370 | ||
| 376 | DBGMCU.cr().modify(|w| { | 371 | DBGMCU.cr().modify(|w| { |
diff --git a/embassy-stm32/src/rcc/h7/pll.rs b/embassy-stm32/src/rcc/h7/pll.rs index 4c40d84d4..d3709378b 100644 --- a/embassy-stm32/src/rcc/h7/pll.rs +++ b/embassy-stm32/src/rcc/h7/pll.rs | |||
| @@ -46,7 +46,7 @@ fn vco_output_divider_setup(output: u32, plln: usize) -> (u32, u32) { | |||
| 46 | /// | 46 | /// |
| 47 | /// Must have exclusive access to the RCC register block | 47 | /// Must have exclusive access to the RCC register block |
| 48 | unsafe fn vco_setup(pll_src: u32, requested_output: u32, plln: usize) -> PllConfigResults { | 48 | unsafe fn vco_setup(pll_src: u32, requested_output: u32, plln: usize) -> PllConfigResults { |
| 49 | use crate::pac::rcc::vals::{Pll1rge, Pll1vcosel}; | 49 | use crate::pac::rcc::vals::{Pllrge, Pllvcosel}; |
| 50 | 50 | ||
| 51 | let (vco_ck_target, pll_x_p) = vco_output_divider_setup(requested_output, plln); | 51 | let (vco_ck_target, pll_x_p) = vco_output_divider_setup(requested_output, plln); |
| 52 | 52 | ||
| @@ -60,8 +60,8 @@ unsafe fn vco_setup(pll_src: u32, requested_output: u32, plln: usize) -> PllConf | |||
| 60 | assert!((1_000_000..=2_000_000).contains(&ref_x_ck)); | 60 | assert!((1_000_000..=2_000_000).contains(&ref_x_ck)); |
| 61 | 61 | ||
| 62 | RCC.pllcfgr().modify(|w| { | 62 | RCC.pllcfgr().modify(|w| { |
| 63 | w.set_pllvcosel(plln, Pll1vcosel::MEDIUMVCO); | 63 | w.set_pllvcosel(plln, Pllvcosel::MEDIUMVCO); |
| 64 | w.set_pllrge(plln, Pll1rge::RANGE1); | 64 | w.set_pllrge(plln, Pllrge::RANGE1); |
| 65 | }); | 65 | }); |
| 66 | PllConfigResults { | 66 | PllConfigResults { |
| 67 | ref_x_ck, | 67 | ref_x_ck, |
| @@ -79,7 +79,7 @@ pub(super) unsafe fn pll_setup( | |||
| 79 | config: &PllConfig, | 79 | config: &PllConfig, |
| 80 | plln: usize, | 80 | plln: usize, |
| 81 | ) -> (Option<u32>, Option<u32>, Option<u32>) { | 81 | ) -> (Option<u32>, Option<u32>, Option<u32>) { |
| 82 | use crate::pac::rcc::vals::{Divp1, Divp1en, Pll1fracen}; | 82 | use crate::pac::rcc::vals::Divp; |
| 83 | 83 | ||
| 84 | match config.p_ck { | 84 | match config.p_ck { |
| 85 | Some(requested_output) => { | 85 | Some(requested_output) => { |
| @@ -101,22 +101,19 @@ pub(super) unsafe fn pll_setup( | |||
| 101 | .modify(|w| w.set_divn1((pll_x_n - 1) as u16)); | 101 | .modify(|w| w.set_divn1((pll_x_n - 1) as u16)); |
| 102 | 102 | ||
| 103 | // No FRACN | 103 | // No FRACN |
| 104 | RCC.pllcfgr() | 104 | RCC.pllcfgr().modify(|w| w.set_pllfracen(plln, false)); |
| 105 | .modify(|w| w.set_pllfracen(plln, Pll1fracen::RESET)); | ||
| 106 | let vco_ck = ref_x_ck * pll_x_n; | 105 | let vco_ck = ref_x_ck * pll_x_n; |
| 107 | 106 | ||
| 108 | RCC.plldivr(plln) | 107 | RCC.plldivr(plln) |
| 109 | .modify(|w| w.set_divp1(Divp1((pll_x_p - 1) as u8))); | 108 | .modify(|w| w.set_divp1(Divp((pll_x_p - 1) as u8))); |
| 110 | RCC.pllcfgr() | 109 | RCC.pllcfgr().modify(|w| w.set_divpen(plln, true)); |
| 111 | .modify(|w| w.set_divpen(plln, Divp1en::ENABLED)); | ||
| 112 | 110 | ||
| 113 | // Calulate additional output dividers | 111 | // Calulate additional output dividers |
| 114 | let q_ck = match config.q_ck { | 112 | let q_ck = match config.q_ck { |
| 115 | Some(Hertz(ck)) if ck > 0 => { | 113 | Some(Hertz(ck)) if ck > 0 => { |
| 116 | let div = (vco_ck + ck - 1) / ck; | 114 | let div = (vco_ck + ck - 1) / ck; |
| 117 | RCC.plldivr(plln).modify(|w| w.set_divq1((div - 1) as u8)); | 115 | RCC.plldivr(plln).modify(|w| w.set_divq1((div - 1) as u8)); |
| 118 | RCC.pllcfgr() | 116 | RCC.pllcfgr().modify(|w| w.set_divqen(plln, true)); |
| 119 | .modify(|w| w.set_divqen(plln, Divp1en::ENABLED)); | ||
| 120 | Some(vco_ck / div) | 117 | Some(vco_ck / div) |
| 121 | } | 118 | } |
| 122 | _ => None, | 119 | _ => None, |
| @@ -125,8 +122,7 @@ pub(super) unsafe fn pll_setup( | |||
| 125 | Some(Hertz(ck)) if ck > 0 => { | 122 | Some(Hertz(ck)) if ck > 0 => { |
| 126 | let div = (vco_ck + ck - 1) / ck; | 123 | let div = (vco_ck + ck - 1) / ck; |
| 127 | RCC.plldivr(plln).modify(|w| w.set_divr1((div - 1) as u8)); | 124 | RCC.plldivr(plln).modify(|w| w.set_divr1((div - 1) as u8)); |
| 128 | RCC.pllcfgr() | 125 | RCC.pllcfgr().modify(|w| w.set_divren(plln, true)); |
| 129 | .modify(|w| w.set_divren(plln, Divp1en::ENABLED)); | ||
| 130 | Some(vco_ck / div) | 126 | Some(vco_ck / div) |
| 131 | } | 127 | } |
| 132 | _ => None, | 128 | _ => None, |
diff --git a/stm32-data b/stm32-data | |||
| Subproject 33dfa674865b1b5f0bfb86f3217055a6a057a6f | Subproject ba3d77f554adf361fbd4b68d256e3c631dbae52 | ||
