diff options
| author | shakencodes <[email protected]> | 2023-11-01 11:46:17 -0700 |
|---|---|---|
| committer | shakencodes <[email protected]> | 2023-11-01 11:46:17 -0700 |
| commit | d0d8585e4cdb73373ead13289a28b7d155377963 (patch) | |
| tree | 691c60c2f3549dc75048482a34523ad6b85ab9ba | |
| parent | 729d69246ac23af7a9589b7df2f102abc64816cc (diff) | |
Reinstate rcc::Config adc_clock_source field
| -rw-r--r-- | embassy-stm32/src/rcc/l4l5.rs | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/embassy-stm32/src/rcc/l4l5.rs b/embassy-stm32/src/rcc/l4l5.rs index 2f89f6821..a7c136a31 100644 --- a/embassy-stm32/src/rcc/l4l5.rs +++ b/embassy-stm32/src/rcc/l4l5.rs | |||
| @@ -4,8 +4,8 @@ pub use crate::pac::rcc::vals::Clk48sel as Clk48Src; | |||
| 4 | #[cfg(any(stm32wb, stm32wl))] | 4 | #[cfg(any(stm32wb, stm32wl))] |
| 5 | pub use crate::pac::rcc::vals::Hsepre as HsePrescaler; | 5 | pub use crate::pac::rcc::vals::Hsepre as HsePrescaler; |
| 6 | pub use crate::pac::rcc::vals::{ | 6 | pub use crate::pac::rcc::vals::{ |
| 7 | Hpre as AHBPrescaler, Msirange as MSIRange, Pllm as PllPreDiv, Plln as PllMul, Pllp as PllPDiv, Pllq as PllQDiv, | 7 | Adcsel, Hpre as AHBPrescaler, Msirange as MSIRange, Pllm as PllPreDiv, Plln as PllMul, Pllp as PllPDiv, |
| 8 | Pllr as PllRDiv, Pllsrc as PLLSource, Ppre as APBPrescaler, Sw as ClockSrc, | 8 | Pllq as PllQDiv, Pllr as PllRDiv, Pllsrc as PLLSource, Ppre as APBPrescaler, Sw as ClockSrc, |
| 9 | }; | 9 | }; |
| 10 | use crate::pac::{FLASH, RCC}; | 10 | use crate::pac::{FLASH, RCC}; |
| 11 | use crate::rcc::{set_freqs, Clocks}; | 11 | use crate::rcc::{set_freqs, Clocks}; |
| @@ -52,7 +52,30 @@ pub struct Pll { | |||
| 52 | pub divr: Option<PllRDiv>, | 52 | pub divr: Option<PllRDiv>, |
| 53 | } | 53 | } |
| 54 | 54 | ||
| 55 | /// Clocks configutation | 55 | #[derive(Clone, Copy)] |
| 56 | pub enum AdcClockSource { | ||
| 57 | HSI16, | ||
| 58 | PLLPCLK, | ||
| 59 | SYSCLK, | ||
| 60 | } | ||
| 61 | |||
| 62 | impl AdcClockSource { | ||
| 63 | pub fn adcsel(&self) -> Adcsel { | ||
| 64 | match self { | ||
| 65 | AdcClockSource::HSI16 => Adcsel::HSI, | ||
| 66 | AdcClockSource::PLLPCLK => Adcsel::PLL1_P, | ||
| 67 | AdcClockSource::SYSCLK => Adcsel::SYS, | ||
| 68 | } | ||
| 69 | } | ||
| 70 | } | ||
| 71 | |||
| 72 | impl Default for AdcClockSource { | ||
| 73 | fn default() -> Self { | ||
| 74 | Self::HSI16 | ||
| 75 | } | ||
| 76 | } | ||
| 77 | |||
| 78 | /// Clocks configuration | ||
| 56 | pub struct Config { | 79 | pub struct Config { |
| 57 | // base clock sources | 80 | // base clock sources |
| 58 | pub msi: Option<MSIRange>, | 81 | pub msi: Option<MSIRange>, |
| @@ -84,6 +107,8 @@ pub struct Config { | |||
| 84 | 107 | ||
| 85 | // low speed LSI/LSE/RTC | 108 | // low speed LSI/LSE/RTC |
| 86 | pub ls: super::LsConfig, | 109 | pub ls: super::LsConfig, |
| 110 | |||
| 111 | pub adc_clock_source: AdcClockSource, | ||
| 87 | } | 112 | } |
| 88 | 113 | ||
| 89 | impl Default for Config { | 114 | impl Default for Config { |
| @@ -111,6 +136,7 @@ impl Default for Config { | |||
| 111 | #[cfg(any(stm32l4, stm32l5, stm32wb))] | 136 | #[cfg(any(stm32l4, stm32l5, stm32wb))] |
| 112 | clk48_src: Clk48Src::HSI48, | 137 | clk48_src: Clk48Src::HSI48, |
| 113 | ls: Default::default(), | 138 | ls: Default::default(), |
| 139 | adc_clock_source: AdcClockSource::default(), | ||
| 114 | } | 140 | } |
| 115 | } | 141 | } |
| 116 | } | 142 | } |
| @@ -344,6 +370,8 @@ pub(crate) unsafe fn init(config: Config) { | |||
| 344 | }); | 370 | }); |
| 345 | while RCC.cfgr().read().sws() != config.mux {} | 371 | while RCC.cfgr().read().sws() != config.mux {} |
| 346 | 372 | ||
| 373 | RCC.ccipr().modify(|w| w.set_adcsel(config.adc_clock_source.adcsel())); | ||
| 374 | |||
| 347 | #[cfg(any(stm32wl, stm32wb))] | 375 | #[cfg(any(stm32wl, stm32wb))] |
| 348 | { | 376 | { |
| 349 | RCC.extcfgr().modify(|w| { | 377 | RCC.extcfgr().modify(|w| { |
