aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-stm32/Cargo.toml4
-rw-r--r--embassy-stm32/src/eth/v1/mod.rs1
-rw-r--r--embassy-stm32/src/eth/v2/mod.rs1
-rw-r--r--embassy-stm32/src/exti.rs5
-rw-r--r--embassy-stm32/src/gpio.rs3
-rw-r--r--embassy-stm32/src/lib.rs10
-rw-r--r--embassy-stm32/src/rcc/f2.rs5
-rw-r--r--embassy-stm32/src/rcc/f4.rs3
-rw-r--r--embassy-stm32/src/rcc/f7.rs8
-rw-r--r--embassy-stm32/src/rcc/h.rs5
-rw-r--r--embassy-stm32/src/rcc/l0.rs7
-rw-r--r--embassy-stm32/src/rcc/l4.rs4
-rw-r--r--embassy-stm32/src/rtc/v2.rs14
-rw-r--r--embassy-stm32/src/usb/usb.rs5
-rw-r--r--embassy-stm32/src/usb_otg/usb.rs12
15 files changed, 20 insertions, 67 deletions
diff --git a/embassy-stm32/Cargo.toml b/embassy-stm32/Cargo.toml
index dd19db24c..ef0ef229b 100644
--- a/embassy-stm32/Cargo.toml
+++ b/embassy-stm32/Cargo.toml
@@ -59,7 +59,7 @@ sdio-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"
61atomic-polyfill = "1.0.1" 61atomic-polyfill = "1.0.1"
62stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-2bdbec6dc0fd5fcef5d9fb473de1fc5050a054c2" } 62stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-74025d56c0ba061703f360558ce80f51d1165060" }
63vcell = "0.1.3" 63vcell = "0.1.3"
64bxcan = "0.7.0" 64bxcan = "0.7.0"
65nb = "1.0.0" 65nb = "1.0.0"
@@ -78,7 +78,7 @@ critical-section = { version = "1.1", features = ["std"] }
78[build-dependencies] 78[build-dependencies]
79proc-macro2 = "1.0.36" 79proc-macro2 = "1.0.36"
80quote = "1.0.15" 80quote = "1.0.15"
81stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-2bdbec6dc0fd5fcef5d9fb473de1fc5050a054c2", default-features = false, features = ["metadata"]} 81stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-74025d56c0ba061703f360558ce80f51d1165060", default-features = false, features = ["metadata"]}
82 82
83[features] 83[features]
84default = ["rt"] 84default = ["rt"]
diff --git a/embassy-stm32/src/eth/v1/mod.rs b/embassy-stm32/src/eth/v1/mod.rs
index a1e0240c8..4d19103dd 100644
--- a/embassy-stm32/src/eth/v1/mod.rs
+++ b/embassy-stm32/src/eth/v1/mod.rs
@@ -129,7 +129,6 @@ impl<'d, T: Instance, P: PHY> Ethernet<'d, T, P> {
129 129
130 #[cfg(any(eth_v1b, eth_v1c))] 130 #[cfg(any(eth_v1b, eth_v1c))]
131 critical_section::with(|_| { 131 critical_section::with(|_| {
132 RCC.apb2enr().modify(|w| w.set_syscfgen(true));
133 RCC.ahb1enr().modify(|w| { 132 RCC.ahb1enr().modify(|w| {
134 w.set_ethen(true); 133 w.set_ethen(true);
135 w.set_ethtxen(true); 134 w.set_ethtxen(true);
diff --git a/embassy-stm32/src/eth/v2/mod.rs b/embassy-stm32/src/eth/v2/mod.rs
index ada495fdb..f03ea2e31 100644
--- a/embassy-stm32/src/eth/v2/mod.rs
+++ b/embassy-stm32/src/eth/v2/mod.rs
@@ -80,7 +80,6 @@ impl<'d, T: Instance, P: PHY> Ethernet<'d, T, P> {
80 // Enable the necessary Clocks 80 // Enable the necessary Clocks
81 #[cfg(not(rcc_h5))] 81 #[cfg(not(rcc_h5))]
82 critical_section::with(|_| { 82 critical_section::with(|_| {
83 crate::pac::RCC.apb4enr().modify(|w| w.set_syscfgen(true));
84 crate::pac::RCC.ahb1enr().modify(|w| { 83 crate::pac::RCC.ahb1enr().modify(|w| {
85 w.set_eth1macen(true); 84 w.set_eth1macen(true);
86 w.set_eth1txen(true); 85 w.set_eth1txen(true);
diff --git a/embassy-stm32/src/exti.rs b/embassy-stm32/src/exti.rs
index efa51fb24..62f321709 100644
--- a/embassy-stm32/src/exti.rs
+++ b/embassy-stm32/src/exti.rs
@@ -371,9 +371,4 @@ pub(crate) unsafe fn init() {
371 use crate::interrupt::typelevel::Interrupt; 371 use crate::interrupt::typelevel::Interrupt;
372 372
373 foreach_exti_irq!(enable_irq); 373 foreach_exti_irq!(enable_irq);
374
375 #[cfg(not(any(rcc_wb, rcc_wl5, rcc_wle, stm32f1, exti_h5, exti_h50)))]
376 <crate::peripherals::SYSCFG as crate::rcc::sealed::RccPeripheral>::enable();
377 #[cfg(stm32f1)]
378 <crate::peripherals::AFIO as crate::rcc::sealed::RccPeripheral>::enable();
379} 374}
diff --git a/embassy-stm32/src/gpio.rs b/embassy-stm32/src/gpio.rs
index a382cb742..c709d46da 100644
--- a/embassy-stm32/src/gpio.rs
+++ b/embassy-stm32/src/gpio.rs
@@ -758,6 +758,9 @@ foreach_pin!(
758); 758);
759 759
760pub(crate) unsafe fn init() { 760pub(crate) unsafe fn init() {
761 #[cfg(afio)]
762 <crate::peripherals::AFIO as crate::rcc::sealed::RccPeripheral>::enable();
763
761 crate::_generated::init_gpio(); 764 crate::_generated::init_gpio();
762} 765}
763 766
diff --git a/embassy-stm32/src/lib.rs b/embassy-stm32/src/lib.rs
index 6a53f8762..9231aa0f2 100644
--- a/embassy-stm32/src/lib.rs
+++ b/embassy-stm32/src/lib.rs
@@ -117,6 +117,7 @@ pub(crate) use stm32_metapac as pac;
117use crate::interrupt::Priority; 117use crate::interrupt::Priority;
118#[cfg(feature = "rt")] 118#[cfg(feature = "rt")]
119pub use crate::pac::NVIC_PRIO_BITS; 119pub use crate::pac::NVIC_PRIO_BITS;
120use crate::rcc::sealed::RccPeripheral;
120 121
121#[non_exhaustive] 122#[non_exhaustive]
122pub struct Config { 123pub struct Config {
@@ -179,6 +180,15 @@ pub fn init(config: Config) -> Peripherals {
179 }); 180 });
180 } 181 }
181 182
183 #[cfg(not(any(stm32f1, stm32h5, stm32wb, stm32wl)))]
184 peripherals::SYSCFG::enable();
185 #[cfg(sbs)]
186 peripherals::SBS::enable();
187 #[cfg(not(any(stm32h5, stm32h7, stm32wb, stm32wl)))]
188 peripherals::PWR::enable();
189 #[cfg(not(any(stm32f2, stm32f4, stm32f7, stm32l0, stm32h5, stm32h7)))]
190 peripherals::FLASH::enable();
191
182 unsafe { 192 unsafe {
183 gpio::init(); 193 gpio::init();
184 dma::init( 194 dma::init(
diff --git a/embassy-stm32/src/rcc/f2.rs b/embassy-stm32/src/rcc/f2.rs
index 1a34c2cbe..44de5bf19 100644
--- a/embassy-stm32/src/rcc/f2.rs
+++ b/embassy-stm32/src/rcc/f2.rs
@@ -4,7 +4,7 @@ use core::ops::{Div, Mul};
4pub use super::bus::{AHBPrescaler, APBPrescaler}; 4pub use super::bus::{AHBPrescaler, APBPrescaler};
5use crate::pac::flash::vals::Latency; 5use crate::pac::flash::vals::Latency;
6use crate::pac::rcc::vals::{Pllp, Pllsrc, Sw}; 6use crate::pac::rcc::vals::{Pllp, Pllsrc, Sw};
7use crate::pac::{FLASH, PWR, RCC}; 7use crate::pac::{FLASH, RCC};
8use crate::rcc::bd::BackupDomain; 8use crate::rcc::bd::BackupDomain;
9use crate::rcc::{set_freqs, Clocks}; 9use crate::rcc::{set_freqs, Clocks};
10use crate::rtc::RtcClockSource; 10use crate::rtc::RtcClockSource;
@@ -435,9 +435,6 @@ pub(crate) unsafe fn init(config: Config) {
435 RCC.cr().modify(|w| w.set_hsion(false)); 435 RCC.cr().modify(|w| w.set_hsion(false));
436 } 436 }
437 437
438 RCC.apb1enr().modify(|w| w.set_pwren(true));
439 PWR.cr().read();
440
441 BackupDomain::configure_ls( 438 BackupDomain::configure_ls(
442 config.rtc.unwrap_or(RtcClockSource::NOCLOCK), 439 config.rtc.unwrap_or(RtcClockSource::NOCLOCK),
443 config.lsi, 440 config.lsi,
diff --git a/embassy-stm32/src/rcc/f4.rs b/embassy-stm32/src/rcc/f4.rs
index d8d0312bc..5914c926a 100644
--- a/embassy-stm32/src/rcc/f4.rs
+++ b/embassy-stm32/src/rcc/f4.rs
@@ -3,7 +3,6 @@ use core::marker::PhantomData;
3use embassy_hal_internal::into_ref; 3use embassy_hal_internal::into_ref;
4use stm32_metapac::rcc::vals::{Mco1, Mco2, Mcopre}; 4use stm32_metapac::rcc::vals::{Mco1, Mco2, Mcopre};
5 5
6use super::sealed::RccPeripheral;
7use crate::gpio::sealed::AFType; 6use crate::gpio::sealed::AFType;
8use crate::gpio::Speed; 7use crate::gpio::Speed;
9use crate::pac::rcc::vals::{Hpre, Ppre, Sw}; 8use crate::pac::rcc::vals::{Hpre, Ppre, Sw};
@@ -332,8 +331,6 @@ fn flash_setup(sysclk: u32) {
332} 331}
333 332
334pub(crate) unsafe fn init(config: Config) { 333pub(crate) unsafe fn init(config: Config) {
335 crate::peripherals::PWR::enable();
336
337 let pllsrcclk = config.hse.map(|hse| hse.0).unwrap_or(HSI_FREQ.0); 334 let pllsrcclk = config.hse.map(|hse| hse.0).unwrap_or(HSI_FREQ.0);
338 let sysclk = config.sys_ck.map(|sys| sys.0).unwrap_or(pllsrcclk); 335 let sysclk = config.sys_ck.map(|sys| sys.0).unwrap_or(pllsrcclk);
339 let sysclk_on_pll = sysclk != pllsrcclk; 336 let sysclk_on_pll = sysclk != pllsrcclk;
diff --git a/embassy-stm32/src/rcc/f7.rs b/embassy-stm32/src/rcc/f7.rs
index 85cb9c661..234511b00 100644
--- a/embassy-stm32/src/rcc/f7.rs
+++ b/embassy-stm32/src/rcc/f7.rs
@@ -1,4 +1,3 @@
1use super::sealed::RccPeripheral;
2use crate::pac::pwr::vals::Vos; 1use crate::pac::pwr::vals::Vos;
3use crate::pac::rcc::vals::{Hpre, Ppre, Sw}; 2use crate::pac::rcc::vals::{Hpre, Ppre, Sw};
4use crate::pac::{FLASH, PWR, RCC}; 3use crate::pac::{FLASH, PWR, RCC};
@@ -111,8 +110,6 @@ fn flash_setup(sysclk: u32) {
111} 110}
112 111
113pub(crate) unsafe fn init(config: Config) { 112pub(crate) unsafe fn init(config: Config) {
114 crate::peripherals::PWR::enable();
115
116 if let Some(hse) = config.hse { 113 if let Some(hse) = config.hse {
117 if config.bypass_hse { 114 if config.bypass_hse {
118 assert!((max::HSE_BYPASS_MIN..=max::HSE_BYPASS_MAX).contains(&hse.0)); 115 assert!((max::HSE_BYPASS_MIN..=max::HSE_BYPASS_MAX).contains(&hse.0));
@@ -212,10 +209,7 @@ pub(crate) unsafe fn init(config: Config) {
212 if plls.use_pll { 209 if plls.use_pll {
213 RCC.cr().modify(|w| w.set_pllon(false)); 210 RCC.cr().modify(|w| w.set_pllon(false));
214 211
215 // enable PWR and setup VOSScale 212 // setup VOSScale
216
217 RCC.apb1enr().modify(|w| w.set_pwren(true));
218
219 let vos_scale = if sysclk <= 144_000_000 { 213 let vos_scale = if sysclk <= 144_000_000 {
220 3 214 3
221 } else if sysclk <= 168_000_000 { 215 } else if sysclk <= 168_000_000 {
diff --git a/embassy-stm32/src/rcc/h.rs b/embassy-stm32/src/rcc/h.rs
index a4730ed49..43e8db22e 100644
--- a/embassy-stm32/src/rcc/h.rs
+++ b/embassy-stm32/src/rcc/h.rs
@@ -215,11 +215,6 @@ impl Default for Config {
215} 215}
216 216
217pub(crate) unsafe fn init(config: Config) { 217pub(crate) unsafe fn init(config: Config) {
218 #[cfg(stm32h7)]
219 RCC.apb4enr().modify(|w| w.set_syscfgen(true));
220 #[cfg(stm32h5)]
221 RCC.apb3enr().modify(|w| w.set_sbsen(true));
222
223 // NB. The lower bytes of CR3 can only be written once after 218 // NB. The lower bytes of CR3 can only be written once after
224 // POR, and must be written with a valid combination. Refer to 219 // POR, and must be written with a valid combination. Refer to
225 // RM0433 Rev 7 6.8.4. This is partially enforced by dropping 220 // RM0433 Rev 7 6.8.4. This is partially enforced by dropping
diff --git a/embassy-stm32/src/rcc/l0.rs b/embassy-stm32/src/rcc/l0.rs
index 1c655592e..67355afbe 100644
--- a/embassy-stm32/src/rcc/l0.rs
+++ b/embassy-stm32/src/rcc/l0.rs
@@ -283,13 +283,6 @@ pub(crate) unsafe fn init(config: Config) {
283 283
284 #[cfg(crs)] 284 #[cfg(crs)]
285 if config.enable_hsi48 { 285 if config.enable_hsi48 {
286 // Reset SYSCFG peripheral
287 RCC.apb2rstr().modify(|w| w.set_syscfgrst(true));
288 RCC.apb2rstr().modify(|w| w.set_syscfgrst(false));
289
290 // Enable SYSCFG peripheral
291 RCC.apb2enr().modify(|w| w.set_syscfgen(true));
292
293 // Reset CRS peripheral 286 // Reset CRS peripheral
294 RCC.apb1rstr().modify(|w| w.set_crsrst(true)); 287 RCC.apb1rstr().modify(|w| w.set_crsrst(true));
295 RCC.apb1rstr().modify(|w| w.set_crsrst(false)); 288 RCC.apb1rstr().modify(|w| w.set_crsrst(false));
diff --git a/embassy-stm32/src/rcc/l4.rs b/embassy-stm32/src/rcc/l4.rs
index f7b9354a6..6f1f7458c 100644
--- a/embassy-stm32/src/rcc/l4.rs
+++ b/embassy-stm32/src/rcc/l4.rs
@@ -409,8 +409,6 @@ pub(crate) unsafe fn init(config: Config) {
409 while RCC.cfgr().read().sws() != Sw::MSI {} 409 while RCC.cfgr().read().sws() != Sw::MSI {}
410 } 410 }
411 411
412 RCC.apb1enr1().modify(|w| w.set_pwren(true));
413
414 BackupDomain::configure_ls(config.rtc_mux, config.lsi, config.lse.map(|_| Default::default())); 412 BackupDomain::configure_ls(config.rtc_mux, config.lsi, config.lse.map(|_| Default::default()));
415 413
416 let (sys_clk, sw) = match config.mux { 414 let (sys_clk, sw) = match config.mux {
@@ -608,8 +606,6 @@ pub(crate) unsafe fn init(config: Config) {
608 } 606 }
609 }; 607 };
610 608
611 RCC.apb1enr1().modify(|w| w.set_pwren(true));
612
613 set_freqs(Clocks { 609 set_freqs(Clocks {
614 sys: Hertz(sys_clk), 610 sys: Hertz(sys_clk),
615 ahb1: Hertz(ahb_freq), 611 ahb1: Hertz(ahb_freq),
diff --git a/embassy-stm32/src/rtc/v2.rs b/embassy-stm32/src/rtc/v2.rs
index 05b85ef46..ab562d2b6 100644
--- a/embassy-stm32/src/rtc/v2.rs
+++ b/embassy-stm32/src/rtc/v2.rs
@@ -295,20 +295,6 @@ impl sealed::Instance for crate::peripherals::RTC {
295 // read to allow the pwr clock to enable 295 // read to allow the pwr clock to enable
296 crate::pac::PWR.cr1().read(); 296 crate::pac::PWR.cr1().read();
297 } 297 }
298 #[cfg(any(rtc_v2f2))]
299 {
300 // enable peripheral clock for communication
301 crate::pac::RCC.apb1enr().modify(|w| w.set_pwren(true));
302
303 // read to allow the pwr clock to enable
304 crate::pac::PWR.cr().read();
305 }
306
307 #[cfg(any(rtc_v2f0, rtc_v2l0))]
308 {
309 // enable peripheral clock for communication
310 crate::pac::RCC.apb1enr().modify(|w| w.set_pwren(true));
311 }
312 } 298 }
313 299
314 fn read_backup_register(rtc: &Rtc, register: usize) -> Option<u32> { 300 fn read_backup_register(rtc: &Rtc, register: usize) -> Option<u32> {
diff --git a/embassy-stm32/src/usb/usb.rs b/embassy-stm32/src/usb/usb.rs
index cef196355..b24fc74eb 100644
--- a/embassy-stm32/src/usb/usb.rs
+++ b/embassy-stm32/src/usb/usb.rs
@@ -264,10 +264,7 @@ impl<'d, T: Instance> Driver<'d, T> {
264 let regs = T::regs(); 264 let regs = T::regs();
265 265
266 #[cfg(stm32l5)] 266 #[cfg(stm32l5)]
267 { 267 crate::pac::PWR.cr2().modify(|w| w.set_usv(true));
268 crate::peripherals::PWR::enable();
269 crate::pac::PWR.cr2().modify(|w| w.set_usv(true));
270 }
271 268
272 #[cfg(pwr_h5)] 269 #[cfg(pwr_h5)]
273 crate::pac::PWR.usbscr().modify(|w| w.set_usb33sv(true)); 270 crate::pac::PWR.usbscr().modify(|w| w.set_usb33sv(true));
diff --git a/embassy-stm32/src/usb_otg/usb.rs b/embassy-stm32/src/usb_otg/usb.rs
index 348f0f79d..1fe010bbb 100644
--- a/embassy-stm32/src/usb_otg/usb.rs
+++ b/embassy-stm32/src/usb_otg/usb.rs
@@ -540,10 +540,7 @@ impl<'d, T: Instance> Bus<'d, T> {
540impl<'d, T: Instance> Bus<'d, T> { 540impl<'d, T: Instance> Bus<'d, T> {
541 fn init(&mut self) { 541 fn init(&mut self) {
542 #[cfg(stm32l4)] 542 #[cfg(stm32l4)]
543 { 543 critical_section::with(|_| crate::pac::PWR.cr2().modify(|w| w.set_usv(true)));
544 crate::peripherals::PWR::enable();
545 critical_section::with(|_| crate::pac::PWR.cr2().modify(|w| w.set_usv(true)));
546 }
547 544
548 #[cfg(stm32f7)] 545 #[cfg(stm32f7)]
549 { 546 {
@@ -618,15 +615,10 @@ impl<'d, T: Instance> Bus<'d, T> {
618 { 615 {
619 // Enable USB power 616 // Enable USB power
620 critical_section::with(|_| { 617 critical_section::with(|_| {
621 crate::pac::RCC.ahb3enr().modify(|w| {
622 w.set_pwren(true);
623 });
624 cortex_m::asm::delay(2);
625
626 crate::pac::PWR.svmcr().modify(|w| { 618 crate::pac::PWR.svmcr().modify(|w| {
627 w.set_usv(true); 619 w.set_usv(true);
628 w.set_uvmen(true); 620 w.set_uvmen(true);
629 }); 621 })
630 }); 622 });
631 623
632 // Wait for USB power to stabilize 624 // Wait for USB power to stabilize