aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-stm32/Cargo.toml4
-rw-r--r--embassy-stm32/src/rcc/f2.rs46
-rw-r--r--embassy-stm32/src/rcc/g0.rs14
-rw-r--r--embassy-stm32/src/rcc/g4.rs14
-rw-r--r--embassy-stm32/src/rcc/l.rs (renamed from embassy-stm32/src/rcc/l4l5.rs)383
-rw-r--r--embassy-stm32/src/rcc/l0l1.rs190
-rw-r--r--embassy-stm32/src/rcc/mod.rs3
-rw-r--r--embassy-stm32/src/rcc/u5.rs22
-rw-r--r--embassy-stm32/src/rcc/wba.rs8
-rw-r--r--examples/stm32f2/src/bin/pll.rs14
-rw-r--r--examples/stm32g4/src/bin/adc.rs4
-rw-r--r--examples/stm32g4/src/bin/pll.rs4
-rw-r--r--examples/stm32g4/src/bin/usb_serial.rs8
-rw-r--r--examples/stm32l4/src/bin/rng.rs4
-rw-r--r--examples/stm32l4/src/bin/rtc.rs2
-rw-r--r--examples/stm32l4/src/bin/spe_adin1110_http_server.rs4
-rw-r--r--examples/stm32l4/src/bin/usb_serial.rs2
-rw-r--r--examples/stm32l5/src/bin/rng.rs4
-rw-r--r--examples/stm32l5/src/bin/usb_ethernet.rs2
-rw-r--r--examples/stm32l5/src/bin/usb_hid_mouse.rs2
-rw-r--r--examples/stm32l5/src/bin/usb_serial.rs2
-rw-r--r--examples/stm32u5/src/bin/usb_serial.rs2
-rw-r--r--examples/stm32wl/src/bin/lora_lorawan.rs2
-rw-r--r--examples/stm32wl/src/bin/lora_p2p_receive.rs2
-rw-r--r--examples/stm32wl/src/bin/lora_p2p_send.rs2
-rw-r--r--examples/stm32wl/src/bin/random.rs2
-rw-r--r--examples/stm32wl/src/bin/rtc.rs2
-rw-r--r--tests/stm32/src/common.rs34
28 files changed, 354 insertions, 428 deletions
diff --git a/embassy-stm32/Cargo.toml b/embassy-stm32/Cargo.toml
index 7b3a6c2bb..373172760 100644
--- a/embassy-stm32/Cargo.toml
+++ b/embassy-stm32/Cargo.toml
@@ -58,7 +58,7 @@ rand_core = "0.6.3"
58sdio-host = "0.5.0" 58sdio-host = "0.5.0"
59embedded-sdmmc = { git = "https://github.com/embassy-rs/embedded-sdmmc-rs", rev = "a4f293d3a6f72158385f79c98634cb8a14d0d2fc", optional = true } 59embedded-sdmmc = { git = "https://github.com/embassy-rs/embedded-sdmmc-rs", rev = "a4f293d3a6f72158385f79c98634cb8a14d0d2fc", optional = true }
60critical-section = "1.1" 60critical-section = "1.1"
61stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-1374ed622714ef4702826699ca21cc1f741f4133" } 61stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-c551c07bf12513dd8346a9fe0bc70cf79f2ea02f" }
62vcell = "0.1.3" 62vcell = "0.1.3"
63bxcan = "0.7.0" 63bxcan = "0.7.0"
64nb = "1.0.0" 64nb = "1.0.0"
@@ -76,7 +76,7 @@ critical-section = { version = "1.1", features = ["std"] }
76[build-dependencies] 76[build-dependencies]
77proc-macro2 = "1.0.36" 77proc-macro2 = "1.0.36"
78quote = "1.0.15" 78quote = "1.0.15"
79stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-1374ed622714ef4702826699ca21cc1f741f4133", default-features = false, features = ["metadata"]} 79stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-c551c07bf12513dd8346a9fe0bc70cf79f2ea02f", default-features = false, features = ["metadata"]}
80 80
81 81
82[features] 82[features]
diff --git a/embassy-stm32/src/rcc/f2.rs b/embassy-stm32/src/rcc/f2.rs
index 9a66e75a4..00480222a 100644
--- a/embassy-stm32/src/rcc/f2.rs
+++ b/embassy-stm32/src/rcc/f2.rs
@@ -1,7 +1,7 @@
1use crate::pac::flash::vals::Latency; 1use crate::pac::flash::vals::Latency;
2use crate::pac::rcc::vals::Sw; 2use crate::pac::rcc::vals::Sw;
3pub use crate::pac::rcc::vals::{ 3pub use crate::pac::rcc::vals::{
4 Hpre as AHBPrescaler, Pllm as PLLPreDiv, Plln as PLLMul, Pllp as PLLPDiv, Pllq as PLLQDiv, Pllsrc as PLLSrc, 4 Hpre as AHBPrescaler, Pllm as PllPreDiv, Plln as PllMul, Pllp as PllPDiv, Pllq as PllQDiv, Pllsrc as PllSource,
5 Ppre as APBPrescaler, 5 Ppre as APBPrescaler,
6}; 6};
7use crate::pac::{FLASH, RCC}; 7use crate::pac::{FLASH, RCC};
@@ -35,30 +35,30 @@ pub enum HSESrc {
35} 35}
36 36
37#[derive(Clone, Copy)] 37#[derive(Clone, Copy)]
38pub struct PLLConfig { 38pub struct Pll {
39 pub pre_div: PLLPreDiv, 39 pub pre_div: PllPreDiv,
40 pub mul: PLLMul, 40 pub mul: PllMul,
41 pub p_div: PLLPDiv, 41 pub divp: PllPDiv,
42 pub q_div: PLLQDiv, 42 pub divq: PllQDiv,
43} 43}
44 44
45impl Default for PLLConfig { 45impl Default for Pll {
46 fn default() -> Self { 46 fn default() -> Self {
47 PLLConfig { 47 Pll {
48 pre_div: PLLPreDiv::DIV16, 48 pre_div: PllPreDiv::DIV16,
49 mul: PLLMul::MUL192, 49 mul: PllMul::MUL192,
50 p_div: PLLPDiv::DIV2, 50 divp: PllPDiv::DIV2,
51 q_div: PLLQDiv::DIV4, 51 divq: PllQDiv::DIV4,
52 } 52 }
53 } 53 }
54} 54}
55 55
56impl PLLConfig { 56impl Pll {
57 pub fn clocks(&self, src_freq: Hertz) -> PLLClocks { 57 pub fn clocks(&self, src_freq: Hertz) -> PLLClocks {
58 let in_freq = src_freq / self.pre_div; 58 let in_freq = src_freq / self.pre_div;
59 let vco_freq = src_freq / self.pre_div * self.mul; 59 let vco_freq = src_freq / self.pre_div * self.mul;
60 let main_freq = vco_freq / self.p_div; 60 let main_freq = vco_freq / self.divp;
61 let pll48_freq = vco_freq / self.q_div; 61 let pll48_freq = vco_freq / self.divq;
62 PLLClocks { 62 PLLClocks {
63 in_freq, 63 in_freq,
64 vco_freq, 64 vco_freq,
@@ -172,8 +172,8 @@ impl VoltageScale {
172pub struct Config { 172pub struct Config {
173 pub hse: Option<HSEConfig>, 173 pub hse: Option<HSEConfig>,
174 pub hsi: bool, 174 pub hsi: bool,
175 pub pll_mux: PLLSrc, 175 pub pll_mux: PllSource,
176 pub pll: PLLConfig, 176 pub pll: Pll,
177 pub mux: ClockSrc, 177 pub mux: ClockSrc,
178 pub voltage: VoltageScale, 178 pub voltage: VoltageScale,
179 pub ahb_pre: AHBPrescaler, 179 pub ahb_pre: AHBPrescaler,
@@ -188,8 +188,8 @@ impl Default for Config {
188 Config { 188 Config {
189 hse: None, 189 hse: None,
190 hsi: true, 190 hsi: true,
191 pll_mux: PLLSrc::HSI, 191 pll_mux: PllSource::HSI,
192 pll: PLLConfig::default(), 192 pll: Pll::default(),
193 voltage: VoltageScale::Range3, 193 voltage: VoltageScale::Range3,
194 mux: ClockSrc::HSI, 194 mux: ClockSrc::HSI,
195 ahb_pre: AHBPrescaler::DIV1, 195 ahb_pre: AHBPrescaler::DIV1,
@@ -217,13 +217,13 @@ pub(crate) unsafe fn init(config: Config) {
217 } 217 }
218 218
219 let pll_src_freq = match config.pll_mux { 219 let pll_src_freq = match config.pll_mux {
220 PLLSrc::HSE => { 220 PllSource::HSE => {
221 let hse_config = config 221 let hse_config = config
222 .hse 222 .hse
223 .unwrap_or_else(|| panic!("HSE must be configured to be used as PLL input")); 223 .unwrap_or_else(|| panic!("HSE must be configured to be used as PLL input"));
224 hse_config.frequency 224 hse_config.frequency
225 } 225 }
226 PLLSrc::HSI => HSI_FREQ, 226 PllSource::HSI => HSI_FREQ,
227 }; 227 };
228 228
229 // Reference: STM32F215xx/217xx datasheet Table 33. Main PLL characteristics 229 // Reference: STM32F215xx/217xx datasheet Table 33. Main PLL characteristics
@@ -238,8 +238,8 @@ pub(crate) unsafe fn init(config: Config) {
238 w.set_pllsrc(config.pll_mux); 238 w.set_pllsrc(config.pll_mux);
239 w.set_pllm(config.pll.pre_div); 239 w.set_pllm(config.pll.pre_div);
240 w.set_plln(config.pll.mul); 240 w.set_plln(config.pll.mul);
241 w.set_pllp(config.pll.p_div); 241 w.set_pllp(config.pll.divp);
242 w.set_pllq(config.pll.q_div); 242 w.set_pllq(config.pll.divq);
243 }); 243 });
244 244
245 let (sys_clk, sw) = match config.mux { 245 let (sys_clk, sw) = match config.mux {
diff --git a/embassy-stm32/src/rcc/g0.rs b/embassy-stm32/src/rcc/g0.rs
index 45d41a4e0..75613dd2b 100644
--- a/embassy-stm32/src/rcc/g0.rs
+++ b/embassy-stm32/src/rcc/g0.rs
@@ -28,7 +28,7 @@ pub enum ClockSrc {
28#[derive(Clone, Copy)] 28#[derive(Clone, Copy)]
29pub struct PllConfig { 29pub struct PllConfig {
30 /// The source from which the PLL receives a clock signal 30 /// The source from which the PLL receives a clock signal
31 pub source: PllSrc, 31 pub source: PllSource,
32 /// The initial divisor of that clock signal 32 /// The initial divisor of that clock signal
33 pub m: Pllm, 33 pub m: Pllm,
34 /// The PLL VCO multiplier, which must be in the range `8..=86`. 34 /// The PLL VCO multiplier, which must be in the range `8..=86`.
@@ -48,7 +48,7 @@ impl Default for PllConfig {
48 fn default() -> PllConfig { 48 fn default() -> PllConfig {
49 // HSI / 1 * 8 / 2 = 64 MHz 49 // HSI / 1 * 8 / 2 = 64 MHz
50 PllConfig { 50 PllConfig {
51 source: PllSrc::HSI, 51 source: PllSource::HSI,
52 m: Pllm::DIV1, 52 m: Pllm::DIV1,
53 n: Plln::MUL8, 53 n: Plln::MUL8,
54 r: Pllr::DIV2, 54 r: Pllr::DIV2,
@@ -59,7 +59,7 @@ impl Default for PllConfig {
59} 59}
60 60
61#[derive(Clone, Copy, Eq, PartialEq)] 61#[derive(Clone, Copy, Eq, PartialEq)]
62pub enum PllSrc { 62pub enum PllSource {
63 HSI, 63 HSI,
64 HSE(Hertz), 64 HSE(Hertz),
65} 65}
@@ -89,8 +89,8 @@ impl Default for Config {
89impl PllConfig { 89impl PllConfig {
90 pub(crate) fn init(self) -> Hertz { 90 pub(crate) fn init(self) -> Hertz {
91 let (src, input_freq) = match self.source { 91 let (src, input_freq) = match self.source {
92 PllSrc::HSI => (vals::Pllsrc::HSI, HSI_FREQ), 92 PllSource::HSI => (vals::Pllsrc::HSI, HSI_FREQ),
93 PllSrc::HSE(freq) => (vals::Pllsrc::HSE, freq), 93 PllSource::HSE(freq) => (vals::Pllsrc::HSE, freq),
94 }; 94 };
95 95
96 let m_freq = input_freq / self.m; 96 let m_freq = input_freq / self.m;
@@ -121,11 +121,11 @@ impl PllConfig {
121 // > 3. Change the desired parameter. 121 // > 3. Change the desired parameter.
122 // Enable whichever clock source we're using, and wait for it to become ready 122 // Enable whichever clock source we're using, and wait for it to become ready
123 match self.source { 123 match self.source {
124 PllSrc::HSI => { 124 PllSource::HSI => {
125 RCC.cr().write(|w| w.set_hsion(true)); 125 RCC.cr().write(|w| w.set_hsion(true));
126 while !RCC.cr().read().hsirdy() {} 126 while !RCC.cr().read().hsirdy() {}
127 } 127 }
128 PllSrc::HSE(_) => { 128 PllSource::HSE(_) => {
129 RCC.cr().write(|w| w.set_hseon(true)); 129 RCC.cr().write(|w| w.set_hseon(true));
130 while !RCC.cr().read().hserdy() {} 130 while !RCC.cr().read().hserdy() {}
131 } 131 }
diff --git a/embassy-stm32/src/rcc/g4.rs b/embassy-stm32/src/rcc/g4.rs
index 13eb0c48d..48b27255d 100644
--- a/embassy-stm32/src/rcc/g4.rs
+++ b/embassy-stm32/src/rcc/g4.rs
@@ -23,16 +23,16 @@ pub enum ClockSrc {
23 23
24/// PLL clock input source 24/// PLL clock input source
25#[derive(Clone, Copy, Debug)] 25#[derive(Clone, Copy, Debug)]
26pub enum PllSrc { 26pub enum PllSource {
27 HSI, 27 HSI,
28 HSE(Hertz), 28 HSE(Hertz),
29} 29}
30 30
31impl Into<Pllsrc> for PllSrc { 31impl Into<Pllsrc> for PllSource {
32 fn into(self) -> Pllsrc { 32 fn into(self) -> Pllsrc {
33 match self { 33 match self {
34 PllSrc::HSE(..) => Pllsrc::HSE, 34 PllSource::HSE(..) => Pllsrc::HSE,
35 PllSrc::HSI => Pllsrc::HSI, 35 PllSource::HSI => Pllsrc::HSI,
36 } 36 }
37 } 37 }
38} 38}
@@ -44,7 +44,7 @@ impl Into<Pllsrc> for PllSrc {
44/// frequency ranges for each of these settings. 44/// frequency ranges for each of these settings.
45pub struct Pll { 45pub struct Pll {
46 /// PLL Source clock selection. 46 /// PLL Source clock selection.
47 pub source: PllSrc, 47 pub source: PllSource,
48 48
49 /// PLL pre-divider 49 /// PLL pre-divider
50 pub prediv_m: PllM, 50 pub prediv_m: PllM,
@@ -118,13 +118,13 @@ pub struct PllFreq {
118pub(crate) unsafe fn init(config: Config) { 118pub(crate) unsafe fn init(config: Config) {
119 let pll_freq = config.pll.map(|pll_config| { 119 let pll_freq = config.pll.map(|pll_config| {
120 let src_freq = match pll_config.source { 120 let src_freq = match pll_config.source {
121 PllSrc::HSI => { 121 PllSource::HSI => {
122 RCC.cr().write(|w| w.set_hsion(true)); 122 RCC.cr().write(|w| w.set_hsion(true));
123 while !RCC.cr().read().hsirdy() {} 123 while !RCC.cr().read().hsirdy() {}
124 124
125 HSI_FREQ 125 HSI_FREQ
126 } 126 }
127 PllSrc::HSE(freq) => { 127 PllSource::HSE(freq) => {
128 RCC.cr().write(|w| w.set_hseon(true)); 128 RCC.cr().write(|w| w.set_hseon(true));
129 while !RCC.cr().read().hserdy() {} 129 while !RCC.cr().read().hserdy() {}
130 freq 130 freq
diff --git a/embassy-stm32/src/rcc/l4l5.rs b/embassy-stm32/src/rcc/l.rs
index c44839104..257fd83fe 100644
--- a/embassy-stm32/src/rcc/l4l5.rs
+++ b/embassy-stm32/src/rcc/l.rs
@@ -1,12 +1,13 @@
1#[cfg(any(stm32l0, stm32l1))]
2pub use crate::pac::pwr::vals::Vos as VoltageScale;
1use crate::pac::rcc::regs::Cfgr; 3use crate::pac::rcc::regs::Cfgr;
2#[cfg(any(stm32l4, stm32l5, stm32wb))] 4#[cfg(any(stm32l4, stm32l5, stm32wb, stm32wl))]
5pub use crate::pac::rcc::vals::Adcsel as AdcClockSource;
6#[cfg(any(rcc_l0_v2, stm32l4, stm32l5, stm32wb))]
3pub use crate::pac::rcc::vals::Clk48sel as Clk48Src; 7pub use crate::pac::rcc::vals::Clk48sel as Clk48Src;
4#[cfg(any(stm32wb, stm32wl))] 8#[cfg(any(stm32wb, stm32wl))]
5pub use crate::pac::rcc::vals::Hsepre as HsePrescaler; 9pub use crate::pac::rcc::vals::Hsepre as HsePrescaler;
6pub use crate::pac::rcc::vals::{ 10pub use crate::pac::rcc::vals::{Hpre as AHBPrescaler, Msirange as MSIRange, Ppre as APBPrescaler, Sw as ClockSrc};
7 Adcsel as AdcClockSource, Hpre as AHBPrescaler, Msirange as MSIRange, Pllm as PllPreDiv, Plln as PllMul,
8 Pllp as PllPDiv, Pllq as PllQDiv, Pllr as PllRDiv, Pllsrc as PLLSource, Ppre as APBPrescaler, Sw as ClockSrc,
9};
10use crate::pac::{FLASH, RCC}; 11use crate::pac::{FLASH, RCC};
11use crate::rcc::{set_freqs, Clocks}; 12use crate::rcc::{set_freqs, Clocks};
12use crate::time::Hertz; 13use crate::time::Hertz;
@@ -33,25 +34,6 @@ pub struct Hse {
33 pub prescaler: HsePrescaler, 34 pub prescaler: HsePrescaler,
34} 35}
35 36
36#[derive(Clone, Copy)]
37pub struct Pll {
38 /// PLL source
39 pub source: PLLSource,
40
41 /// PLL pre-divider (DIVM).
42 pub prediv: PllPreDiv,
43
44 /// PLL multiplication factor.
45 pub mul: PllMul,
46
47 /// PLL P division factor. If None, PLL P output is disabled.
48 pub divp: Option<PllPDiv>,
49 /// PLL Q division factor. If None, PLL Q output is disabled.
50 pub divq: Option<PllQDiv>,
51 /// PLL R division factor. If None, PLL R output is disabled.
52 pub divr: Option<PllRDiv>,
53}
54
55/// Clocks configuration 37/// Clocks configuration
56pub struct Config { 38pub struct Config {
57 // base clock sources 39 // base clock sources
@@ -79,13 +61,17 @@ pub struct Config {
79 pub shared_ahb_pre: AHBPrescaler, 61 pub shared_ahb_pre: AHBPrescaler,
80 62
81 // muxes 63 // muxes
82 #[cfg(any(stm32l4, stm32l5, stm32wb))] 64 #[cfg(any(rcc_l0_v2, stm32l4, stm32l5, stm32wb))]
83 pub clk48_src: Clk48Src, 65 pub clk48_src: Clk48Src,
84 66
85 // low speed LSI/LSE/RTC 67 // low speed LSI/LSE/RTC
86 pub ls: super::LsConfig, 68 pub ls: super::LsConfig,
87 69
70 #[cfg(any(stm32l4, stm32l5, stm32wb, stm32wl))]
88 pub adc_clock_source: AdcClockSource, 71 pub adc_clock_source: AdcClockSource,
72
73 #[cfg(any(stm32l0, stm32l1))]
74 pub voltage_scale: VoltageScale,
89} 75}
90 76
91impl Default for Config { 77impl Default for Config {
@@ -110,10 +96,13 @@ impl Default for Config {
110 pllsai2: None, 96 pllsai2: None,
111 #[cfg(crs)] 97 #[cfg(crs)]
112 hsi48: Some(Default::default()), 98 hsi48: Some(Default::default()),
113 #[cfg(any(stm32l4, stm32l5, stm32wb))] 99 #[cfg(any(rcc_l0_v2, stm32l4, stm32l5, stm32wb))]
114 clk48_src: Clk48Src::HSI48, 100 clk48_src: Clk48Src::HSI48,
115 ls: Default::default(), 101 ls: Default::default(),
102 #[cfg(any(stm32l4, stm32l5, stm32wb, stm32wl))]
116 adc_clock_source: AdcClockSource::SYS, 103 adc_clock_source: AdcClockSource::SYS,
104 #[cfg(any(stm32l0, stm32l1))]
105 voltage_scale: VoltageScale::RANGE1,
117 } 106 }
118 } 107 }
119} 108}
@@ -135,7 +124,7 @@ pub const WPAN_DEFAULT: Config = Config {
135 ls: super::LsConfig::default_lse(), 124 ls: super::LsConfig::default_lse(),
136 125
137 pll: Some(Pll { 126 pll: Some(Pll {
138 source: PLLSource::HSE, 127 source: PllSource::HSE,
139 prediv: PllPreDiv::DIV2, 128 prediv: PllPreDiv::DIV2,
140 mul: PllMul::MUL12, 129 mul: PllMul::MUL12,
141 divp: Some(PllPDiv::DIV3), // 32 / 2 * 12 / 3 = 64Mhz 130 divp: Some(PllPDiv::DIV3), // 32 / 2 * 12 / 3 = 64Mhz
@@ -152,20 +141,26 @@ pub const WPAN_DEFAULT: Config = Config {
152 adc_clock_source: AdcClockSource::SYS, 141 adc_clock_source: AdcClockSource::SYS,
153}; 142};
154 143
144fn msi_enable(range: MSIRange) {
145 #[cfg(any(stm32l4, stm32l5, stm32wb, stm32wl))]
146 RCC.cr().modify(|w| {
147 #[cfg(not(stm32wb))]
148 w.set_msirgsel(crate::pac::rcc::vals::Msirgsel::CR);
149 w.set_msirange(range);
150 w.set_msipllen(false);
151 });
152 #[cfg(any(stm32l0, stm32l1))]
153 RCC.icscr().modify(|w| w.set_msirange(range));
154
155 RCC.cr().modify(|w| w.set_msion(true));
156 while !RCC.cr().read().msirdy() {}
157}
158
155pub(crate) unsafe fn init(config: Config) { 159pub(crate) unsafe fn init(config: Config) {
156 // Switch to MSI to prevent problems with PLL configuration. 160 // Switch to MSI to prevent problems with PLL configuration.
157 if !RCC.cr().read().msion() { 161 if !RCC.cr().read().msion() {
158 // Turn on MSI and configure it to 4MHz. 162 // Turn on MSI and configure it to 4MHz.
159 RCC.cr().modify(|w| { 163 msi_enable(MSIRange::RANGE4M)
160 #[cfg(not(stm32wb))]
161 w.set_msirgsel(crate::pac::rcc::vals::Msirgsel::CR);
162 w.set_msirange(MSIRange::RANGE4M);
163 w.set_msipllen(false);
164 w.set_msion(true)
165 });
166
167 // Wait until MSI is running
168 while !RCC.cr().read().msirdy() {}
169 } 164 }
170 if RCC.cfgr().read().sws() != ClockSrc::MSI { 165 if RCC.cfgr().read().sws() != ClockSrc::MSI {
171 // Set MSI as a clock source, reset prescalers. 166 // Set MSI as a clock source, reset prescalers.
@@ -174,6 +169,14 @@ pub(crate) unsafe fn init(config: Config) {
174 while RCC.cfgr().read().sws() != ClockSrc::MSI {} 169 while RCC.cfgr().read().sws() != ClockSrc::MSI {}
175 } 170 }
176 171
172 // Set voltage scale
173 #[cfg(any(stm32l0, stm32l1))]
174 {
175 while crate::pac::PWR.csr().read().vosf() {}
176 crate::pac::PWR.cr().write(|w| w.set_vos(config.voltage_scale));
177 while crate::pac::PWR.csr().read().vosf() {}
178 }
179
177 #[cfg(stm32l5)] 180 #[cfg(stm32l5)]
178 crate::pac::PWR.cr1().modify(|w| { 181 crate::pac::PWR.cr1().modify(|w| {
179 w.set_vos(crate::pac::pwr::vals::Vos::RANGE0); 182 w.set_vos(crate::pac::pwr::vals::Vos::RANGE0);
@@ -182,21 +185,16 @@ pub(crate) unsafe fn init(config: Config) {
182 let rtc = config.ls.init(); 185 let rtc = config.ls.init();
183 186
184 let msi = config.msi.map(|range| { 187 let msi = config.msi.map(|range| {
185 // Enable MSI 188 msi_enable(range);
186 RCC.cr().modify(|w| {
187 #[cfg(not(stm32wb))]
188 w.set_msirgsel(crate::pac::rcc::vals::Msirgsel::CR);
189 w.set_msirange(range);
190 w.set_msion(true);
191
192 // If LSE is enabled, enable calibration of MSI
193 w.set_msipllen(config.ls.lse.is_some());
194 });
195 while !RCC.cr().read().msirdy() {}
196
197 msirange_to_hertz(range) 189 msirange_to_hertz(range)
198 }); 190 });
199 191
192 // If LSE is enabled and the right freq, enable calibration of MSI
193 #[cfg(any(stm32l4, stm32l5, stm32wb, stm32wl))]
194 if config.ls.lse.map(|x| x.frequency) == Some(Hertz(32_768)) {
195 RCC.cr().modify(|w| w.set_msipllen(true));
196 }
197
200 let hsi = config.hsi.then(|| { 198 let hsi = config.hsi.then(|| {
201 RCC.cr().modify(|w| w.set_hsion(true)); 199 RCC.cr().modify(|w| w.set_hsion(true));
202 while !RCC.cr().read().hsirdy() {} 200 while !RCC.cr().read().hsirdy() {}
@@ -218,7 +216,10 @@ pub(crate) unsafe fn init(config: Config) {
218 }); 216 });
219 217
220 #[cfg(crs)] 218 #[cfg(crs)]
221 let _hsi48 = config.hsi48.map(super::init_hsi48); 219 let _hsi48 = config.hsi48.map(|config| {
220 //
221 super::init_hsi48(config)
222 });
222 #[cfg(not(crs))] 223 #[cfg(not(crs))]
223 let _hsi48: Option<Hertz> = None; 224 let _hsi48: Option<Hertz> = None;
224 225
@@ -251,7 +252,12 @@ pub(crate) unsafe fn init(config: Config) {
251 }), 252 }),
252 }; 253 };
253 254
254 let pll_input = PllInput { hse, hsi, msi }; 255 let pll_input = PllInput {
256 hse,
257 hsi,
258 #[cfg(any(stm32l4, stm32l5, stm32wb, stm32wl))]
259 msi,
260 };
255 let pll = init_pll(PllInstance::Pll, config.pll, &pll_input); 261 let pll = init_pll(PllInstance::Pll, config.pll, &pll_input);
256 #[cfg(any(stm32l4, stm32l5, stm32wb))] 262 #[cfg(any(stm32l4, stm32l5, stm32wb))]
257 let pllsai1 = init_pll(PllInstance::Pllsai1, config.pllsai1, &pll_input); 263 let pllsai1 = init_pll(PllInstance::Pllsai1, config.pllsai1, &pll_input);
@@ -265,10 +271,13 @@ pub(crate) unsafe fn init(config: Config) {
265 ClockSrc::PLL1_R => pll.r.unwrap(), 271 ClockSrc::PLL1_R => pll.r.unwrap(),
266 }; 272 };
267 273
268 #[cfg(stm32l4)] 274 #[cfg(any(rcc_l0_v2, stm32l4, stm32l5, stm32wb))]
269 RCC.ccipr().modify(|w| w.set_clk48sel(config.clk48_src)); 275 RCC.ccipr().modify(|w| w.set_clk48sel(config.clk48_src));
270 #[cfg(stm32l5)] 276 #[cfg(any(rcc_l0_v2))]
271 RCC.ccipr1().modify(|w| w.set_clk48sel(config.clk48_src)); 277 let _clk48 = match config.clk48_src {
278 Clk48Src::HSI48 => _hsi48,
279 Clk48Src::PLL1_VCO_DIV_2 => pll.clk48,
280 };
272 #[cfg(any(stm32l4, stm32l5, stm32wb))] 281 #[cfg(any(stm32l4, stm32l5, stm32wb))]
273 let _clk48 = match config.clk48_src { 282 let _clk48 = match config.clk48_src {
274 Clk48Src::HSI48 => _hsi48, 283 Clk48Src::HSI48 => _hsi48,
@@ -285,16 +294,23 @@ pub(crate) unsafe fn init(config: Config) {
285 let hclk1 = sys_clk / config.ahb_pre; 294 let hclk1 = sys_clk / config.ahb_pre;
286 let (pclk1, pclk1_tim) = super::util::calc_pclk(hclk1, config.apb1_pre); 295 let (pclk1, pclk1_tim) = super::util::calc_pclk(hclk1, config.apb1_pre);
287 let (pclk2, pclk2_tim) = super::util::calc_pclk(hclk1, config.apb2_pre); 296 let (pclk2, pclk2_tim) = super::util::calc_pclk(hclk1, config.apb2_pre);
288 #[cfg(not(any(stm32wl5x, stm32wb)))] 297 #[cfg(any(stm32l4, stm32l5, stm32wlex))]
289 let hclk2 = hclk1; 298 let hclk2 = hclk1;
290 #[cfg(any(stm32wl5x, stm32wb))] 299 #[cfg(any(stm32wl5x, stm32wb))]
291 let hclk2 = sys_clk / config.core2_ahb_pre; 300 let hclk2 = sys_clk / config.core2_ahb_pre;
292 #[cfg(not(any(stm32wl, stm32wb)))] 301 #[cfg(any(stm32l4, stm32l5, stm32wlex))]
293 let hclk3 = hclk1; 302 let hclk3 = hclk1;
294 #[cfg(any(stm32wl, stm32wb))] 303 #[cfg(any(stm32wl5x, stm32wb))]
295 let hclk3 = sys_clk / config.shared_ahb_pre; 304 let hclk3 = sys_clk / config.shared_ahb_pre;
296 305
297 // Set flash wait states 306 // Set flash wait states
307 #[cfg(any(stm32l0, stm32l1))]
308 let latency = match (config.voltage_scale, sys_clk.0) {
309 (VoltageScale::RANGE1, ..=16_000_000) => false,
310 (VoltageScale::RANGE2, ..=8_000_000) => false,
311 (VoltageScale::RANGE3, ..=4_200_000) => false,
312 _ => true,
313 };
298 #[cfg(stm32l4)] 314 #[cfg(stm32l4)]
299 let latency = match hclk1.0 { 315 let latency = match hclk1.0 {
300 0..=16_000_000 => 0, 316 0..=16_000_000 => 0,
@@ -330,6 +346,10 @@ pub(crate) unsafe fn init(config: Config) {
330 _ => 4, 346 _ => 4,
331 }; 347 };
332 348
349 #[cfg(stm32l1)]
350 FLASH.acr().write(|w| w.set_acc64(true));
351 #[cfg(not(stm32l5))]
352 FLASH.acr().modify(|w| w.set_prften(true));
333 FLASH.acr().modify(|w| w.set_latency(latency)); 353 FLASH.acr().modify(|w| w.set_latency(latency));
334 while FLASH.acr().read().latency() != latency {} 354 while FLASH.acr().read().latency() != latency {}
335 355
@@ -341,9 +361,7 @@ pub(crate) unsafe fn init(config: Config) {
341 }); 361 });
342 while RCC.cfgr().read().sws() != config.mux {} 362 while RCC.cfgr().read().sws() != config.mux {}
343 363
344 #[cfg(stm32l5)] 364 #[cfg(any(stm32l4, stm32l5, stm32wb, stm32wl))]
345 RCC.ccipr1().modify(|w| w.set_adcsel(config.adc_clock_source));
346 #[cfg(not(stm32l5))]
347 RCC.ccipr().modify(|w| w.set_adcsel(config.adc_clock_source)); 365 RCC.ccipr().modify(|w| w.set_adcsel(config.adc_clock_source));
348 366
349 #[cfg(any(stm32wl, stm32wb))] 367 #[cfg(any(stm32wl, stm32wb))]
@@ -361,7 +379,9 @@ pub(crate) unsafe fn init(config: Config) {
361 set_freqs(Clocks { 379 set_freqs(Clocks {
362 sys: sys_clk, 380 sys: sys_clk,
363 hclk1, 381 hclk1,
382 #[cfg(any(stm32l4, stm32l5, stm32wb, stm32wl))]
364 hclk2, 383 hclk2,
384 #[cfg(any(stm32l4, stm32l5, stm32wb, stm32wl))]
365 hclk3, 385 hclk3,
366 pclk1, 386 pclk1,
367 pclk2, 387 pclk2,
@@ -389,6 +409,12 @@ pub(crate) unsafe fn init(config: Config) {
389 }); 409 });
390} 410}
391 411
412#[cfg(any(stm32l0, stm32l1))]
413fn msirange_to_hertz(range: MSIRange) -> Hertz {
414 Hertz(32_768 * (1 << (range as u8 + 1)))
415}
416
417#[cfg(any(stm32l4, stm32l5, stm32wb, stm32wl))]
392fn msirange_to_hertz(range: MSIRange) -> Hertz { 418fn msirange_to_hertz(range: MSIRange) -> Hertz {
393 match range { 419 match range {
394 MSIRange::RANGE100K => Hertz(100_000), 420 MSIRange::RANGE100K => Hertz(100_000),
@@ -407,20 +433,6 @@ fn msirange_to_hertz(range: MSIRange) -> Hertz {
407 } 433 }
408} 434}
409 435
410struct PllInput {
411 hsi: Option<Hertz>,
412 hse: Option<Hertz>,
413 msi: Option<Hertz>,
414}
415
416#[allow(unused)]
417#[derive(Default)]
418struct PllOutput {
419 p: Option<Hertz>,
420 q: Option<Hertz>,
421 r: Option<Hertz>,
422}
423
424#[derive(PartialEq, Eq, Clone, Copy)] 436#[derive(PartialEq, Eq, Clone, Copy)]
425enum PllInstance { 437enum PllInstance {
426 Pll, 438 Pll,
@@ -449,77 +461,182 @@ fn pll_enable(instance: PllInstance, enabled: bool) {
449 } 461 }
450} 462}
451 463
452fn init_pll(instance: PllInstance, config: Option<Pll>, input: &PllInput) -> PllOutput { 464pub use pll::*;
453 // Disable PLL
454 pll_enable(instance, false);
455 465
456 let Some(pll) = config else { return PllOutput::default() }; 466#[cfg(any(stm32l0, stm32l1))]
467mod pll {
468 use super::{pll_enable, PllInstance};
469 pub use crate::pac::rcc::vals::{Plldiv as PllDiv, Pllmul as PllMul, Pllsrc as PllSource};
470 use crate::pac::RCC;
471 use crate::time::Hertz;
457 472
458 let pll_src = match pll.source { 473 #[derive(Clone, Copy)]
459 PLLSource::DISABLE => panic!("must not select PLL source as DISABLE"), 474 pub struct Pll {
460 PLLSource::HSE => input.hse, 475 /// PLL source
461 PLLSource::HSI => input.hsi, 476 pub source: PllSource,
462 PLLSource::MSI => input.msi,
463 };
464 477
465 let pll_src = pll_src.unwrap(); 478 /// PLL multiplication factor.
479 pub mul: PllMul,
466 480
467 let vco_freq = pll_src / pll.prediv * pll.mul; 481 /// PLL main output division factor.
482 pub div: PllDiv,
483 }
468 484
469 let p = pll.divp.map(|div| vco_freq / div); 485 pub(super) struct PllInput {
470 let q = pll.divq.map(|div| vco_freq / div); 486 pub hsi: Option<Hertz>,
471 let r = pll.divr.map(|div| vco_freq / div); 487 pub hse: Option<Hertz>,
488 }
472 489
473 #[cfg(stm32l5)] 490 #[allow(unused)]
474 if instance == PllInstance::Pllsai2 { 491 #[derive(Default)]
475 assert!(q.is_none(), "PLLSAI2_Q is not available on L5"); 492 pub(super) struct PllOutput {
476 assert!(r.is_none(), "PLLSAI2_R is not available on L5"); 493 pub r: Option<Hertz>,
494 pub clk48: Option<Hertz>,
477 } 495 }
478 496
479 macro_rules! write_fields { 497 pub(super) fn init_pll(instance: PllInstance, config: Option<Pll>, input: &PllInput) -> PllOutput {
480 ($w:ident) => { 498 // Disable PLL
481 $w.set_plln(pll.mul); 499 pll_enable(instance, false);
482 if let Some(divp) = pll.divp { 500
483 $w.set_pllp(divp); 501 let Some(pll) = config else { return PllOutput::default() };
484 $w.set_pllpen(true); 502
485 } 503 let pll_src = match pll.source {
486 if let Some(divq) = pll.divq { 504 PllSource::HSE => unwrap!(input.hse),
487 $w.set_pllq(divq); 505 PllSource::HSI => unwrap!(input.hsi),
488 $w.set_pllqen(true);
489 }
490 if let Some(divr) = pll.divr {
491 $w.set_pllr(divr);
492 $w.set_pllren(true);
493 }
494 }; 506 };
495 }
496 507
497 match instance { 508 let vco_freq = pll_src * pll.mul;
498 PllInstance::Pll => RCC.pllcfgr().write(|w| { 509
499 w.set_pllm(pll.prediv); 510 let r = vco_freq / pll.div;
500 w.set_pllsrc(pll.source); 511 let clk48 = (vco_freq == Hertz(96_000_000)).then_some(Hertz(48_000_000));
501 write_fields!(w); 512
502 }), 513 assert!(r <= Hertz(32_000_000));
503 #[cfg(any(stm32l4, stm32l5, stm32wb))] 514
504 PllInstance::Pllsai1 => RCC.pllsai1cfgr().write(|w| { 515 RCC.cfgr().write(move |w| {
505 #[cfg(any(rcc_l4plus, stm32l5))] 516 w.set_pllmul(pll.mul);
506 w.set_pllm(pll.prediv); 517 w.set_plldiv(pll.div);
507 #[cfg(stm32l5)]
508 w.set_pllsrc(pll.source);
509 write_fields!(w);
510 }),
511 #[cfg(any(stm32l47x, stm32l48x, stm32l49x, stm32l4ax, rcc_l4plus, stm32l5))]
512 PllInstance::Pllsai2 => RCC.pllsai2cfgr().write(|w| {
513 #[cfg(any(rcc_l4plus, stm32l5))]
514 w.set_pllm(pll.prediv);
515 #[cfg(stm32l5)]
516 w.set_pllsrc(pll.source); 518 w.set_pllsrc(pll.source);
517 write_fields!(w); 519 });
518 }), 520
521 // Enable PLL
522 pll_enable(instance, true);
523
524 PllOutput { r: Some(r), clk48 }
525 }
526}
527
528#[cfg(any(stm32l4, stm32l5, stm32wb, stm32wl))]
529mod pll {
530 use super::{pll_enable, PllInstance};
531 pub use crate::pac::rcc::vals::{
532 Pllm as PllPreDiv, Plln as PllMul, Pllp as PllPDiv, Pllq as PllQDiv, Pllr as PllRDiv, Pllsrc as PllSource,
533 };
534 use crate::pac::RCC;
535 use crate::time::Hertz;
536
537 #[derive(Clone, Copy)]
538 pub struct Pll {
539 /// PLL source
540 pub source: PllSource,
541
542 /// PLL pre-divider (DIVM).
543 pub prediv: PllPreDiv,
544
545 /// PLL multiplication factor.
546 pub mul: PllMul,
547
548 /// PLL P division factor. If None, PLL P output is disabled.
549 pub divp: Option<PllPDiv>,
550 /// PLL Q division factor. If None, PLL Q output is disabled.
551 pub divq: Option<PllQDiv>,
552 /// PLL R division factor. If None, PLL R output is disabled.
553 pub divr: Option<PllRDiv>,
519 } 554 }
520 555
521 // Enable PLL 556 pub(super) struct PllInput {
522 pll_enable(instance, true); 557 pub hsi: Option<Hertz>,
558 pub hse: Option<Hertz>,
559 pub msi: Option<Hertz>,
560 }
561
562 #[allow(unused)]
563 #[derive(Default)]
564 pub(super) struct PllOutput {
565 pub p: Option<Hertz>,
566 pub q: Option<Hertz>,
567 pub r: Option<Hertz>,
568 }
569
570 pub(super) fn init_pll(instance: PllInstance, config: Option<Pll>, input: &PllInput) -> PllOutput {
571 // Disable PLL
572 pll_enable(instance, false);
573
574 let Some(pll) = config else { return PllOutput::default() };
575
576 let pll_src = match pll.source {
577 PllSource::DISABLE => panic!("must not select PLL source as DISABLE"),
578 PllSource::HSE => unwrap!(input.hse),
579 PllSource::HSI => unwrap!(input.hsi),
580 PllSource::MSI => unwrap!(input.msi),
581 };
582
583 let vco_freq = pll_src / pll.prediv * pll.mul;
523 584
524 PllOutput { p, q, r } 585 let p = pll.divp.map(|div| vco_freq / div);
586 let q = pll.divq.map(|div| vco_freq / div);
587 let r = pll.divr.map(|div| vco_freq / div);
588
589 #[cfg(stm32l5)]
590 if instance == PllInstance::Pllsai2 {
591 assert!(q.is_none(), "PLLSAI2_Q is not available on L5");
592 assert!(r.is_none(), "PLLSAI2_R is not available on L5");
593 }
594
595 macro_rules! write_fields {
596 ($w:ident) => {
597 $w.set_plln(pll.mul);
598 if let Some(divp) = pll.divp {
599 $w.set_pllp(divp);
600 $w.set_pllpen(true);
601 }
602 if let Some(divq) = pll.divq {
603 $w.set_pllq(divq);
604 $w.set_pllqen(true);
605 }
606 if let Some(divr) = pll.divr {
607 $w.set_pllr(divr);
608 $w.set_pllren(true);
609 }
610 };
611 }
612
613 match instance {
614 PllInstance::Pll => RCC.pllcfgr().write(|w| {
615 w.set_pllm(pll.prediv);
616 w.set_pllsrc(pll.source);
617 write_fields!(w);
618 }),
619 #[cfg(any(stm32l4, stm32l5, stm32wb))]
620 PllInstance::Pllsai1 => RCC.pllsai1cfgr().write(|w| {
621 #[cfg(any(rcc_l4plus, stm32l5))]
622 w.set_pllm(pll.prediv);
623 #[cfg(stm32l5)]
624 w.set_pllsrc(pll.source);
625 write_fields!(w);
626 }),
627 #[cfg(any(stm32l47x, stm32l48x, stm32l49x, stm32l4ax, rcc_l4plus, stm32l5))]
628 PllInstance::Pllsai2 => RCC.pllsai2cfgr().write(|w| {
629 #[cfg(any(rcc_l4plus, stm32l5))]
630 w.set_pllm(pll.prediv);
631 #[cfg(stm32l5)]
632 w.set_pllsrc(pll.source);
633 write_fields!(w);
634 }),
635 }
636
637 // Enable PLL
638 pll_enable(instance, true);
639
640 PllOutput { p, q, r }
641 }
525} 642}
diff --git a/embassy-stm32/src/rcc/l0l1.rs b/embassy-stm32/src/rcc/l0l1.rs
deleted file mode 100644
index 25a7762a3..000000000
--- a/embassy-stm32/src/rcc/l0l1.rs
+++ /dev/null
@@ -1,190 +0,0 @@
1pub use crate::pac::pwr::vals::Vos as VoltageScale;
2pub use crate::pac::rcc::vals::{
3 Hpre as AHBPrescaler, Msirange as MSIRange, Plldiv as PLLDiv, Plldiv as PllDiv, Pllmul as PLLMul, Pllmul as PllMul,
4 Pllsrc as PLLSource, Ppre as APBPrescaler, Sw as ClockSrc,
5};
6use crate::pac::{FLASH, PWR, RCC};
7use crate::rcc::{set_freqs, Clocks};
8use crate::time::Hertz;
9
10/// HSI speed
11pub const HSI_FREQ: Hertz = Hertz(16_000_000);
12
13#[derive(Clone, Copy, Eq, PartialEq)]
14pub enum HseMode {
15 /// crystal/ceramic oscillator (HSEBYP=0)
16 Oscillator,
17 /// external analog clock (low swing) (HSEBYP=1)
18 Bypass,
19}
20
21#[derive(Clone, Copy, Eq, PartialEq)]
22pub struct Hse {
23 /// HSE frequency.
24 pub freq: Hertz,
25 /// HSE mode.
26 pub mode: HseMode,
27}
28
29#[derive(Clone, Copy)]
30pub struct Pll {
31 /// PLL source
32 pub source: PLLSource,
33
34 /// PLL multiplication factor.
35 pub mul: PllMul,
36
37 /// PLL main output division factor.
38 pub div: PllDiv,
39}
40
41/// Clocks configutation
42pub struct Config {
43 // base clock sources
44 pub msi: Option<MSIRange>,
45 pub hsi: bool,
46 pub hse: Option<Hse>,
47 #[cfg(crs)]
48 pub hsi48: Option<super::Hsi48Config>,
49
50 pub pll: Option<Pll>,
51
52 pub mux: ClockSrc,
53 pub ahb_pre: AHBPrescaler,
54 pub apb1_pre: APBPrescaler,
55 pub apb2_pre: APBPrescaler,
56
57 pub ls: super::LsConfig,
58 pub voltage_scale: VoltageScale,
59}
60
61impl Default for Config {
62 #[inline]
63 fn default() -> Config {
64 Config {
65 msi: Some(MSIRange::RANGE5),
66 hse: None,
67 hsi: false,
68 #[cfg(crs)]
69 hsi48: Some(Default::default()),
70
71 pll: None,
72
73 mux: ClockSrc::MSI,
74 ahb_pre: AHBPrescaler::DIV1,
75 apb1_pre: APBPrescaler::DIV1,
76 apb2_pre: APBPrescaler::DIV1,
77 voltage_scale: VoltageScale::RANGE1,
78 ls: Default::default(),
79 }
80 }
81}
82
83pub(crate) unsafe fn init(config: Config) {
84 // Set voltage scale
85 while PWR.csr().read().vosf() {}
86 PWR.cr().write(|w| w.set_vos(config.voltage_scale));
87 while PWR.csr().read().vosf() {}
88
89 let rtc = config.ls.init();
90
91 let msi = config.msi.map(|range| {
92 RCC.icscr().modify(|w| w.set_msirange(range));
93
94 RCC.cr().modify(|w| w.set_msion(true));
95 while !RCC.cr().read().msirdy() {}
96
97 Hertz(32_768 * (1 << (range as u8 + 1)))
98 });
99
100 let hsi = config.hsi.then(|| {
101 RCC.cr().modify(|w| w.set_hsion(true));
102 while !RCC.cr().read().hsirdy() {}
103
104 HSI_FREQ
105 });
106
107 let hse = config.hse.map(|hse| {
108 RCC.cr().modify(|w| {
109 w.set_hsebyp(hse.mode == HseMode::Bypass);
110 w.set_hseon(true);
111 });
112 while !RCC.cr().read().hserdy() {}
113
114 hse.freq
115 });
116
117 let pll = config.pll.map(|pll| {
118 let freq = match pll.source {
119 PLLSource::HSE => hse.unwrap(),
120 PLLSource::HSI => hsi.unwrap(),
121 };
122
123 // Disable PLL
124 RCC.cr().modify(|w| w.set_pllon(false));
125 while RCC.cr().read().pllrdy() {}
126
127 let freq = freq * pll.mul / pll.div;
128
129 assert!(freq <= Hertz(32_000_000));
130
131 RCC.cfgr().write(move |w| {
132 w.set_pllmul(pll.mul);
133 w.set_plldiv(pll.div);
134 w.set_pllsrc(pll.source);
135 });
136
137 // Enable PLL
138 RCC.cr().modify(|w| w.set_pllon(true));
139 while !RCC.cr().read().pllrdy() {}
140
141 freq
142 });
143
144 let sys_clk = match config.mux {
145 ClockSrc::HSE => hse.unwrap(),
146 ClockSrc::HSI => hsi.unwrap(),
147 ClockSrc::MSI => msi.unwrap(),
148 ClockSrc::PLL1_P => pll.unwrap(),
149 };
150
151 let wait_states = match (config.voltage_scale, sys_clk.0) {
152 (VoltageScale::RANGE1, ..=16_000_000) => 0,
153 (VoltageScale::RANGE2, ..=8_000_000) => 0,
154 (VoltageScale::RANGE3, ..=4_200_000) => 0,
155 _ => 1,
156 };
157
158 #[cfg(stm32l1)]
159 FLASH.acr().write(|w| w.set_acc64(true));
160 FLASH.acr().modify(|w| w.set_prften(true));
161 FLASH.acr().modify(|w| w.set_latency(wait_states != 0));
162
163 RCC.cfgr().modify(|w| {
164 w.set_sw(config.mux);
165 w.set_hpre(config.ahb_pre);
166 w.set_ppre1(config.apb1_pre);
167 w.set_ppre2(config.apb2_pre);
168 });
169
170 let hclk1 = sys_clk / config.ahb_pre;
171 let (pclk1, pclk1_tim) = super::util::calc_pclk(hclk1, config.apb1_pre);
172 let (pclk2, pclk2_tim) = super::util::calc_pclk(hclk1, config.apb2_pre);
173
174 #[cfg(crs)]
175 let _hsi48 = config.hsi48.map(|config| {
176 // Select HSI48 as USB clock
177 RCC.ccipr().modify(|w| w.set_hsi48msel(true));
178 super::init_hsi48(config)
179 });
180
181 set_freqs(Clocks {
182 sys: sys_clk,
183 hclk1,
184 pclk1,
185 pclk2,
186 pclk1_tim,
187 pclk2_tim,
188 rtc,
189 });
190}
diff --git a/embassy-stm32/src/rcc/mod.rs b/embassy-stm32/src/rcc/mod.rs
index e15f4fe41..debd16ca1 100644
--- a/embassy-stm32/src/rcc/mod.rs
+++ b/embassy-stm32/src/rcc/mod.rs
@@ -23,8 +23,7 @@ pub use hsi48::*;
23#[cfg_attr(rcc_g0, path = "g0.rs")] 23#[cfg_attr(rcc_g0, path = "g0.rs")]
24#[cfg_attr(rcc_g4, path = "g4.rs")] 24#[cfg_attr(rcc_g4, path = "g4.rs")]
25#[cfg_attr(any(rcc_h5, rcc_h50, rcc_h7, rcc_h7rm0433, rcc_h7ab), path = "h.rs")] 25#[cfg_attr(any(rcc_h5, rcc_h50, rcc_h7, rcc_h7rm0433, rcc_h7ab), path = "h.rs")]
26#[cfg_attr(any(rcc_l0, rcc_l0_v2, rcc_l1), path = "l0l1.rs")] 26#[cfg_attr(any(stm32l0, stm32l1, stm32l4, stm32l5, stm32wb, stm32wl), path = "l.rs")]
27#[cfg_attr(any(rcc_l4, rcc_l4plus, rcc_l5, rcc_wl5, rcc_wle, rcc_wb), path = "l4l5.rs")]
28#[cfg_attr(rcc_u5, path = "u5.rs")] 27#[cfg_attr(rcc_u5, path = "u5.rs")]
29#[cfg_attr(rcc_wba, path = "wba.rs")] 28#[cfg_attr(rcc_wba, path = "wba.rs")]
30mod _version; 29mod _version;
diff --git a/embassy-stm32/src/rcc/u5.rs b/embassy-stm32/src/rcc/u5.rs
index c111362bf..81bdec881 100644
--- a/embassy-stm32/src/rcc/u5.rs
+++ b/embassy-stm32/src/rcc/u5.rs
@@ -35,7 +35,7 @@ impl Default for ClockSrc {
35#[derive(Clone, Copy)] 35#[derive(Clone, Copy)]
36pub struct PllConfig { 36pub struct PllConfig {
37 /// The clock source for the PLL. 37 /// The clock source for the PLL.
38 pub source: PllSrc, 38 pub source: PllSource,
39 /// The PLL prescaler. 39 /// The PLL prescaler.
40 /// 40 ///
41 /// The clock speed of the `source` divided by `m` must be between 4 and 16 MHz. 41 /// The clock speed of the `source` divided by `m` must be between 4 and 16 MHz.
@@ -57,7 +57,7 @@ impl PllConfig {
57 /// A configuration for HSI / 1 * 10 / 1 = 160 MHz 57 /// A configuration for HSI / 1 * 10 / 1 = 160 MHz
58 pub const fn hsi_160mhz() -> Self { 58 pub const fn hsi_160mhz() -> Self {
59 PllConfig { 59 PllConfig {
60 source: PllSrc::HSI, 60 source: PllSource::HSI,
61 m: Pllm::DIV1, 61 m: Pllm::DIV1,
62 n: Plln::MUL10, 62 n: Plln::MUL10,
63 r: Plldiv::DIV1, 63 r: Plldiv::DIV1,
@@ -67,7 +67,7 @@ impl PllConfig {
67 /// A configuration for MSIS @ 48 MHz / 3 * 10 / 1 = 160 MHz 67 /// A configuration for MSIS @ 48 MHz / 3 * 10 / 1 = 160 MHz
68 pub const fn msis_160mhz() -> Self { 68 pub const fn msis_160mhz() -> Self {
69 PllConfig { 69 PllConfig {
70 source: PllSrc::MSIS(Msirange::RANGE_48MHZ), 70 source: PllSource::MSIS(Msirange::RANGE_48MHZ),
71 m: Pllm::DIV3, 71 m: Pllm::DIV3,
72 n: Plln::MUL10, 72 n: Plln::MUL10,
73 r: Plldiv::DIV1, 73 r: Plldiv::DIV1,
@@ -76,7 +76,7 @@ impl PllConfig {
76} 76}
77 77
78#[derive(Clone, Copy)] 78#[derive(Clone, Copy)]
79pub enum PllSrc { 79pub enum PllSource {
80 /// Use an internal medium speed oscillator as the PLL source. 80 /// Use an internal medium speed oscillator as the PLL source.
81 MSIS(Msirange), 81 MSIS(Msirange),
82 /// Use the external high speed clock as the system PLL source. 82 /// Use the external high speed clock as the system PLL source.
@@ -88,12 +88,12 @@ pub enum PllSrc {
88 HSI, 88 HSI,
89} 89}
90 90
91impl Into<Pllsrc> for PllSrc { 91impl Into<Pllsrc> for PllSource {
92 fn into(self) -> Pllsrc { 92 fn into(self) -> Pllsrc {
93 match self { 93 match self {
94 PllSrc::MSIS(..) => Pllsrc::MSIS, 94 PllSource::MSIS(..) => Pllsrc::MSIS,
95 PllSrc::HSE(..) => Pllsrc::HSE, 95 PllSource::HSE(..) => Pllsrc::HSE,
96 PllSrc::HSI => Pllsrc::HSI, 96 PllSource::HSI => Pllsrc::HSI,
97 } 97 }
98 } 98 }
99} 99}
@@ -216,9 +216,9 @@ pub(crate) unsafe fn init(config: Config) {
216 ClockSrc::PLL1_R(pll) => { 216 ClockSrc::PLL1_R(pll) => {
217 // Configure the PLL source 217 // Configure the PLL source
218 let source_clk = match pll.source { 218 let source_clk = match pll.source {
219 PllSrc::MSIS(range) => config.init_msis(range), 219 PllSource::MSIS(range) => config.init_msis(range),
220 PllSrc::HSE(hertz) => config.init_hse(hertz), 220 PllSource::HSE(hertz) => config.init_hse(hertz),
221 PllSrc::HSI => config.init_hsi(), 221 PllSource::HSI => config.init_hsi(),
222 }; 222 };
223 223
224 // Calculate the reference clock, which is the source divided by m 224 // Calculate the reference clock, which is the source divided by m
diff --git a/embassy-stm32/src/rcc/wba.rs b/embassy-stm32/src/rcc/wba.rs
index 8925d9606..c0cd91507 100644
--- a/embassy-stm32/src/rcc/wba.rs
+++ b/embassy-stm32/src/rcc/wba.rs
@@ -17,16 +17,16 @@ pub enum ClockSrc {
17} 17}
18 18
19#[derive(Clone, Copy, Debug)] 19#[derive(Clone, Copy, Debug)]
20pub enum PllSrc { 20pub enum PllSource {
21 HSE(Hertz), 21 HSE(Hertz),
22 HSI, 22 HSI,
23} 23}
24 24
25impl Into<Pllsrc> for PllSrc { 25impl Into<Pllsrc> for PllSource {
26 fn into(self) -> Pllsrc { 26 fn into(self) -> Pllsrc {
27 match self { 27 match self {
28 PllSrc::HSE(..) => Pllsrc::HSE, 28 PllSource::HSE(..) => Pllsrc::HSE,
29 PllSrc::HSI => Pllsrc::HSI, 29 PllSource::HSI => Pllsrc::HSI,
30 } 30 }
31 } 31 }
32} 32}
diff --git a/examples/stm32f2/src/bin/pll.rs b/examples/stm32f2/src/bin/pll.rs
index 56591b527..feec90016 100644
--- a/examples/stm32f2/src/bin/pll.rs
+++ b/examples/stm32f2/src/bin/pll.rs
@@ -7,7 +7,7 @@ use core::convert::TryFrom;
7use defmt::*; 7use defmt::*;
8use embassy_executor::Spawner; 8use embassy_executor::Spawner;
9use embassy_stm32::rcc::{ 9use embassy_stm32::rcc::{
10 APBPrescaler, ClockSrc, HSEConfig, HSESrc, PLLConfig, PLLMul, PLLPDiv, PLLPreDiv, PLLQDiv, PLLSrc, 10 APBPrescaler, ClockSrc, HSEConfig, HSESrc, Pll, PllMul, PllPDiv, PllPreDiv, PllQDiv, PllSource,
11}; 11};
12use embassy_stm32::time::Hertz; 12use embassy_stm32::time::Hertz;
13use embassy_stm32::Config; 13use embassy_stm32::Config;
@@ -25,16 +25,16 @@ async fn main(_spawner: Spawner) {
25 source: HSESrc::Bypass, 25 source: HSESrc::Bypass,
26 }); 26 });
27 // PLL uses HSE as the clock source 27 // PLL uses HSE as the clock source
28 config.rcc.pll_mux = PLLSrc::HSE; 28 config.rcc.pll_mux = PllSource::HSE;
29 config.rcc.pll = PLLConfig { 29 config.rcc.pll = Pll {
30 // 8 MHz clock source / 8 = 1 MHz PLL input 30 // 8 MHz clock source / 8 = 1 MHz PLL input
31 pre_div: unwrap!(PLLPreDiv::try_from(8)), 31 pre_div: unwrap!(PllPreDiv::try_from(8)),
32 // 1 MHz PLL input * 240 = 240 MHz PLL VCO 32 // 1 MHz PLL input * 240 = 240 MHz PLL VCO
33 mul: unwrap!(PLLMul::try_from(240)), 33 mul: unwrap!(PllMul::try_from(240)),
34 // 240 MHz PLL VCO / 2 = 120 MHz main PLL output 34 // 240 MHz PLL VCO / 2 = 120 MHz main PLL output
35 p_div: PLLPDiv::DIV2, 35 divp: PllPDiv::DIV2,
36 // 240 MHz PLL VCO / 5 = 48 MHz PLL48 output 36 // 240 MHz PLL VCO / 5 = 48 MHz PLL48 output
37 q_div: PLLQDiv::DIV5, 37 divq: PllQDiv::DIV5,
38 }; 38 };
39 // System clock comes from PLL (= the 120 MHz main PLL output) 39 // System clock comes from PLL (= the 120 MHz main PLL output)
40 config.rcc.mux = ClockSrc::PLL; 40 config.rcc.mux = ClockSrc::PLL;
diff --git a/examples/stm32g4/src/bin/adc.rs b/examples/stm32g4/src/bin/adc.rs
index f05733847..63b20c0d4 100644
--- a/examples/stm32g4/src/bin/adc.rs
+++ b/examples/stm32g4/src/bin/adc.rs
@@ -5,7 +5,7 @@
5use defmt::*; 5use defmt::*;
6use embassy_executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::adc::{Adc, SampleTime}; 7use embassy_stm32::adc::{Adc, SampleTime};
8use embassy_stm32::rcc::{AdcClockSource, ClockSrc, Pll, PllM, PllN, PllR, PllSrc}; 8use embassy_stm32::rcc::{AdcClockSource, ClockSrc, Pll, PllM, PllN, PllR, PllSource};
9use embassy_stm32::Config; 9use embassy_stm32::Config;
10use embassy_time::{Delay, Timer}; 10use embassy_time::{Delay, Timer};
11use {defmt_rtt as _, panic_probe as _}; 11use {defmt_rtt as _, panic_probe as _};
@@ -15,7 +15,7 @@ async fn main(_spawner: Spawner) {
15 let mut config = Config::default(); 15 let mut config = Config::default();
16 16
17 config.rcc.pll = Some(Pll { 17 config.rcc.pll = Some(Pll {
18 source: PllSrc::HSI, 18 source: PllSource::HSI,
19 prediv_m: PllM::DIV4, 19 prediv_m: PllM::DIV4,
20 mul_n: PllN::MUL85, 20 mul_n: PllN::MUL85,
21 div_p: None, 21 div_p: None,
diff --git a/examples/stm32g4/src/bin/pll.rs b/examples/stm32g4/src/bin/pll.rs
index 90c3f8dce..09ef59d44 100644
--- a/examples/stm32g4/src/bin/pll.rs
+++ b/examples/stm32g4/src/bin/pll.rs
@@ -4,7 +4,7 @@
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::rcc::{ClockSrc, Pll, PllM, PllN, PllR, PllSrc}; 7use embassy_stm32::rcc::{ClockSrc, Pll, PllM, PllN, PllR, PllSource};
8use embassy_stm32::Config; 8use embassy_stm32::Config;
9use embassy_time::Timer; 9use embassy_time::Timer;
10use {defmt_rtt as _, panic_probe as _}; 10use {defmt_rtt as _, panic_probe as _};
@@ -14,7 +14,7 @@ async fn main(_spawner: Spawner) {
14 let mut config = Config::default(); 14 let mut config = Config::default();
15 15
16 config.rcc.pll = Some(Pll { 16 config.rcc.pll = Some(Pll {
17 source: PllSrc::HSI, 17 source: PllSource::HSI,
18 prediv_m: PllM::DIV4, 18 prediv_m: PllM::DIV4,
19 mul_n: PllN::MUL85, 19 mul_n: PllN::MUL85,
20 div_p: None, 20 div_p: None,
diff --git a/examples/stm32g4/src/bin/usb_serial.rs b/examples/stm32g4/src/bin/usb_serial.rs
index 378e7b988..565b25d60 100644
--- a/examples/stm32g4/src/bin/usb_serial.rs
+++ b/examples/stm32g4/src/bin/usb_serial.rs
@@ -4,7 +4,7 @@
4 4
5use defmt::{panic, *}; 5use defmt::{panic, *};
6use embassy_executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::rcc::{Clock48MhzSrc, ClockSrc, Hsi48Config, Pll, PllM, PllN, PllQ, PllR, PllSrc}; 7use embassy_stm32::rcc::{Clock48MhzSrc, ClockSrc, Hsi48Config, Pll, PllM, PllN, PllQ, PllR, PllSource};
8use embassy_stm32::time::Hertz; 8use embassy_stm32::time::Hertz;
9use embassy_stm32::usb::{self, Driver, Instance}; 9use embassy_stm32::usb::{self, Driver, Instance};
10use embassy_stm32::{bind_interrupts, peripherals, Config}; 10use embassy_stm32::{bind_interrupts, peripherals, Config};
@@ -25,14 +25,14 @@ async fn main(_spawner: Spawner) {
25 // Change this to `false` to use the HSE clock source for the USB. This example assumes an 8MHz HSE. 25 // Change this to `false` to use the HSE clock source for the USB. This example assumes an 8MHz HSE.
26 const USE_HSI48: bool = true; 26 const USE_HSI48: bool = true;
27 27
28 let pllq_div = if USE_HSI48 { None } else { Some(PllQ::DIV6) }; 28 let plldivq = if USE_HSI48 { None } else { Some(PllQ::DIV6) };
29 29
30 config.rcc.pll = Some(Pll { 30 config.rcc.pll = Some(Pll {
31 source: PllSrc::HSE(Hertz(8_000_000)), 31 source: PllSource::HSE(Hertz(8_000_000)),
32 prediv_m: PllM::DIV2, 32 prediv_m: PllM::DIV2,
33 mul_n: PllN::MUL72, 33 mul_n: PllN::MUL72,
34 div_p: None, 34 div_p: None,
35 div_q: pllq_div, 35 div_q: plldivq,
36 // Main system clock at 144 MHz 36 // Main system clock at 144 MHz
37 div_r: Some(PllR::DIV2), 37 div_r: Some(PllR::DIV2),
38 }); 38 });
diff --git a/examples/stm32l4/src/bin/rng.rs b/examples/stm32l4/src/bin/rng.rs
index 553d11c03..e5ad56fb9 100644
--- a/examples/stm32l4/src/bin/rng.rs
+++ b/examples/stm32l4/src/bin/rng.rs
@@ -4,7 +4,7 @@
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::rcc::{ClockSrc, PLLSource, Pll, PllMul, PllPreDiv, PllQDiv, PllRDiv}; 7use embassy_stm32::rcc::{ClockSrc, Pll, PllMul, PllPreDiv, PllQDiv, PllRDiv, PllSource};
8use embassy_stm32::rng::Rng; 8use embassy_stm32::rng::Rng;
9use embassy_stm32::{bind_interrupts, peripherals, rng, Config}; 9use embassy_stm32::{bind_interrupts, peripherals, rng, Config};
10use {defmt_rtt as _, panic_probe as _}; 10use {defmt_rtt as _, panic_probe as _};
@@ -19,7 +19,7 @@ async fn main(_spawner: Spawner) {
19 config.rcc.mux = ClockSrc::PLL1_R; 19 config.rcc.mux = ClockSrc::PLL1_R;
20 config.rcc.hsi = true; 20 config.rcc.hsi = true;
21 config.rcc.pll = Some(Pll { 21 config.rcc.pll = Some(Pll {
22 source: PLLSource::HSI, 22 source: PllSource::HSI,
23 prediv: PllPreDiv::DIV1, 23 prediv: PllPreDiv::DIV1,
24 mul: PllMul::MUL18, 24 mul: PllMul::MUL18,
25 divp: None, 25 divp: None,
diff --git a/examples/stm32l4/src/bin/rtc.rs b/examples/stm32l4/src/bin/rtc.rs
index 69527c9ad..d2a2aa1f2 100644
--- a/examples/stm32l4/src/bin/rtc.rs
+++ b/examples/stm32l4/src/bin/rtc.rs
@@ -22,7 +22,7 @@ async fn main(_spawner: Spawner) {
22 mode: HseMode::Oscillator, 22 mode: HseMode::Oscillator,
23 }); 23 });
24 config.rcc.pll = Some(Pll { 24 config.rcc.pll = Some(Pll {
25 source: PLLSource::HSE, 25 source: PllSource::HSE,
26 prediv: PllPreDiv::DIV1, 26 prediv: PllPreDiv::DIV1,
27 mul: PllMul::MUL20, 27 mul: PllMul::MUL20,
28 divp: None, 28 divp: None,
diff --git a/examples/stm32l4/src/bin/spe_adin1110_http_server.rs b/examples/stm32l4/src/bin/spe_adin1110_http_server.rs
index 62caeea55..3a7e5370c 100644
--- a/examples/stm32l4/src/bin/spe_adin1110_http_server.rs
+++ b/examples/stm32l4/src/bin/spe_adin1110_http_server.rs
@@ -75,7 +75,7 @@ async fn main(spawner: Spawner) {
75 let mut config = embassy_stm32::Config::default(); 75 let mut config = embassy_stm32::Config::default();
76 { 76 {
77 use embassy_stm32::rcc::*; 77 use embassy_stm32::rcc::*;
78 // 80Mhz clock (Source: 8 / SrcDiv: 1 * PLLMul 20 / ClkDiv 2) 78 // 80Mhz clock (Source: 8 / SrcDiv: 1 * PllMul 20 / ClkDiv 2)
79 // 80MHz highest frequency for flash 0 wait. 79 // 80MHz highest frequency for flash 0 wait.
80 config.rcc.mux = ClockSrc::PLL1_R; 80 config.rcc.mux = ClockSrc::PLL1_R;
81 config.rcc.hse = Some(Hse { 81 config.rcc.hse = Some(Hse {
@@ -83,7 +83,7 @@ async fn main(spawner: Spawner) {
83 mode: HseMode::Oscillator, 83 mode: HseMode::Oscillator,
84 }); 84 });
85 config.rcc.pll = Some(Pll { 85 config.rcc.pll = Some(Pll {
86 source: PLLSource::HSE, 86 source: PllSource::HSE,
87 prediv: PllPreDiv::DIV1, 87 prediv: PllPreDiv::DIV1,
88 mul: PllMul::MUL20, 88 mul: PllMul::MUL20,
89 divp: None, 89 divp: None,
diff --git a/examples/stm32l4/src/bin/usb_serial.rs b/examples/stm32l4/src/bin/usb_serial.rs
index d977398f5..4baf5f05d 100644
--- a/examples/stm32l4/src/bin/usb_serial.rs
+++ b/examples/stm32l4/src/bin/usb_serial.rs
@@ -27,7 +27,7 @@ async fn main(_spawner: Spawner) {
27 config.rcc.mux = ClockSrc::PLL1_R; 27 config.rcc.mux = ClockSrc::PLL1_R;
28 config.rcc.hsi = true; 28 config.rcc.hsi = true;
29 config.rcc.pll = Some(Pll { 29 config.rcc.pll = Some(Pll {
30 source: PLLSource::HSI, 30 source: PllSource::HSI,
31 prediv: PllPreDiv::DIV1, 31 prediv: PllPreDiv::DIV1,
32 mul: PllMul::MUL10, 32 mul: PllMul::MUL10,
33 divp: None, 33 divp: None,
diff --git a/examples/stm32l5/src/bin/rng.rs b/examples/stm32l5/src/bin/rng.rs
index b9d4cd255..279f4f65d 100644
--- a/examples/stm32l5/src/bin/rng.rs
+++ b/examples/stm32l5/src/bin/rng.rs
@@ -4,7 +4,7 @@
4 4
5use defmt::*; 5use defmt::*;
6use embassy_executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::rcc::{ClockSrc, PLLSource, Pll, PllMul, PllPreDiv, PllRDiv}; 7use embassy_stm32::rcc::{ClockSrc, Pll, PllMul, PllPreDiv, PllRDiv, PllSource};
8use embassy_stm32::rng::Rng; 8use embassy_stm32::rng::Rng;
9use embassy_stm32::{bind_interrupts, peripherals, rng, Config}; 9use embassy_stm32::{bind_interrupts, peripherals, rng, Config};
10use {defmt_rtt as _, panic_probe as _}; 10use {defmt_rtt as _, panic_probe as _};
@@ -20,7 +20,7 @@ async fn main(_spawner: Spawner) {
20 config.rcc.mux = ClockSrc::PLL1_R; 20 config.rcc.mux = ClockSrc::PLL1_R;
21 config.rcc.pll = Some(Pll { 21 config.rcc.pll = Some(Pll {
22 // 64Mhz clock (16 / 1 * 8 / 2) 22 // 64Mhz clock (16 / 1 * 8 / 2)
23 source: PLLSource::HSI, 23 source: PllSource::HSI,
24 prediv: PllPreDiv::DIV1, 24 prediv: PllPreDiv::DIV1,
25 mul: PllMul::MUL8, 25 mul: PllMul::MUL8,
26 divp: None, 26 divp: None,
diff --git a/examples/stm32l5/src/bin/usb_ethernet.rs b/examples/stm32l5/src/bin/usb_ethernet.rs
index 923193abf..0b0a0e2db 100644
--- a/examples/stm32l5/src/bin/usb_ethernet.rs
+++ b/examples/stm32l5/src/bin/usb_ethernet.rs
@@ -49,7 +49,7 @@ async fn main(spawner: Spawner) {
49 config.rcc.mux = ClockSrc::PLL1_R; 49 config.rcc.mux = ClockSrc::PLL1_R;
50 config.rcc.pll = Some(Pll { 50 config.rcc.pll = Some(Pll {
51 // 80Mhz clock (16 / 1 * 10 / 2) 51 // 80Mhz clock (16 / 1 * 10 / 2)
52 source: PLLSource::HSI, 52 source: PllSource::HSI,
53 prediv: PllPreDiv::DIV1, 53 prediv: PllPreDiv::DIV1,
54 mul: PllMul::MUL10, 54 mul: PllMul::MUL10,
55 divp: None, 55 divp: None,
diff --git a/examples/stm32l5/src/bin/usb_hid_mouse.rs b/examples/stm32l5/src/bin/usb_hid_mouse.rs
index f64d0f34e..3614a8e0a 100644
--- a/examples/stm32l5/src/bin/usb_hid_mouse.rs
+++ b/examples/stm32l5/src/bin/usb_hid_mouse.rs
@@ -26,7 +26,7 @@ async fn main(_spawner: Spawner) {
26 config.rcc.mux = ClockSrc::PLL1_R; 26 config.rcc.mux = ClockSrc::PLL1_R;
27 config.rcc.pll = Some(Pll { 27 config.rcc.pll = Some(Pll {
28 // 80Mhz clock (16 / 1 * 10 / 2) 28 // 80Mhz clock (16 / 1 * 10 / 2)
29 source: PLLSource::HSI, 29 source: PllSource::HSI,
30 prediv: PllPreDiv::DIV1, 30 prediv: PllPreDiv::DIV1,
31 mul: PllMul::MUL10, 31 mul: PllMul::MUL10,
32 divp: None, 32 divp: None,
diff --git a/examples/stm32l5/src/bin/usb_serial.rs b/examples/stm32l5/src/bin/usb_serial.rs
index 58a8898a6..f2b894b68 100644
--- a/examples/stm32l5/src/bin/usb_serial.rs
+++ b/examples/stm32l5/src/bin/usb_serial.rs
@@ -24,7 +24,7 @@ async fn main(_spawner: Spawner) {
24 config.rcc.mux = ClockSrc::PLL1_R; 24 config.rcc.mux = ClockSrc::PLL1_R;
25 config.rcc.pll = Some(Pll { 25 config.rcc.pll = Some(Pll {
26 // 80Mhz clock (16 / 1 * 10 / 2) 26 // 80Mhz clock (16 / 1 * 10 / 2)
27 source: PLLSource::HSI, 27 source: PllSource::HSI,
28 prediv: PllPreDiv::DIV1, 28 prediv: PllPreDiv::DIV1,
29 mul: PllMul::MUL10, 29 mul: PllMul::MUL10,
30 divp: None, 30 divp: None,
diff --git a/examples/stm32u5/src/bin/usb_serial.rs b/examples/stm32u5/src/bin/usb_serial.rs
index a218d5dfd..839d6472f 100644
--- a/examples/stm32u5/src/bin/usb_serial.rs
+++ b/examples/stm32u5/src/bin/usb_serial.rs
@@ -24,7 +24,7 @@ async fn main(_spawner: Spawner) {
24 24
25 let mut config = Config::default(); 25 let mut config = Config::default();
26 config.rcc.mux = ClockSrc::PLL1_R(PllConfig { 26 config.rcc.mux = ClockSrc::PLL1_R(PllConfig {
27 source: PllSrc::HSI, 27 source: PllSource::HSI,
28 m: Pllm::DIV2, 28 m: Pllm::DIV2,
29 n: Plln::MUL10, 29 n: Plln::MUL10,
30 r: Plldiv::DIV1, 30 r: Plldiv::DIV1,
diff --git a/examples/stm32wl/src/bin/lora_lorawan.rs b/examples/stm32wl/src/bin/lora_lorawan.rs
index 226e6786f..348e3cdce 100644
--- a/examples/stm32wl/src/bin/lora_lorawan.rs
+++ b/examples/stm32wl/src/bin/lora_lorawan.rs
@@ -44,7 +44,7 @@ async fn main(_spawner: Spawner) {
44 }); 44 });
45 config.rcc.mux = ClockSrc::PLL1_R; 45 config.rcc.mux = ClockSrc::PLL1_R;
46 config.rcc.pll = Some(Pll { 46 config.rcc.pll = Some(Pll {
47 source: PLLSource::HSE, 47 source: PllSource::HSE,
48 prediv: PllPreDiv::DIV2, 48 prediv: PllPreDiv::DIV2,
49 mul: PllMul::MUL6, 49 mul: PllMul::MUL6,
50 divp: None, 50 divp: None,
diff --git a/examples/stm32wl/src/bin/lora_p2p_receive.rs b/examples/stm32wl/src/bin/lora_p2p_receive.rs
index a3bb0c0f9..c643ddb15 100644
--- a/examples/stm32wl/src/bin/lora_p2p_receive.rs
+++ b/examples/stm32wl/src/bin/lora_p2p_receive.rs
@@ -37,7 +37,7 @@ async fn main(_spawner: Spawner) {
37 }); 37 });
38 config.rcc.mux = ClockSrc::PLL1_R; 38 config.rcc.mux = ClockSrc::PLL1_R;
39 config.rcc.pll = Some(Pll { 39 config.rcc.pll = Some(Pll {
40 source: PLLSource::HSE, 40 source: PllSource::HSE,
41 prediv: PllPreDiv::DIV2, 41 prediv: PllPreDiv::DIV2,
42 mul: PllMul::MUL6, 42 mul: PllMul::MUL6,
43 divp: None, 43 divp: None,
diff --git a/examples/stm32wl/src/bin/lora_p2p_send.rs b/examples/stm32wl/src/bin/lora_p2p_send.rs
index 08dd0845e..7fe8cea3e 100644
--- a/examples/stm32wl/src/bin/lora_p2p_send.rs
+++ b/examples/stm32wl/src/bin/lora_p2p_send.rs
@@ -37,7 +37,7 @@ async fn main(_spawner: Spawner) {
37 }); 37 });
38 config.rcc.mux = ClockSrc::PLL1_R; 38 config.rcc.mux = ClockSrc::PLL1_R;
39 config.rcc.pll = Some(Pll { 39 config.rcc.pll = Some(Pll {
40 source: PLLSource::HSE, 40 source: PllSource::HSE,
41 prediv: PllPreDiv::DIV2, 41 prediv: PllPreDiv::DIV2,
42 mul: PllMul::MUL6, 42 mul: PllMul::MUL6,
43 divp: None, 43 divp: None,
diff --git a/examples/stm32wl/src/bin/random.rs b/examples/stm32wl/src/bin/random.rs
index 1a8822b42..2fd234966 100644
--- a/examples/stm32wl/src/bin/random.rs
+++ b/examples/stm32wl/src/bin/random.rs
@@ -25,7 +25,7 @@ async fn main(_spawner: Spawner) {
25 }); 25 });
26 config.rcc.mux = ClockSrc::PLL1_R; 26 config.rcc.mux = ClockSrc::PLL1_R;
27 config.rcc.pll = Some(Pll { 27 config.rcc.pll = Some(Pll {
28 source: PLLSource::HSE, 28 source: PllSource::HSE,
29 prediv: PllPreDiv::DIV2, 29 prediv: PllPreDiv::DIV2,
30 mul: PllMul::MUL6, 30 mul: PllMul::MUL6,
31 divp: None, 31 divp: None,
diff --git a/examples/stm32wl/src/bin/rtc.rs b/examples/stm32wl/src/bin/rtc.rs
index b3b7f9c5c..4ffb0bb58 100644
--- a/examples/stm32wl/src/bin/rtc.rs
+++ b/examples/stm32wl/src/bin/rtc.rs
@@ -24,7 +24,7 @@ async fn main(_spawner: Spawner) {
24 }); 24 });
25 config.rcc.mux = ClockSrc::PLL1_R; 25 config.rcc.mux = ClockSrc::PLL1_R;
26 config.rcc.pll = Some(Pll { 26 config.rcc.pll = Some(Pll {
27 source: PLLSource::HSE, 27 source: PllSource::HSE,
28 prediv: PllPreDiv::DIV2, 28 prediv: PllPreDiv::DIV2,
29 mul: PllMul::MUL6, 29 mul: PllMul::MUL6,
30 divp: None, 30 divp: None,
diff --git a/tests/stm32/src/common.rs b/tests/stm32/src/common.rs
index 3668e18ce..e7367d5ed 100644
--- a/tests/stm32/src/common.rs
+++ b/tests/stm32/src/common.rs
@@ -241,16 +241,16 @@ pub fn config() -> Config {
241 source: HSESrc::Bypass, 241 source: HSESrc::Bypass,
242 }); 242 });
243 // PLL uses HSE as the clock source 243 // PLL uses HSE as the clock source
244 config.rcc.pll_mux = PLLSrc::HSE; 244 config.rcc.pll_mux = PllSource::HSE;
245 config.rcc.pll = PLLConfig { 245 config.rcc.pll = Pll {
246 // 8 MHz clock source / 8 = 1 MHz PLL input 246 // 8 MHz clock source / 8 = 1 MHz PLL input
247 pre_div: unwrap!(PLLPreDiv::try_from(8)), 247 pre_div: unwrap!(PllPreDiv::try_from(8)),
248 // 1 MHz PLL input * 240 = 240 MHz PLL VCO 248 // 1 MHz PLL input * 240 = 240 MHz PLL VCO
249 mul: unwrap!(PLLMul::try_from(240)), 249 mul: unwrap!(PllMul::try_from(240)),
250 // 240 MHz PLL VCO / 2 = 120 MHz main PLL output 250 // 240 MHz PLL VCO / 2 = 120 MHz main PLL output
251 p_div: PLLPDiv::DIV2, 251 divp: PllPDiv::DIV2,
252 // 240 MHz PLL VCO / 5 = 48 MHz PLL48 output 252 // 240 MHz PLL VCO / 5 = 48 MHz PLL48 output
253 q_div: PLLQDiv::DIV5, 253 divq: PllQDiv::DIV5,
254 }; 254 };
255 // System clock comes from PLL (= the 120 MHz main PLL output) 255 // System clock comes from PLL (= the 120 MHz main PLL output)
256 config.rcc.mux = ClockSrc::PLL; 256 config.rcc.mux = ClockSrc::PLL;
@@ -397,7 +397,7 @@ pub fn config() -> Config {
397 config.rcc.mux = ClockSrc::PLL1_R; 397 config.rcc.mux = ClockSrc::PLL1_R;
398 config.rcc.hsi = true; 398 config.rcc.hsi = true;
399 config.rcc.pll = Some(Pll { 399 config.rcc.pll = Some(Pll {
400 source: PLLSource::HSI, 400 source: PllSource::HSI,
401 prediv: PllPreDiv::DIV1, 401 prediv: PllPreDiv::DIV1,
402 mul: PllMul::MUL18, 402 mul: PllMul::MUL18,
403 divp: None, 403 divp: None,
@@ -416,7 +416,7 @@ pub fn config() -> Config {
416 }); 416 });
417 config.rcc.mux = ClockSrc::PLL1_R; 417 config.rcc.mux = ClockSrc::PLL1_R;
418 config.rcc.pll = Some(Pll { 418 config.rcc.pll = Some(Pll {
419 source: PLLSource::HSE, 419 source: PllSource::HSE,
420 prediv: PllPreDiv::DIV2, 420 prediv: PllPreDiv::DIV2,
421 mul: PllMul::MUL6, 421 mul: PllMul::MUL6,
422 divp: None, 422 divp: None,
@@ -432,7 +432,7 @@ pub fn config() -> Config {
432 config.rcc.mux = ClockSrc::PLL1_R; 432 config.rcc.mux = ClockSrc::PLL1_R;
433 config.rcc.pll = Some(Pll { 433 config.rcc.pll = Some(Pll {
434 // 110Mhz clock (16 / 4 * 55 / 2) 434 // 110Mhz clock (16 / 4 * 55 / 2)
435 source: PLLSource::HSI, 435 source: PllSource::HSI,
436 prediv: PllPreDiv::DIV4, 436 prediv: PllPreDiv::DIV4,
437 mul: PllMul::MUL55, 437 mul: PllMul::MUL55,
438 divp: None, 438 divp: None,
@@ -462,11 +462,11 @@ pub fn config() -> Config {
462 use embassy_stm32::rcc::*; 462 use embassy_stm32::rcc::*;
463 config.rcc.hsi = true; 463 config.rcc.hsi = true;
464 config.rcc.pll = Some(Pll { 464 config.rcc.pll = Some(Pll {
465 source: PLLSource::HSI, 465 source: PllSource::HSI,
466 mul: PLLMul::MUL4, 466 mul: PllMul::MUL4,
467 div: PLLDiv::DIV2, // 32Mhz clock (16 * 4 / 2) 467 div: PllDiv::DIV2, // 32Mhz clock (16 * 4 / 2)
468 }); 468 });
469 config.rcc.mux = ClockSrc::PLL1_P; 469 config.rcc.mux = ClockSrc::PLL1_R;
470 } 470 }
471 471
472 #[cfg(any(feature = "stm32l152re"))] 472 #[cfg(any(feature = "stm32l152re"))]
@@ -474,11 +474,11 @@ pub fn config() -> Config {
474 use embassy_stm32::rcc::*; 474 use embassy_stm32::rcc::*;
475 config.rcc.hsi = true; 475 config.rcc.hsi = true;
476 config.rcc.pll = Some(Pll { 476 config.rcc.pll = Some(Pll {
477 source: PLLSource::HSI, 477 source: PllSource::HSI,
478 mul: PLLMul::MUL4, 478 mul: PllMul::MUL4,
479 div: PLLDiv::DIV2, // 32Mhz clock (16 * 4 / 2) 479 div: PllDiv::DIV2, // 32Mhz clock (16 * 4 / 2)
480 }); 480 });
481 config.rcc.mux = ClockSrc::PLL1_P; 481 config.rcc.mux = ClockSrc::PLL1_R;
482 } 482 }
483 483
484 config 484 config