aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshakencodes <[email protected]>2023-11-01 11:46:17 -0700
committershakencodes <[email protected]>2023-11-01 11:46:17 -0700
commitd0d8585e4cdb73373ead13289a28b7d155377963 (patch)
tree691c60c2f3549dc75048482a34523ad6b85ab9ba
parent729d69246ac23af7a9589b7df2f102abc64816cc (diff)
Reinstate rcc::Config adc_clock_source field
-rw-r--r--embassy-stm32/src/rcc/l4l5.rs34
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))]
5pub use crate::pac::rcc::vals::Hsepre as HsePrescaler; 5pub use crate::pac::rcc::vals::Hsepre as HsePrescaler;
6pub use crate::pac::rcc::vals::{ 6pub 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};
10use crate::pac::{FLASH, RCC}; 10use crate::pac::{FLASH, RCC};
11use crate::rcc::{set_freqs, Clocks}; 11use 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)]
56pub enum AdcClockSource {
57 HSI16,
58 PLLPCLK,
59 SYSCLK,
60}
61
62impl 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
72impl Default for AdcClockSource {
73 fn default() -> Self {
74 Self::HSI16
75 }
76}
77
78/// Clocks configuration
56pub struct Config { 79pub 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
89impl Default for Config { 114impl 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| {