Merge pull request #3002 from honzasp/rcc-info

stm32/rcc: replace generated enable/disable code with runtime info
This commit is contained in:
Dario Nieuwenhuis 2024-05-30 11:50:40 +00:00 committed by GitHub
commit 39c5a6c3f7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
45 changed files with 379 additions and 305 deletions

View File

@ -367,9 +367,6 @@ fn main() {
.filter_map(|p| p.registers.as_ref()) .filter_map(|p| p.registers.as_ref())
.find(|r| r.kind == "rcc") .find(|r| r.kind == "rcc")
.unwrap(); .unwrap();
for b in rcc_registers.ir.blocks {
eprintln!("{}", b.name);
}
let rcc_block = rcc_registers.ir.blocks.iter().find(|b| b.name == "Rcc").unwrap(); let rcc_block = rcc_registers.ir.blocks.iter().find(|b| b.name == "Rcc").unwrap();
// ======== // ========
@ -388,7 +385,6 @@ fn main() {
rcc_registers: &'a PeripheralRegisters, rcc_registers: &'a PeripheralRegisters,
chained_muxes: HashMap<&'a str, &'a PeripheralRccRegister>, chained_muxes: HashMap<&'a str, &'a PeripheralRccRegister>,
refcount_statics: BTreeSet<Ident>,
clock_names: BTreeSet<String>, clock_names: BTreeSet<String>,
muxes: BTreeSet<(Ident, Ident, Ident)>, muxes: BTreeSet<(Ident, Ident, Ident)>,
} }
@ -397,7 +393,6 @@ fn main() {
rcc_registers, rcc_registers,
chained_muxes: HashMap::new(), chained_muxes: HashMap::new(),
refcount_statics: BTreeSet::new(),
clock_names: BTreeSet::new(), clock_names: BTreeSet::new(),
muxes: BTreeSet::new(), muxes: BTreeSet::new(),
}; };
@ -516,80 +511,64 @@ fn main() {
} }
} }
let mut refcount_idxs = HashMap::new();
for p in METADATA.peripherals { for p in METADATA.peripherals {
if !singletons.contains(&p.name.to_string()) { if !singletons.contains(&p.name.to_string()) {
continue; continue;
} }
if let Some(rcc) = &p.rcc { if let Some(rcc) = &p.rcc {
let en = rcc.enable.as_ref().unwrap(); let rst_reg = rcc.reset.as_ref();
let en_reg = rcc.enable.as_ref().unwrap();
let (start_rst, end_rst) = match &rcc.reset {
Some(rst) => {
let rst_reg = format_ident!("{}", rst.register.to_ascii_lowercase());
let set_rst_field = format_ident!("set_{}", rst.field.to_ascii_lowercase());
(
quote! {
crate::pac::RCC.#rst_reg().modify(|w| w.#set_rst_field(true));
},
quote! {
crate::pac::RCC.#rst_reg().modify(|w| w.#set_rst_field(false));
},
)
}
None => (TokenStream::new(), TokenStream::new()),
};
let pname = format_ident!("{}", p.name); let pname = format_ident!("{}", p.name);
let en_reg = format_ident!("{}", en.register.to_ascii_lowercase());
let set_en_field = format_ident!("set_{}", en.field.to_ascii_lowercase());
let en_reg_offs = rcc_block
.items
.iter()
.find(|i| i.name.eq_ignore_ascii_case(en.register))
.unwrap()
.byte_offset;
let en_reg_offs: u8 = (en_reg_offs / 4).try_into().unwrap();
let en_bit_offs = &rcc_registers let get_offset_and_bit = |reg: &PeripheralRccRegister| -> TokenStream {
.ir let reg_offset = rcc_block
.fieldsets .items
.iter() .iter()
.find(|i| i.name.eq_ignore_ascii_case(en.register)) .find(|i| i.name.eq_ignore_ascii_case(reg.register))
.unwrap() .unwrap()
.fields .byte_offset;
.iter() let reg_offset: u8 = (reg_offset / 4).try_into().unwrap();
.find(|i| i.name.eq_ignore_ascii_case(en.field))
.unwrap() let bit_offset = &rcc_registers
.bit_offset; .ir
let BitOffset::Regular(en_bit_offs) = en_bit_offs else { .fieldsets
panic!("cursed bit offset") .iter()
.find(|i| i.name.eq_ignore_ascii_case(reg.register))
.unwrap()
.fields
.iter()
.find(|i| i.name.eq_ignore_ascii_case(reg.field))
.unwrap()
.bit_offset;
let BitOffset::Regular(bit_offset) = bit_offset else {
panic!("cursed bit offset")
};
let bit_offset: u8 = bit_offset.offset.try_into().unwrap();
quote! { (#reg_offset, #bit_offset) }
}; };
let en_bit_offs: u8 = en_bit_offs.offset.try_into().unwrap();
let refcount = *rcc_field_count.get(&(en.register, en.field)).unwrap() > 1; let reset_offset_and_bit = match rst_reg {
let (before_enable, before_disable) = if refcount { Some(rst_reg) => {
let refcount_static = let reset_offset_and_bit = get_offset_and_bit(rst_reg);
format_ident!("{}_{}", en.register.to_ascii_uppercase(), en.field.to_ascii_uppercase()); quote! { Some(#reset_offset_and_bit) }
}
None => quote! { None },
};
let enable_offset_and_bit = get_offset_and_bit(en_reg);
clock_gen.refcount_statics.insert(refcount_static.clone()); let needs_refcount = *rcc_field_count.get(&(en_reg.register, en_reg.field)).unwrap() > 1;
let refcount_idx = if needs_refcount {
( let next_refcount_idx = refcount_idxs.len() as u8;
quote! { let refcount_idx = *refcount_idxs
unsafe { refcount_statics::#refcount_static += 1 }; .entry((en_reg.register, en_reg.field))
if unsafe { refcount_statics::#refcount_static } > 1 { .or_insert(next_refcount_idx);
return; quote! { Some(#refcount_idx) }
}
},
quote! {
unsafe { refcount_statics::#refcount_static -= 1 };
if unsafe { refcount_statics::#refcount_static } > 0 {
return;
}
},
)
} else { } else {
(TokenStream::new(), TokenStream::new()) quote! { None }
}; };
let clock_frequency = match &rcc.kernel_clock { let clock_frequency = match &rcc.kernel_clock {
@ -599,24 +578,10 @@ fn main() {
// A refcount leak can result if the same field is shared by peripherals with different stop modes // A refcount leak can result if the same field is shared by peripherals with different stop modes
// This condition should be checked in stm32-data // This condition should be checked in stm32-data
let stop_refcount = match rcc.stop_mode { let stop_mode = match rcc.stop_mode {
StopMode::Standby => None, StopMode::Standby => quote! { crate::rcc::StopMode::Standby },
StopMode::Stop2 => Some(quote! { REFCOUNT_STOP2 }), StopMode::Stop2 => quote! { crate::rcc::StopMode::Stop2 },
StopMode::Stop1 => Some(quote! { REFCOUNT_STOP1 }), StopMode::Stop1 => quote! { crate::rcc::StopMode::Stop1 },
};
let (incr_stop_refcount, decr_stop_refcount) = match stop_refcount {
Some(stop_refcount) => (
quote! {
#[cfg(feature = "low-power")]
unsafe { crate::rcc::#stop_refcount += 1 };
},
quote! {
#[cfg(feature = "low-power")]
unsafe { crate::rcc::#stop_refcount -= 1 };
},
),
None => (TokenStream::new(), TokenStream::new()),
}; };
g.extend(quote! { g.extend(quote! {
@ -624,34 +589,16 @@ fn main() {
fn frequency() -> crate::time::Hertz { fn frequency() -> crate::time::Hertz {
#clock_frequency #clock_frequency
} }
fn enable_and_reset_with_cs(_cs: critical_section::CriticalSection) {
#before_enable
#incr_stop_refcount
#start_rst const RCC_INFO: crate::rcc::RccInfo = unsafe {
crate::rcc::RccInfo::new(
crate::pac::RCC.#en_reg().modify(|w| w.#set_en_field(true)); #reset_offset_and_bit,
#enable_offset_and_bit,
// we must wait two peripheral clock cycles before the clock is active #refcount_idx,
// this seems to work, but might be incorrect #[cfg(feature = "low-power")]
// see http://efton.sk/STM32/gotcha/g183.html #stop_mode,
)
// dummy read (like in the ST HALs) };
let _ = crate::pac::RCC.#en_reg().read();
// DSB for good measure
cortex_m::asm::dsb();
#end_rst
}
fn disable_with_cs(_cs: critical_section::CriticalSection) {
#before_disable
crate::pac::RCC.#en_reg().modify(|w| w.#set_en_field(false));
#decr_stop_refcount
}
const ENABLE_BIT: crate::rcc::ClockEnableBit =
unsafe { crate::rcc::ClockEnableBit::new(#en_reg_offs, #en_bit_offs) };
} }
impl crate::rcc::RccPeripheral for peripherals::#pname {} impl crate::rcc::RccPeripheral for peripherals::#pname {}
@ -659,6 +606,14 @@ fn main() {
} }
} }
g.extend({
let refcounts_len = refcount_idxs.len();
let refcount_zeros: TokenStream = refcount_idxs.iter().map(|_| quote! { 0u8, }).collect();
quote! {
pub(crate) static mut REFCOUNTS: [u8; #refcounts_len] = [#refcount_zeros];
}
});
let struct_fields: Vec<_> = clock_gen let struct_fields: Vec<_> = clock_gen
.muxes .muxes
.iter() .iter()
@ -762,22 +717,6 @@ fn main() {
} }
); );
let refcount_mod: TokenStream = clock_gen
.refcount_statics
.iter()
.map(|refcount_static| {
quote! {
pub(crate) static mut #refcount_static: u8 = 0;
}
})
.collect();
g.extend(quote! {
mod refcount_statics {
#refcount_mod
}
});
// ======== // ========
// Generate fns to enable GPIO, DMA in RCC // Generate fns to enable GPIO, DMA in RCC

View File

@ -7,7 +7,7 @@ use embassy_hal_internal::into_ref;
use super::blocking_delay_us; use super::blocking_delay_us;
use crate::adc::{Adc, AdcChannel, Instance, SampleTime}; use crate::adc::{Adc, AdcChannel, Instance, SampleTime};
use crate::time::Hertz; use crate::time::Hertz;
use crate::{interrupt, Peripheral}; use crate::{interrupt, rcc, Peripheral};
pub const VDDA_CALIB_MV: u32 = 3300; pub const VDDA_CALIB_MV: u32 = 3300;
pub const ADC_MAX: u32 = (1 << 12) - 1; pub const ADC_MAX: u32 = (1 << 12) - 1;
@ -50,7 +50,7 @@ impl<T: Instance> super::SealedAdcChannel<T> for Temperature {
impl<'d, T: Instance> Adc<'d, T> { impl<'d, T: Instance> Adc<'d, T> {
pub fn new(adc: impl Peripheral<P = T> + 'd) -> Self { pub fn new(adc: impl Peripheral<P = T> + 'd) -> Self {
into_ref!(adc); into_ref!(adc);
T::enable_and_reset(); rcc::enable_and_reset::<T>();
T::regs().cr2().modify(|reg| reg.set_adon(true)); T::regs().cr2().modify(|reg| reg.set_adon(true));
// 11.4: Before starting a calibration, the ADC must have been in power-on state (ADON bit = 1) // 11.4: Before starting a calibration, the ADC must have been in power-on state (ADON bit = 1)
@ -169,6 +169,6 @@ impl<'d, T: Instance> Drop for Adc<'d, T> {
fn drop(&mut self) { fn drop(&mut self) {
T::regs().cr2().modify(|reg| reg.set_adon(false)); T::regs().cr2().modify(|reg| reg.set_adon(false));
T::disable(); rcc::disable::<T>();
} }
} }

View File

@ -8,7 +8,7 @@ use super::blocking_delay_us;
use crate::adc::{Adc, AdcChannel, Instance, SampleTime}; use crate::adc::{Adc, AdcChannel, Instance, SampleTime};
use crate::interrupt::typelevel::Interrupt; use crate::interrupt::typelevel::Interrupt;
use crate::time::Hertz; use crate::time::Hertz;
use crate::{interrupt, Peripheral}; use crate::{interrupt, rcc, Peripheral};
pub const VDDA_CALIB_MV: u32 = 3300; pub const VDDA_CALIB_MV: u32 = 3300;
pub const ADC_MAX: u32 = (1 << 12) - 1; pub const ADC_MAX: u32 = (1 << 12) - 1;
@ -63,7 +63,7 @@ impl<'d, T: Instance> Adc<'d, T> {
into_ref!(adc); into_ref!(adc);
T::enable_and_reset(); rcc::enable_and_reset::<T>();
// Enable the adc regulator // Enable the adc regulator
T::regs().cr().modify(|w| w.set_advregen(vals::Advregen::INTERMEDIATE)); T::regs().cr().modify(|w| w.set_advregen(vals::Advregen::INTERMEDIATE));
@ -188,6 +188,6 @@ impl<'d, T: Instance> Drop for Adc<'d, T> {
T::regs().cr().modify(|w| w.set_advregen(vals::Advregen::INTERMEDIATE)); T::regs().cr().modify(|w| w.set_advregen(vals::Advregen::INTERMEDIATE));
T::regs().cr().modify(|w| w.set_advregen(vals::Advregen::DISABLED)); T::regs().cr().modify(|w| w.set_advregen(vals::Advregen::DISABLED));
T::disable(); rcc::disable::<T>();
} }
} }

View File

@ -10,7 +10,7 @@ use super::Resolution;
use crate::adc::{Adc, AdcChannel, Instance, SampleTime}; use crate::adc::{Adc, AdcChannel, Instance, SampleTime};
use crate::interrupt::typelevel::Interrupt; use crate::interrupt::typelevel::Interrupt;
use crate::time::Hertz; use crate::time::Hertz;
use crate::{interrupt, Peripheral}; use crate::{interrupt, rcc, Peripheral};
const ADC_FREQ: Hertz = crate::rcc::HSI_FREQ; const ADC_FREQ: Hertz = crate::rcc::HSI_FREQ;
@ -143,7 +143,7 @@ impl<'d, T: Instance> Adc<'d, T> {
) -> Self { ) -> Self {
into_ref!(adc); into_ref!(adc);
T::enable_and_reset(); rcc::enable_and_reset::<T>();
//let r = T::regs(); //let r = T::regs();
//r.cr2().write(|w| w.set_align(true)); //r.cr2().write(|w| w.set_align(true));
@ -403,6 +403,6 @@ impl<'d, T: Instance> Drop for Adc<'d, T> {
T::regs().cr2().modify(|w| w.set_adon(false)); T::regs().cr2().modify(|w| w.set_adon(false));
T::disable(); rcc::disable::<T>();
} }
} }

View File

@ -4,7 +4,7 @@ use pac::adccommon::vals::Presc;
use super::{blocking_delay_us, Adc, AdcChannel, Instance, Resolution, SampleTime}; use super::{blocking_delay_us, Adc, AdcChannel, Instance, Resolution, SampleTime};
use crate::time::Hertz; use crate::time::Hertz;
use crate::{pac, Peripheral}; use crate::{pac, rcc, Peripheral};
/// Default VREF voltage used for sample conversion to millivolts. /// Default VREF voltage used for sample conversion to millivolts.
pub const VREF_DEFAULT_MV: u32 = 3300; pub const VREF_DEFAULT_MV: u32 = 3300;
@ -130,7 +130,7 @@ impl<'d, T: Instance> Adc<'d, T> {
/// Create a new ADC driver. /// Create a new ADC driver.
pub fn new(adc: impl Peripheral<P = T> + 'd) -> Self { pub fn new(adc: impl Peripheral<P = T> + 'd) -> Self {
embassy_hal_internal::into_ref!(adc); embassy_hal_internal::into_ref!(adc);
T::enable_and_reset(); rcc::enable_and_reset::<T>();
let prescaler = Prescaler::from_ker_ck(T::frequency()); let prescaler = Prescaler::from_ker_ck(T::frequency());

View File

@ -10,7 +10,7 @@ use super::blocking_delay_us;
use crate::adc::{Adc, AdcChannel, Instance, Resolution, SampleTime}; use crate::adc::{Adc, AdcChannel, Instance, Resolution, SampleTime};
use crate::interrupt::typelevel::Interrupt; use crate::interrupt::typelevel::Interrupt;
use crate::peripherals::ADC1; use crate::peripherals::ADC1;
use crate::{interrupt, Peripheral}; use crate::{interrupt, rcc, Peripheral};
pub const VDDA_CALIB_MV: u32 = 3300; pub const VDDA_CALIB_MV: u32 = 3300;
pub const VREF_INT: u32 = 1230; pub const VREF_INT: u32 = 1230;
@ -67,7 +67,7 @@ impl<'d, T: Instance> Adc<'d, T> {
_irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd,
) -> Self { ) -> Self {
into_ref!(adc); into_ref!(adc);
T::enable_and_reset(); rcc::enable_and_reset::<T>();
// Delay 1μs when using HSI14 as the ADC clock. // Delay 1μs when using HSI14 as the ADC clock.
// //
@ -199,6 +199,6 @@ impl<'d, T: Instance> Drop for Adc<'d, T> {
T::regs().cr().modify(|reg| reg.set_addis(true)); T::regs().cr().modify(|reg| reg.set_addis(true));
while T::regs().cr().read().aden() {} while T::regs().cr().read().aden() {}
T::disable(); rcc::disable::<T>();
} }
} }

View File

@ -4,7 +4,7 @@ use super::blocking_delay_us;
use crate::adc::{Adc, AdcChannel, Instance, Resolution, SampleTime}; use crate::adc::{Adc, AdcChannel, Instance, Resolution, SampleTime};
use crate::peripherals::ADC1; use crate::peripherals::ADC1;
use crate::time::Hertz; use crate::time::Hertz;
use crate::Peripheral; use crate::{rcc, Peripheral};
/// Default VREF voltage used for sample conversion to millivolts. /// Default VREF voltage used for sample conversion to millivolts.
pub const VREF_DEFAULT_MV: u32 = 3300; pub const VREF_DEFAULT_MV: u32 = 3300;
@ -96,7 +96,7 @@ where
{ {
pub fn new(adc: impl Peripheral<P = T> + 'd) -> Self { pub fn new(adc: impl Peripheral<P = T> + 'd) -> Self {
into_ref!(adc); into_ref!(adc);
T::enable_and_reset(); rcc::enable_and_reset::<T>();
let presc = Prescaler::from_pclk2(T::frequency()); let presc = Prescaler::from_pclk2(T::frequency());
T::common_regs().ccr().modify(|w| w.set_adcpre(presc.adcpre())); T::common_regs().ccr().modify(|w| w.set_adcpre(presc.adcpre()));
@ -206,6 +206,6 @@ impl<'d, T: Instance> Drop for Adc<'d, T> {
reg.set_adon(false); reg.set_adon(false);
}); });
T::disable(); rcc::disable::<T>();
} }
} }

View File

@ -3,7 +3,7 @@ use embassy_hal_internal::into_ref;
use super::blocking_delay_us; use super::blocking_delay_us;
use crate::adc::{Adc, AdcChannel, Instance, Resolution, SampleTime}; use crate::adc::{Adc, AdcChannel, Instance, Resolution, SampleTime};
use crate::Peripheral; use crate::{rcc, Peripheral};
/// Default VREF voltage used for sample conversion to millivolts. /// Default VREF voltage used for sample conversion to millivolts.
pub const VREF_DEFAULT_MV: u32 = 3300; pub const VREF_DEFAULT_MV: u32 = 3300;
@ -94,7 +94,7 @@ cfg_if! {
impl<'d, T: Instance> Adc<'d, T> { impl<'d, T: Instance> Adc<'d, T> {
pub fn new(adc: impl Peripheral<P = T> + 'd) -> Self { pub fn new(adc: impl Peripheral<P = T> + 'd) -> Self {
into_ref!(adc); into_ref!(adc);
T::enable_and_reset(); rcc::enable_and_reset::<T>();
T::regs().cr().modify(|reg| { T::regs().cr().modify(|reg| {
#[cfg(not(any(adc_g0, adc_u0)))] #[cfg(not(any(adc_g0, adc_u0)))]
reg.set_deeppwd(false); reg.set_deeppwd(false);

View File

@ -4,7 +4,7 @@ use pac::adccommon::vals::Presc;
use super::{blocking_delay_us, Adc, AdcChannel, Instance, Resolution, SampleTime}; use super::{blocking_delay_us, Adc, AdcChannel, Instance, Resolution, SampleTime};
use crate::time::Hertz; use crate::time::Hertz;
use crate::{pac, Peripheral}; use crate::{pac, rcc, Peripheral};
/// Default VREF voltage used for sample conversion to millivolts. /// Default VREF voltage used for sample conversion to millivolts.
pub const VREF_DEFAULT_MV: u32 = 3300; pub const VREF_DEFAULT_MV: u32 = 3300;
@ -130,7 +130,7 @@ impl<'d, T: Instance> Adc<'d, T> {
/// Create a new ADC driver. /// Create a new ADC driver.
pub fn new(adc: impl Peripheral<P = T> + 'd) -> Self { pub fn new(adc: impl Peripheral<P = T> + 'd) -> Self {
embassy_hal_internal::into_ref!(adc); embassy_hal_internal::into_ref!(adc);
T::enable_and_reset(); rcc::enable_and_reset::<T>();
let prescaler = Prescaler::from_ker_ck(T::frequency()); let prescaler = Prescaler::from_ker_ck(T::frequency());

View File

@ -19,7 +19,7 @@ use super::util;
use crate::can::enums::{BusError, TryReadError}; use crate::can::enums::{BusError, TryReadError};
use crate::gpio::AFType; use crate::gpio::AFType;
use crate::interrupt::typelevel::Interrupt; use crate::interrupt::typelevel::Interrupt;
use crate::rcc::RccPeripheral; use crate::rcc::{self, RccPeripheral};
use crate::{interrupt, peripherals, Peripheral}; use crate::{interrupt, peripherals, Peripheral};
/// Interrupt handler. /// Interrupt handler.
@ -183,7 +183,7 @@ impl<'d, T: Instance> Can<'d, T> {
rx.set_as_af(rx.af_num(), AFType::Input); rx.set_as_af(rx.af_num(), AFType::Input);
tx.set_as_af(tx.af_num(), AFType::OutputPushPull); tx.set_as_af(tx.af_num(), AFType::OutputPushPull);
T::enable_and_reset(); rcc::enable_and_reset::<T>();
{ {
T::regs().ier().write(|w| { T::regs().ier().write(|w| {
@ -759,7 +759,7 @@ impl<'d, T: Instance> Drop for Can<'d, T> {
// Cannot call `free()` because it moves the instance. // Cannot call `free()` because it moves the instance.
// Manually reset the peripheral. // Manually reset the peripheral.
T::regs().mcr().write(|w| w.set_reset(true)); T::regs().mcr().write(|w| w.set_reset(true));
T::disable(); rcc::disable::<T>();
} }
} }

View File

@ -12,7 +12,7 @@ use embassy_sync::waitqueue::AtomicWaker;
use crate::can::fd::peripheral::Registers; use crate::can::fd::peripheral::Registers;
use crate::gpio::AFType; use crate::gpio::AFType;
use crate::interrupt::typelevel::Interrupt; use crate::interrupt::typelevel::Interrupt;
use crate::rcc::RccPeripheral; use crate::rcc::{self, RccPeripheral};
use crate::{interrupt, peripherals, Peripheral}; use crate::{interrupt, peripherals, Peripheral};
pub(crate) mod fd; pub(crate) mod fd;
@ -184,7 +184,7 @@ impl<'d, T: Instance> CanConfigurator<'d, T> {
rx.set_as_af(rx.af_num(), AFType::Input); rx.set_as_af(rx.af_num(), AFType::Input);
tx.set_as_af(tx.af_num(), AFType::OutputPushPull); tx.set_as_af(tx.af_num(), AFType::OutputPushPull);
T::enable_and_reset(); rcc::enable_and_reset::<T>();
let mut config = crate::can::fd::config::FdCanConfig::default(); let mut config = crate::can::fd::config::FdCanConfig::default();
config.timestamp_source = TimestampSource::Prescaler(TimestampPrescaler::_1); config.timestamp_source = TimestampSource::Prescaler(TimestampPrescaler::_1);

View File

@ -4,7 +4,7 @@ use embassy_hal_internal::drop::OnDrop;
use embassy_hal_internal::{into_ref, Peripheral, PeripheralRef}; use embassy_hal_internal::{into_ref, Peripheral, PeripheralRef};
use crate::pac::cordic::vals; use crate::pac::cordic::vals;
use crate::{dma, peripherals}; use crate::{dma, peripherals, rcc};
mod enums; mod enums;
pub use enums::*; pub use enums::*;
@ -199,7 +199,7 @@ impl<'d, T: Instance> Cordic<'d, T> {
/// If you need a peripheral -> CORDIC -> peripheral mode, /// If you need a peripheral -> CORDIC -> peripheral mode,
/// you may want to set Cordic into [Mode::ZeroOverhead] mode, and add extra arguments with [Self::extra_config] /// you may want to set Cordic into [Mode::ZeroOverhead] mode, and add extra arguments with [Self::extra_config]
pub fn new(peri: impl Peripheral<P = T> + 'd, config: Config) -> Self { pub fn new(peri: impl Peripheral<P = T> + 'd, config: Config) -> Self {
T::enable_and_reset(); rcc::enable_and_reset::<T>();
into_ref!(peri); into_ref!(peri);
@ -259,7 +259,7 @@ impl<'d, T: Instance> Cordic<'d, T> {
impl<'d, T: Instance> Drop for Cordic<'d, T> { impl<'d, T: Instance> Drop for Cordic<'d, T> {
fn drop(&mut self) { fn drop(&mut self) {
T::disable(); rcc::disable::<T>();
} }
} }

View File

@ -2,8 +2,7 @@ use embassy_hal_internal::{into_ref, PeripheralRef};
use crate::pac::CRC as PAC_CRC; use crate::pac::CRC as PAC_CRC;
use crate::peripherals::CRC; use crate::peripherals::CRC;
use crate::rcc::SealedRccPeripheral; use crate::{rcc, Peripheral};
use crate::Peripheral;
/// CRC driver. /// CRC driver.
pub struct Crc<'d> { pub struct Crc<'d> {
@ -17,7 +16,7 @@ impl<'d> Crc<'d> {
// Note: enable and reset come from RccPeripheral. // Note: enable and reset come from RccPeripheral.
// enable CRC clock in RCC. // enable CRC clock in RCC.
CRC::enable_and_reset(); rcc::enable_and_reset::<CRC>();
// Peripheral the peripheral // Peripheral the peripheral
let mut instance = Self { _peri: peripheral }; let mut instance = Self { _peri: peripheral };
instance.reset(); instance.reset();

View File

@ -3,8 +3,7 @@ use embassy_hal_internal::{into_ref, PeripheralRef};
use crate::pac::crc::vals; use crate::pac::crc::vals;
use crate::pac::CRC as PAC_CRC; use crate::pac::CRC as PAC_CRC;
use crate::peripherals::CRC; use crate::peripherals::CRC;
use crate::rcc::SealedRccPeripheral; use crate::{rcc, Peripheral};
use crate::Peripheral;
/// CRC driver. /// CRC driver.
pub struct Crc<'d> { pub struct Crc<'d> {
@ -84,7 +83,7 @@ impl<'d> Crc<'d> {
pub fn new(peripheral: impl Peripheral<P = CRC> + 'd, config: Config) -> Self { pub fn new(peripheral: impl Peripheral<P = CRC> + 'd, config: Config) -> Self {
// Note: enable and reset come from RccPeripheral. // Note: enable and reset come from RccPeripheral.
// reset to default values and enable CRC clock in RCC. // reset to default values and enable CRC clock in RCC.
CRC::enable_and_reset(); rcc::enable_and_reset::<CRC>();
into_ref!(peripheral); into_ref!(peripheral);
let mut instance = Self { let mut instance = Self {
_peripheral: peripheral, _peripheral: peripheral,

View File

@ -9,7 +9,7 @@ use embassy_sync::waitqueue::AtomicWaker;
use crate::dma::{NoDma, Transfer, TransferOptions}; use crate::dma::{NoDma, Transfer, TransferOptions};
use crate::interrupt::typelevel::Interrupt; use crate::interrupt::typelevel::Interrupt;
use crate::{interrupt, pac, peripherals, Peripheral}; use crate::{interrupt, pac, peripherals, rcc, Peripheral};
const DES_BLOCK_SIZE: usize = 8; // 64 bits const DES_BLOCK_SIZE: usize = 8; // 64 bits
const AES_BLOCK_SIZE: usize = 16; // 128 bits const AES_BLOCK_SIZE: usize = 16; // 128 bits
@ -1021,7 +1021,7 @@ impl<'d, T: Instance, DmaIn, DmaOut> Cryp<'d, T, DmaIn, DmaOut> {
outdma: impl Peripheral<P = DmaOut> + 'd, outdma: impl Peripheral<P = DmaOut> + 'd,
_irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd,
) -> Self { ) -> Self {
T::enable_and_reset(); rcc::enable_and_reset::<T>();
into_ref!(peri, indma, outdma); into_ref!(peri, indma, outdma);
let instance = Self { let instance = Self {
_peripheral: peri, _peripheral: peri,

View File

@ -8,7 +8,7 @@ use embassy_hal_internal::{into_ref, PeripheralRef};
use crate::dma::NoDma; use crate::dma::NoDma;
#[cfg(any(dac_v3, dac_v4, dac_v5, dac_v6, dac_v7))] #[cfg(any(dac_v3, dac_v4, dac_v5, dac_v6, dac_v7))]
use crate::pac::dac; use crate::pac::dac;
use crate::rcc::RccPeripheral; use crate::rcc::{self, RccPeripheral};
use crate::{peripherals, Peripheral}; use crate::{peripherals, Peripheral};
mod tsel; mod tsel;
@ -131,7 +131,7 @@ impl<'d, T: Instance, const N: u8, DMA> DacChannel<'d, T, N, DMA> {
) -> Self { ) -> Self {
into_ref!(dma, pin); into_ref!(dma, pin);
pin.set_as_analog(); pin.set_as_analog();
T::enable_and_reset(); rcc::enable_and_reset::<T>();
let mut dac = Self { let mut dac = Self {
phantom: PhantomData, phantom: PhantomData,
dma, dma,
@ -157,7 +157,7 @@ impl<'d, T: Instance, const N: u8, DMA> DacChannel<'d, T, N, DMA> {
#[cfg(all(any(dac_v3, dac_v4, dac_v5, dac_v6, dac_v7), not(any(stm32h56x, stm32h57x))))] #[cfg(all(any(dac_v3, dac_v4, dac_v5, dac_v6, dac_v7), not(any(stm32h56x, stm32h57x))))]
pub fn new_internal(_peri: impl Peripheral<P = T> + 'd, dma: impl Peripheral<P = DMA> + 'd) -> Self { pub fn new_internal(_peri: impl Peripheral<P = T> + 'd, dma: impl Peripheral<P = DMA> + 'd) -> Self {
into_ref!(dma); into_ref!(dma);
T::enable_and_reset(); rcc::enable_and_reset::<T>();
let mut dac = Self { let mut dac = Self {
phantom: PhantomData, phantom: PhantomData,
dma, dma,
@ -356,7 +356,7 @@ impl_dma_methods!(2, DacDma2);
impl<'d, T: Instance, const N: u8, DMA> Drop for DacChannel<'d, T, N, DMA> { impl<'d, T: Instance, const N: u8, DMA> Drop for DacChannel<'d, T, N, DMA> {
fn drop(&mut self) { fn drop(&mut self) {
T::disable(); rcc::disable::<T>();
} }
} }
@ -400,8 +400,8 @@ impl<'d, T: Instance, DMACh1, DMACh2> Dac<'d, T, DMACh1, DMACh2> {
pin_ch2.set_as_analog(); pin_ch2.set_as_analog();
// Enable twice to increment the DAC refcount for each channel. // Enable twice to increment the DAC refcount for each channel.
T::enable_and_reset(); rcc::enable_and_reset::<T>();
T::enable_and_reset(); rcc::enable_and_reset::<T>();
let mut ch1 = DacCh1 { let mut ch1 = DacCh1 {
phantom: PhantomData, phantom: PhantomData,
@ -444,8 +444,8 @@ impl<'d, T: Instance, DMACh1, DMACh2> Dac<'d, T, DMACh1, DMACh2> {
) -> Self { ) -> Self {
into_ref!(dma_ch1, dma_ch2); into_ref!(dma_ch1, dma_ch2);
// Enable twice to increment the DAC refcount for each channel. // Enable twice to increment the DAC refcount for each channel.
T::enable_and_reset(); rcc::enable_and_reset::<T>();
T::enable_and_reset(); rcc::enable_and_reset::<T>();
let mut ch1 = DacCh1 { let mut ch1 = DacCh1 {
phantom: PhantomData, phantom: PhantomData,

View File

@ -9,7 +9,7 @@ use embassy_sync::waitqueue::AtomicWaker;
use crate::dma::Transfer; use crate::dma::Transfer;
use crate::gpio::{AFType, Speed}; use crate::gpio::{AFType, Speed};
use crate::interrupt::typelevel::Interrupt; use crate::interrupt::typelevel::Interrupt;
use crate::{interrupt, Peripheral}; use crate::{interrupt, rcc, Peripheral};
/// Interrupt handler. /// Interrupt handler.
pub struct InterruptHandler<T: Instance> { pub struct InterruptHandler<T: Instance> {
@ -350,7 +350,7 @@ where
use_embedded_synchronization: bool, use_embedded_synchronization: bool,
edm: u8, edm: u8,
) -> Self { ) -> Self {
T::enable_and_reset(); rcc::enable_and_reset::<T>();
peri.regs().cr().modify(|r| { peri.regs().cr().modify(|r| {
r.set_cm(true); // disable continuous mode (snapshot mode) r.set_cm(true); // disable continuous mode (snapshot mode)

View File

@ -6,7 +6,7 @@ use embassy_hal_internal::{into_ref, PeripheralRef};
//use crate::gpio::{AnyPin, SealedPin}; //use crate::gpio::{AnyPin, SealedPin};
use crate::gpio::{AFType, AnyPin, Pull, Speed}; use crate::gpio::{AFType, AnyPin, Pull, Speed};
use crate::rcc::RccPeripheral; use crate::rcc::{self, RccPeripheral};
use crate::{peripherals, Peripheral}; use crate::{peripherals, Peripheral};
/// Performs a busy-wait delay for a specified number of microseconds. /// Performs a busy-wait delay for a specified number of microseconds.
@ -77,7 +77,7 @@ impl<'d, T: Instance> DsiHost<'d, T> {
pub fn new(_peri: impl Peripheral<P = T> + 'd, te: impl Peripheral<P = impl TePin<T>> + 'd) -> Self { pub fn new(_peri: impl Peripheral<P = T> + 'd, te: impl Peripheral<P = impl TePin<T>> + 'd) -> Self {
into_ref!(te); into_ref!(te);
T::enable_and_reset(); rcc::enable_and_reset::<T>();
// Set Tearing Enable pin according to CubeMx example // Set Tearing Enable pin according to CubeMx example
te.set_as_af_pull(te.af_num(), AFType::OutputPushPull, Pull::None); te.set_as_af_pull(te.af_num(), AFType::OutputPushPull, Pull::None);

View File

@ -4,7 +4,7 @@ use core::marker::PhantomData;
use embassy_hal_internal::into_ref; use embassy_hal_internal::into_ref;
use crate::gpio::{AFType, Pull, Speed}; use crate::gpio::{AFType, Pull, Speed};
use crate::Peripheral; use crate::{rcc, Peripheral};
/// FMC driver /// FMC driver
pub struct Fmc<'d, T: Instance> { pub struct Fmc<'d, T: Instance> {
@ -27,7 +27,7 @@ where
/// Enable the FMC peripheral and reset it. /// Enable the FMC peripheral and reset it.
pub fn enable(&mut self) { pub fn enable(&mut self) {
T::enable_and_reset(); rcc::enable_and_reset::<T>();
} }
/// Enable the memory controller on applicable chips. /// Enable the memory controller on applicable chips.
@ -54,7 +54,7 @@ where
const REGISTERS: *const () = T::REGS.as_ptr() as *const _; const REGISTERS: *const () = T::REGS.as_ptr() as *const _;
fn enable(&mut self) { fn enable(&mut self) {
T::enable_and_reset(); rcc::enable_and_reset::<T>();
} }
fn memory_controller_enable(&mut self) { fn memory_controller_enable(&mut self) {
@ -200,7 +200,7 @@ impl<'d, T: Instance> Fmc<'d, T> {
)); ));
} }
trait SealedInstance: crate::rcc::SealedRccPeripheral { trait SealedInstance: crate::rcc::RccPeripheral {
const REGS: crate::pac::fmc::Fmc; const REGS: crate::pac::fmc::Fmc;
} }

View File

@ -822,7 +822,7 @@ foreach_pin!(
pub(crate) unsafe fn init(_cs: CriticalSection) { pub(crate) unsafe fn init(_cs: CriticalSection) {
#[cfg(afio)] #[cfg(afio)]
<crate::peripherals::AFIO as crate::rcc::SealedRccPeripheral>::enable_and_reset_with_cs(_cs); crate::rcc::enable_and_reset_with_cs::<crate::peripherals::AFIO>(_cs);
crate::_generated::init_gpio(); crate::_generated::init_gpio();
} }

View File

@ -17,8 +17,7 @@ use crate::dma::NoDma;
use crate::dma::Transfer; use crate::dma::Transfer;
use crate::interrupt::typelevel::Interrupt; use crate::interrupt::typelevel::Interrupt;
use crate::peripherals::HASH; use crate::peripherals::HASH;
use crate::rcc::SealedRccPeripheral; use crate::{interrupt, pac, peripherals, rcc, Peripheral};
use crate::{interrupt, pac, peripherals, Peripheral};
#[cfg(hash_v1)] #[cfg(hash_v1)]
const NUM_CONTEXT_REGS: usize = 51; const NUM_CONTEXT_REGS: usize = 51;
@ -130,7 +129,7 @@ impl<'d, T: Instance, D> Hash<'d, T, D> {
dma: impl Peripheral<P = D> + 'd, dma: impl Peripheral<P = D> + 'd,
_irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd,
) -> Self { ) -> Self {
HASH::enable_and_reset(); rcc::enable_and_reset::<HASH>();
into_ref!(peripheral, dma); into_ref!(peripheral, dma);
let instance = Self { let instance = Self {
_peripheral: peripheral, _peripheral: peripheral,

View File

@ -9,7 +9,7 @@ pub use traits::Instance;
use crate::gpio::{AFType, AnyPin}; use crate::gpio::{AFType, AnyPin};
use crate::time::Hertz; use crate::time::Hertz;
use crate::Peripheral; use crate::{rcc, Peripheral};
/// HRTIM burst controller instance. /// HRTIM burst controller instance.
pub struct BurstController<T: Instance> { pub struct BurstController<T: Instance> {
@ -172,7 +172,7 @@ impl<'d, T: Instance> AdvancedPwm<'d, T> {
fn new_inner(tim: impl Peripheral<P = T> + 'd) -> Self { fn new_inner(tim: impl Peripheral<P = T> + 'd) -> Self {
into_ref!(tim); into_ref!(tim);
T::enable_and_reset(); rcc::enable_and_reset::<T>();
#[cfg(stm32f334)] #[cfg(stm32f334)]
if crate::pac::RCC.cfgr3().read().hrtim1sw() == crate::pac::rcc::vals::Timsw::PLL1_P { if crate::pac::RCC.cfgr3().read().hrtim1sw() == crate::pac::rcc::vals::Timsw::PLL1_P {

View File

@ -18,7 +18,7 @@ use crate::dma::ChannelAndRequest;
use crate::gpio::{AFType, Pull}; use crate::gpio::{AFType, Pull};
use crate::interrupt::typelevel::Interrupt; use crate::interrupt::typelevel::Interrupt;
use crate::mode::{Async, Blocking, Mode}; use crate::mode::{Async, Blocking, Mode};
use crate::rcc::{ClockEnableBit, SealedRccPeripheral}; use crate::rcc::{self, RccInfo, SealedRccPeripheral};
use crate::time::Hertz; use crate::time::Hertz;
use crate::{interrupt, peripherals}; use crate::{interrupt, peripherals};
@ -128,7 +128,7 @@ impl<'d, M: Mode> I2c<'d, M> {
) -> Self { ) -> Self {
into_ref!(scl, sda); into_ref!(scl, sda);
T::enable_and_reset(); rcc::enable_and_reset::<T>();
scl.set_as_af_pull( scl.set_as_af_pull(
scl.af_num(), scl.af_num(),
@ -224,7 +224,7 @@ impl State {
struct Info { struct Info {
regs: crate::pac::i2c::I2c, regs: crate::pac::i2c::I2c,
pub(crate) enable_bit: ClockEnableBit, rcc: RccInfo,
} }
peri_trait!( peri_trait!(
@ -265,7 +265,7 @@ foreach_peripheral!(
fn info() -> &'static Info { fn info() -> &'static Info {
static INFO: Info = Info{ static INFO: Info = Info{
regs: crate::pac::$inst, regs: crate::pac::$inst,
enable_bit: crate::peripherals::$inst::ENABLE_BIT, rcc: crate::peripherals::$inst::RCC_INFO,
}; };
&INFO &INFO
} }

View File

@ -702,7 +702,7 @@ impl<'d> I2c<'d, Async> {
impl<'d, M: PeriMode> Drop for I2c<'d, M> { impl<'d, M: PeriMode> Drop for I2c<'d, M> {
fn drop(&mut self) { fn drop(&mut self) {
self.info.enable_bit.disable() self.info.rcc.disable()
} }
} }

View File

@ -673,7 +673,7 @@ impl<'d> I2c<'d, Async> {
impl<'d, M: Mode> Drop for I2c<'d, M> { impl<'d, M: Mode> Drop for I2c<'d, M> {
fn drop(&mut self) { fn drop(&mut self) {
self.info.enable_bit.disable(); self.info.rcc.disable();
} }
} }

View File

@ -6,10 +6,9 @@ use core::task::Poll;
use embassy_sync::waitqueue::AtomicWaker; use embassy_sync::waitqueue::AtomicWaker;
use crate::interrupt;
use crate::interrupt::typelevel::Interrupt; use crate::interrupt::typelevel::Interrupt;
use crate::peripherals::IPCC; use crate::peripherals::IPCC;
use crate::rcc::SealedRccPeripheral; use crate::{interrupt, rcc};
/// Interrupt handler. /// Interrupt handler.
pub struct ReceiveInterruptHandler {} pub struct ReceiveInterruptHandler {}
@ -102,7 +101,7 @@ pub struct Ipcc;
impl Ipcc { impl Ipcc {
/// Enable IPCC. /// Enable IPCC.
pub fn enable(_config: Config) { pub fn enable(_config: Config) {
IPCC::enable_and_reset(); rcc::enable_and_reset::<IPCC>();
IPCC::set_cpu2(true); IPCC::set_cpu2(true);
// set RF wake-up clock = LSE // set RF wake-up clock = LSE

View File

@ -194,7 +194,6 @@ pub(crate) use stm32_metapac as pac;
use crate::interrupt::Priority; use crate::interrupt::Priority;
#[cfg(feature = "rt")] #[cfg(feature = "rt")]
pub use crate::pac::NVIC_PRIO_BITS; pub use crate::pac::NVIC_PRIO_BITS;
use crate::rcc::SealedRccPeripheral;
/// `embassy-stm32` global configuration. /// `embassy-stm32` global configuration.
#[non_exhaustive] #[non_exhaustive]
@ -310,11 +309,11 @@ pub fn init(config: Config) -> Peripherals {
}); });
#[cfg(not(any(stm32f1, stm32wb, stm32wl)))] #[cfg(not(any(stm32f1, stm32wb, stm32wl)))]
peripherals::SYSCFG::enable_and_reset_with_cs(cs); rcc::enable_and_reset_with_cs::<peripherals::SYSCFG>(cs);
#[cfg(not(any(stm32h5, stm32h7, stm32h7rs, stm32wb, stm32wl)))] #[cfg(not(any(stm32h5, stm32h7, stm32h7rs, stm32wb, stm32wl)))]
peripherals::PWR::enable_and_reset_with_cs(cs); rcc::enable_and_reset_with_cs::<peripherals::PWR>(cs);
#[cfg(not(any(stm32f2, stm32f4, stm32f7, stm32l0, stm32h5, stm32h7, stm32h7rs)))] #[cfg(not(any(stm32f2, stm32f4, stm32f7, stm32l0, stm32h5, stm32h7, stm32h7rs)))]
peripherals::FLASH::enable_and_reset_with_cs(cs); rcc::enable_and_reset_with_cs::<peripherals::FLASH>(cs);
// Enable the VDDIO2 power supply on chips that have it. // Enable the VDDIO2 power supply on chips that have it.
// Note that this requires the PWR peripheral to be enabled first. // Note that this requires the PWR peripheral to be enabled first.

View File

@ -1,7 +1,7 @@
//! LTDC //! LTDC
use core::marker::PhantomData; use core::marker::PhantomData;
use crate::rcc::RccPeripheral; use crate::rcc::{self, RccPeripheral};
use crate::{peripherals, Peripheral}; use crate::{peripherals, Peripheral};
/// LTDC driver. /// LTDC driver.
@ -60,7 +60,7 @@ impl<'d, T: Instance> Ltdc<'d, T> {
.modify(|w| w.set_pllsaidivr(stm32_metapac::rcc::vals::Pllsaidivr::DIV2)); .modify(|w| w.set_pllsaidivr(stm32_metapac::rcc::vals::Pllsaidivr::DIV2));
}); });
T::enable_and_reset(); rcc::enable_and_reset::<T>();
//new_pin!(clk, AFType::OutputPushPull, Speed::VeryHigh, Pull::None); //new_pin!(clk, AFType::OutputPushPull, Speed::VeryHigh, Pull::None);

View File

@ -16,7 +16,7 @@ use crate::dma::{word, ChannelAndRequest};
use crate::gpio::{AFType, AnyPin, Pull, SealedPin as _, Speed}; use crate::gpio::{AFType, AnyPin, Pull, SealedPin as _, Speed};
use crate::mode::{Async, Blocking, Mode as PeriMode}; use crate::mode::{Async, Blocking, Mode as PeriMode};
use crate::pac::octospi::{vals, Octospi as Regs}; use crate::pac::octospi::{vals, Octospi as Regs};
use crate::rcc::RccPeripheral; use crate::rcc::{self, RccPeripheral};
use crate::{peripherals, Peripheral}; use crate::{peripherals, Peripheral};
/// OPSI driver config. /// OPSI driver config.
@ -198,7 +198,7 @@ impl<'d, T: Instance, M: PeriMode> Ospi<'d, T, M> {
into_ref!(peri); into_ref!(peri);
// System configuration // System configuration
T::enable_and_reset(); rcc::enable_and_reset::<T>();
while T::REGS.sr().read().busy() {} while T::REGS.sr().read().busy() {}
// Device configuration // Device configuration
@ -1013,7 +1013,7 @@ impl<'d, T: Instance, M: PeriMode> Drop for Ospi<'d, T, M> {
self.nss.as_ref().map(|x| x.set_as_disconnected()); self.nss.as_ref().map(|x| x.set_as_disconnected());
self.dqs.as_ref().map(|x| x.set_as_disconnected()); self.dqs.as_ref().map(|x| x.set_as_disconnected());
T::disable(); rcc::disable::<T>();
} }
} }

View File

@ -13,7 +13,7 @@ use crate::dma::ChannelAndRequest;
use crate::gpio::{AFType, AnyPin, Pull, Speed}; use crate::gpio::{AFType, AnyPin, Pull, Speed};
use crate::mode::{Async, Blocking, Mode as PeriMode}; use crate::mode::{Async, Blocking, Mode as PeriMode};
use crate::pac::quadspi::Quadspi as Regs; use crate::pac::quadspi::Quadspi as Regs;
use crate::rcc::RccPeripheral; use crate::rcc::{self, RccPeripheral};
use crate::{peripherals, Peripheral}; use crate::{peripherals, Peripheral};
/// QSPI transfer configuration. /// QSPI transfer configuration.
@ -102,7 +102,7 @@ impl<'d, T: Instance, M: PeriMode> Qspi<'d, T, M> {
) -> Self { ) -> Self {
into_ref!(peri); into_ref!(peri);
T::enable_and_reset(); rcc::enable_and_reset::<T>();
while T::REGS.sr().read().busy() {} while T::REGS.sr().read().busy() {}

View File

@ -2,7 +2,7 @@
use crate::pac::crs::vals::Syncsrc; use crate::pac::crs::vals::Syncsrc;
use crate::pac::{CRS, RCC}; use crate::pac::{CRS, RCC};
use crate::rcc::SealedRccPeripheral; use crate::rcc::{self, SealedRccPeripheral};
use crate::time::Hertz; use crate::time::Hertz;
/// HSI48 speed /// HSI48 speed
@ -44,7 +44,7 @@ pub(crate) fn init_hsi48(config: Hsi48Config) -> Hertz {
while r.read().hsi48rdy() == false {} while r.read().hsi48rdy() == false {}
if config.sync_from_usb { if config.sync_from_usb {
crate::peripherals::CRS::enable_and_reset(); rcc::enable_and_reset::<crate::peripherals::CRS>();
CRS.cfgr().modify(|w| { CRS.cfgr().modify(|w| {
w.set_syncsrc(Syncsrc::USB); w.set_syncsrc(Syncsrc::USB);

View File

@ -67,23 +67,185 @@ pub(crate) unsafe fn get_freqs() -> &'static Clocks {
} }
pub(crate) trait SealedRccPeripheral { pub(crate) trait SealedRccPeripheral {
const ENABLE_BIT: ClockEnableBit;
fn frequency() -> Hertz; fn frequency() -> Hertz;
fn enable_and_reset_with_cs(cs: CriticalSection); const RCC_INFO: RccInfo;
fn disable_with_cs(cs: CriticalSection);
fn enable_and_reset() {
critical_section::with(|cs| Self::enable_and_reset_with_cs(cs))
}
fn disable() {
critical_section::with(|cs| Self::disable_with_cs(cs))
}
} }
#[allow(private_bounds)] #[allow(private_bounds)]
pub trait RccPeripheral: SealedRccPeripheral + 'static {} pub trait RccPeripheral: SealedRccPeripheral + 'static {}
/// Runtime information necessary to reset, enable and disable a peripheral.
pub(crate) struct RccInfo {
/// Offset in 32-bit words of the xxxRSTR register into the RCC register block, or 0xff if the
/// peripheral has no reset bit (we don't use an `Option` to save one byte of storage).
reset_offset_or_0xff: u8,
/// Position of the xxxRST bit within the xxxRSTR register (0..=31).
reset_bit: u8,
/// Offset in 32-bit words of the xxxENR register into the RCC register block.
enable_offset: u8,
/// Position of the xxxEN bit within the xxxENR register (0..=31).
enable_bit: u8,
/// If this peripheral shares the same xxxRSTR bit and xxxEN bit with other peripherals, we
/// maintain a refcount in `crate::_generated::REFCOUNTS` at this index. If the bit is not
/// shared, this is 0xff (we don't use an `Option` to save one byte of storage).
refcount_idx_or_0xff: u8,
/// Stop mode of the peripheral, used to maintain `REFCOUNT_STOP1` and `REFCOUNT_STOP2`.
#[cfg(feature = "low-power")]
stop_mode: StopMode,
}
#[cfg(feature = "low-power")]
#[allow(dead_code)]
pub(crate) enum StopMode {
Standby,
Stop2,
Stop1,
}
impl RccInfo {
/// Safety:
/// - `reset_offset_and_bit`, if set, must correspond to valid xxxRST bit
/// - `enable_offset_and_bit` must correspond to valid xxxEN bit
/// - `refcount_idx`, if set, must correspond to valid refcount in `_generated::REFCOUNTS`
/// - `stop_mode` must be valid
pub(crate) const unsafe fn new(
reset_offset_and_bit: Option<(u8, u8)>,
enable_offset_and_bit: (u8, u8),
refcount_idx: Option<u8>,
#[cfg(feature = "low-power")] stop_mode: StopMode,
) -> Self {
let (reset_offset_or_0xff, reset_bit) = match reset_offset_and_bit {
Some((offset, bit)) => (offset, bit),
None => (0xff, 0xff),
};
let (enable_offset, enable_bit) = enable_offset_and_bit;
let refcount_idx_or_0xff = match refcount_idx {
Some(idx) => idx,
None => 0xff,
};
Self {
reset_offset_or_0xff,
reset_bit,
enable_offset,
enable_bit,
refcount_idx_or_0xff,
#[cfg(feature = "low-power")]
stop_mode,
}
}
// TODO: should this be `unsafe`?
pub(crate) fn enable_and_reset_with_cs(&self, _cs: CriticalSection) {
if self.refcount_idx_or_0xff != 0xff {
let refcount_idx = self.refcount_idx_or_0xff as usize;
unsafe {
crate::_generated::REFCOUNTS[refcount_idx] += 1;
}
if unsafe { crate::_generated::REFCOUNTS[refcount_idx] } > 1 {
return;
}
}
#[cfg(feature = "low-power")]
match self.stop_mode {
StopMode::Standby => {}
StopMode::Stop2 => unsafe {
REFCOUNT_STOP2 += 1;
},
StopMode::Stop1 => unsafe {
REFCOUNT_STOP1 += 1;
},
}
// set the xxxRST bit
let reset_ptr = self.reset_ptr();
if let Some(reset_ptr) = reset_ptr {
unsafe {
let val = reset_ptr.read_volatile();
reset_ptr.write_volatile(val | 1u32 << self.reset_bit);
}
}
// set the xxxEN bit
let enable_ptr = self.enable_ptr();
unsafe {
let val = enable_ptr.read_volatile();
enable_ptr.write_volatile(val | 1u32 << self.enable_bit);
}
// we must wait two peripheral clock cycles before the clock is active
// this seems to work, but might be incorrect
// see http://efton.sk/STM32/gotcha/g183.html
// dummy read (like in the ST HALs)
let _ = unsafe { enable_ptr.read_volatile() };
// DSB for good measure
cortex_m::asm::dsb();
// clear the xxxRST bit
if let Some(reset_ptr) = reset_ptr {
unsafe {
let val = reset_ptr.read_volatile();
reset_ptr.write_volatile(val & !(1u32 << self.reset_bit));
}
}
}
// TODO: should this be `unsafe`?
pub(crate) fn disable_with_cs(&self, _cs: CriticalSection) {
if self.refcount_idx_or_0xff != 0xff {
let refcount_idx = self.refcount_idx_or_0xff as usize;
unsafe {
crate::_generated::REFCOUNTS[refcount_idx] -= 1;
}
if unsafe { crate::_generated::REFCOUNTS[refcount_idx] } > 0 {
return;
}
}
#[cfg(feature = "low-power")]
match self.stop_mode {
StopMode::Standby => {}
StopMode::Stop2 => unsafe {
REFCOUNT_STOP2 -= 1;
},
StopMode::Stop1 => unsafe {
REFCOUNT_STOP1 -= 1;
},
}
// clear the xxxEN bit
let enable_ptr = self.enable_ptr();
unsafe {
let val = enable_ptr.read_volatile();
enable_ptr.write_volatile(val & !(1u32 << self.enable_bit));
}
}
// TODO: should this be `unsafe`?
pub(crate) fn enable_and_reset(&self) {
critical_section::with(|cs| self.enable_and_reset_with_cs(cs))
}
// TODO: should this be `unsafe`?
pub(crate) fn disable(&self) {
critical_section::with(|cs| self.disable_with_cs(cs))
}
fn reset_ptr(&self) -> Option<*mut u32> {
if self.reset_offset_or_0xff != 0xff {
Some(unsafe { (RCC.as_ptr() as *mut u32).add(self.reset_offset_or_0xff as _) })
} else {
None
}
}
fn enable_ptr(&self) -> *mut u32 {
unsafe { (RCC.as_ptr() as *mut u32).add(self.enable_offset as _) }
}
}
#[allow(unused)] #[allow(unused)]
mod util { mod util {
use crate::time::Hertz; use crate::time::Hertz;
@ -128,8 +290,9 @@ pub fn frequency<T: RccPeripheral>() -> Hertz {
/// # Safety /// # Safety
/// ///
/// Peripheral must not be in use. /// Peripheral must not be in use.
pub unsafe fn enable_and_reset<T: RccPeripheral>() { // TODO: should this be `unsafe`?
T::enable_and_reset(); pub fn enable_and_reset_with_cs<T: RccPeripheral>(cs: CriticalSection) {
T::RCC_INFO.enable_and_reset_with_cs(cs);
} }
/// Disables peripheral `T`. /// Disables peripheral `T`.
@ -137,52 +300,27 @@ pub unsafe fn enable_and_reset<T: RccPeripheral>() {
/// # Safety /// # Safety
/// ///
/// Peripheral must not be in use. /// Peripheral must not be in use.
pub unsafe fn disable<T: RccPeripheral>() { // TODO: should this be `unsafe`?
T::disable(); pub fn disable_with_cs<T: RccPeripheral>(cs: CriticalSection) {
T::RCC_INFO.disable_with_cs(cs);
} }
/// Struct representing some clock enable bit (xxxENR.xxEN), only known at runtime. /// Enables and resets peripheral `T`.
#[derive(Clone, Copy)] ///
pub(crate) struct ClockEnableBit { /// # Safety
/// offset in 32bit words of the xxxENR register into the RCC register block. ///
offset: u8, /// Peripheral must not be in use.
/// bit within the register (0..=31) // TODO: should this be `unsafe`?
bit: u8, pub fn enable_and_reset<T: RccPeripheral>() {
T::RCC_INFO.enable_and_reset();
} }
impl ClockEnableBit { /// Disables peripheral `T`.
/// Safety: offset+bit must correspond to a valid xxxEN bit. ///
pub(crate) const unsafe fn new(offset: u8, bit: u8) -> Self { /// # Safety
Self { offset, bit } ///
} /// Peripheral must not be in use.
// TODO: should this be `unsafe`?
fn ptr(self) -> *mut u32 { pub fn disable<T: RccPeripheral>() {
unsafe { (RCC.as_ptr() as *mut u32).add(self.offset as _) } T::RCC_INFO.disable();
}
#[allow(unused)]
pub(crate) fn enable_with_cs(self, _cs: CriticalSection) {
let p = self.ptr();
unsafe {
let val = p.read_volatile();
p.write_volatile(val | 1u32 << self.bit);
}
}
pub(crate) fn disable_with_cs(self, _cs: CriticalSection) {
let p = self.ptr();
unsafe {
let val = p.read_volatile();
p.write_volatile(val & !(1u32 << self.bit));
}
}
#[allow(unused)]
pub(crate) fn enable(self) {
critical_section::with(|cs| self.enable_with_cs(cs))
}
pub(crate) fn disable(self) {
critical_section::with(|cs| self.disable_with_cs(cs))
}
} }

View File

@ -10,7 +10,7 @@ use embassy_sync::waitqueue::AtomicWaker;
use rand_core::{CryptoRng, RngCore}; use rand_core::{CryptoRng, RngCore};
use crate::interrupt::typelevel::Interrupt; use crate::interrupt::typelevel::Interrupt;
use crate::{interrupt, pac, peripherals, Peripheral}; use crate::{interrupt, pac, peripherals, rcc, Peripheral};
static RNG_WAKER: AtomicWaker = AtomicWaker::new(); static RNG_WAKER: AtomicWaker = AtomicWaker::new();
@ -52,7 +52,7 @@ impl<'d, T: Instance> Rng<'d, T> {
inner: impl Peripheral<P = T> + 'd, inner: impl Peripheral<P = T> + 'd,
_irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd, _irq: impl interrupt::typelevel::Binding<T::Interrupt, InterruptHandler<T>> + 'd,
) -> Self { ) -> Self {
T::enable_and_reset(); rcc::enable_and_reset::<T>();
into_ref!(inner); into_ref!(inner);
let mut random = Self { _inner: inner }; let mut random = Self { _inner: inner };
random.reset(); random.reset();

View File

@ -142,7 +142,7 @@ impl Rtc {
/// Create a new RTC instance. /// Create a new RTC instance.
pub fn new(_rtc: impl Peripheral<P = RTC>, rtc_config: RtcConfig) -> Self { pub fn new(_rtc: impl Peripheral<P = RTC>, rtc_config: RtcConfig) -> Self {
#[cfg(not(any(stm32l0, stm32f3, stm32l1, stm32f0, stm32f2)))] #[cfg(not(any(stm32l0, stm32f3, stm32l1, stm32f0, stm32f2)))]
<RTC as crate::rcc::SealedRccPeripheral>::enable_and_reset(); crate::rcc::enable_and_reset::<RTC>();
let mut this = Self { let mut this = Self {
#[cfg(feature = "low-power")] #[cfg(feature = "low-power")]

View File

@ -11,7 +11,7 @@ pub use crate::dma::word;
use crate::dma::{ringbuffer, Channel, ReadableRingBuffer, Request, TransferOptions, WritableRingBuffer}; use crate::dma::{ringbuffer, Channel, ReadableRingBuffer, Request, TransferOptions, WritableRingBuffer};
use crate::gpio::{AFType, AnyPin, SealedPin as _}; use crate::gpio::{AFType, AnyPin, SealedPin as _};
use crate::pac::sai::{vals, Sai as Regs}; use crate::pac::sai::{vals, Sai as Regs};
use crate::rcc::RccPeripheral; use crate::rcc::{self, RccPeripheral};
use crate::{peripherals, Peripheral}; use crate::{peripherals, Peripheral};
/// SAI error /// SAI error
@ -722,7 +722,7 @@ pub struct SubBlock<'d, T, S: SubBlockInstance> {
/// You can then create a [`Sai`] driver for each each half. /// You can then create a [`Sai`] driver for each each half.
pub fn split_subblocks<'d, T: Instance>(peri: impl Peripheral<P = T> + 'd) -> (SubBlock<'d, T, A>, SubBlock<'d, T, B>) { pub fn split_subblocks<'d, T: Instance>(peri: impl Peripheral<P = T> + 'd) -> (SubBlock<'d, T, A>, SubBlock<'d, T, B>) {
into_ref!(peri); into_ref!(peri);
T::enable_and_reset(); rcc::enable_and_reset::<T>();
( (
SubBlock { SubBlock {
@ -978,7 +978,7 @@ impl<'d, T: Instance, W: word::Word> Sai<'d, T, W> {
/// Reset SAI operation. /// Reset SAI operation.
pub fn reset() { pub fn reset() {
T::enable_and_reset(); rcc::enable_and_reset::<T>();
} }
/// Flush. /// Flush.

View File

@ -16,7 +16,7 @@ use crate::dma::NoDma;
use crate::gpio::{AFType, AnyPin, Pull, SealedPin, Speed}; use crate::gpio::{AFType, AnyPin, Pull, SealedPin, Speed};
use crate::interrupt::typelevel::Interrupt; use crate::interrupt::typelevel::Interrupt;
use crate::pac::sdmmc::Sdmmc as RegBlock; use crate::pac::sdmmc::Sdmmc as RegBlock;
use crate::rcc::RccPeripheral; use crate::rcc::{self, RccPeripheral};
use crate::time::Hertz; use crate::time::Hertz;
use crate::{interrupt, peripherals, Peripheral}; use crate::{interrupt, peripherals, Peripheral};
@ -468,7 +468,7 @@ impl<'d, T: Instance, Dma: SdmmcDma<T> + 'd> Sdmmc<'d, T, Dma> {
) -> Self { ) -> Self {
into_ref!(sdmmc, dma); into_ref!(sdmmc, dma);
T::enable_and_reset(); rcc::enable_and_reset::<T>();
T::Interrupt::unpend(); T::Interrupt::unpend();
unsafe { T::Interrupt::enable() }; unsafe { T::Interrupt::enable() };

View File

@ -13,7 +13,7 @@ use crate::dma::{slice_ptr_parts, word, ChannelAndRequest};
use crate::gpio::{AFType, AnyPin, Pull, SealedPin as _, Speed}; use crate::gpio::{AFType, AnyPin, Pull, SealedPin as _, Speed};
use crate::mode::{Async, Blocking, Mode as PeriMode}; use crate::mode::{Async, Blocking, Mode as PeriMode};
use crate::pac::spi::{regs, vals, Spi as Regs}; use crate::pac::spi::{regs, vals, Spi as Regs};
use crate::rcc::{ClockEnableBit, SealedRccPeripheral}; use crate::rcc::{self, RccInfo, SealedRccPeripheral};
use crate::time::Hertz; use crate::time::Hertz;
use crate::Peripheral; use crate::Peripheral;
@ -129,7 +129,7 @@ impl<'d, M: PeriMode> Spi<'d, M> {
let lsbfirst = config.raw_byte_order(); let lsbfirst = config.raw_byte_order();
T::enable_and_reset(); rcc::enable_and_reset::<T>();
#[cfg(any(spi_v1, spi_f1))] #[cfg(any(spi_v1, spi_f1))]
{ {
@ -830,7 +830,7 @@ impl<'d, M: PeriMode> Drop for Spi<'d, M> {
self.mosi.as_ref().map(|x| x.set_as_disconnected()); self.mosi.as_ref().map(|x| x.set_as_disconnected());
self.miso.as_ref().map(|x| x.set_as_disconnected()); self.miso.as_ref().map(|x| x.set_as_disconnected());
self.info.enable_bit.disable(); self.info.rcc.disable();
} }
} }
@ -1216,7 +1216,7 @@ mod word_impl {
pub(crate) struct Info { pub(crate) struct Info {
pub(crate) regs: Regs, pub(crate) regs: Regs,
pub(crate) enable_bit: ClockEnableBit, pub(crate) rcc: RccInfo,
} }
struct State {} struct State {}
@ -1243,7 +1243,7 @@ foreach_peripheral!(
(spi, $inst:ident) => { (spi, $inst:ident) => {
peri_trait_impl!($inst, Info { peri_trait_impl!($inst, Info {
regs: crate::pac::$inst, regs: crate::pac::$inst,
enable_bit: crate::peripherals::$inst::ENABLE_BIT, rcc: crate::peripherals::$inst::RCC_INFO,
}); });
}; };
); );

View File

@ -12,7 +12,7 @@ use stm32_metapac::timer::{regs, TimGp16};
use crate::interrupt::typelevel::Interrupt; use crate::interrupt::typelevel::Interrupt;
use crate::pac::timer::vals; use crate::pac::timer::vals;
use crate::rcc::SealedRccPeripheral; use crate::rcc::{self, SealedRccPeripheral};
#[cfg(feature = "low-power")] #[cfg(feature = "low-power")]
use crate::rtc::Rtc; use crate::rtc::Rtc;
use crate::timer::{CoreInstance, GeneralInstance1Channel}; use crate::timer::{CoreInstance, GeneralInstance1Channel};
@ -276,7 +276,7 @@ impl RtcDriver {
fn init(&'static self, cs: critical_section::CriticalSection) { fn init(&'static self, cs: critical_section::CriticalSection) {
let r = regs_gp16(); let r = regs_gp16();
<T as SealedRccPeripheral>::enable_and_reset_with_cs(cs); rcc::enable_and_reset_with_cs::<T>(cs);
let timer_freq = T::frequency(); let timer_freq = T::frequency();

View File

@ -10,6 +10,7 @@ use embassy_hal_internal::{into_ref, Peripheral, PeripheralRef};
use super::*; use super::*;
use crate::pac::timer::vals; use crate::pac::timer::vals;
use crate::rcc;
use crate::time::Hertz; use crate::time::Hertz;
/// Input capture mode. /// Input capture mode.
@ -181,7 +182,7 @@ pub struct Timer<'d, T: CoreInstance> {
impl<'d, T: CoreInstance> Drop for Timer<'d, T> { impl<'d, T: CoreInstance> Drop for Timer<'d, T> {
fn drop(&mut self) { fn drop(&mut self) {
T::disable() rcc::disable::<T>();
} }
} }
@ -190,7 +191,7 @@ impl<'d, T: CoreInstance> Timer<'d, T> {
pub fn new(tim: impl Peripheral<P = T> + 'd) -> Self { pub fn new(tim: impl Peripheral<P = T> + 'd) -> Self {
into_ref!(tim); into_ref!(tim);
T::enable_and_reset(); rcc::enable_and_reset::<T>();
Self { tim } Self { tim }
} }

View File

@ -72,7 +72,7 @@ pub use enums::*;
use crate::gpio::{AFType, AnyPin}; use crate::gpio::{AFType, AnyPin};
use crate::pac::tsc::Tsc as Regs; use crate::pac::tsc::Tsc as Regs;
use crate::rcc::RccPeripheral; use crate::rcc::{self, RccPeripheral};
use crate::{peripherals, Peripheral}; use crate::{peripherals, Peripheral};
#[cfg(tsc_v1)] #[cfg(tsc_v1)]
@ -649,7 +649,7 @@ impl<'d, T: Instance> Tsc<'d, T> {
) -> Self { ) -> Self {
into_ref!(peri); into_ref!(peri);
T::enable_and_reset(); rcc::enable_and_reset::<T>();
T::REGS.cr().modify(|w| { T::REGS.cr().modify(|w| {
w.set_tsce(true); w.set_tsce(true);
@ -880,7 +880,7 @@ impl<'d, T: Instance> Tsc<'d, T> {
impl<'d, T: Instance> Drop for Tsc<'d, T> { impl<'d, T: Instance> Drop for Tsc<'d, T> {
fn drop(&mut self) { fn drop(&mut self) {
T::disable(); rcc::disable::<T>();
} }
} }

View File

@ -28,7 +28,7 @@ use crate::interrupt;
use crate::interrupt::typelevel::Interrupt; use crate::interrupt::typelevel::Interrupt;
use crate::pac::ucpd::vals::{Anamode, Ccenable, PscUsbpdclk, Txmode}; use crate::pac::ucpd::vals::{Anamode, Ccenable, PscUsbpdclk, Txmode};
pub use crate::pac::ucpd::vals::{Phyccsel as CcSel, TypecVstateCc as CcVState}; pub use crate::pac::ucpd::vals::{Phyccsel as CcSel, TypecVstateCc as CcVState};
use crate::rcc::RccPeripheral; use crate::rcc::{self, RccPeripheral};
pub(crate) fn init( pub(crate) fn init(
_cs: critical_section::CriticalSection, _cs: critical_section::CriticalSection,
@ -103,7 +103,7 @@ impl<'d, T: Instance> Ucpd<'d, T> {
cc1.set_as_analog(); cc1.set_as_analog();
cc2.set_as_analog(); cc2.set_as_analog();
T::enable_and_reset(); rcc::enable_and_reset::<T>();
T::Interrupt::unpend(); T::Interrupt::unpend();
unsafe { T::Interrupt::enable() }; unsafe { T::Interrupt::enable() };
@ -212,7 +212,7 @@ impl<'d, T: Instance> Drop for CcPhy<'d, T> {
drop_not_ready.store(true, Ordering::Relaxed); drop_not_ready.store(true, Ordering::Relaxed);
} else { } else {
r.cfgr1().write(|w| w.set_ucpden(false)); r.cfgr1().write(|w| w.set_ucpden(false));
T::disable(); rcc::disable::<T>();
T::Interrupt::disable(); T::Interrupt::disable();
} }
} }
@ -325,7 +325,7 @@ impl<'d, T: Instance> Drop for PdPhy<'d, T> {
drop_not_ready.store(true, Ordering::Relaxed); drop_not_ready.store(true, Ordering::Relaxed);
} else { } else {
T::REGS.cfgr1().write(|w| w.set_ucpden(false)); T::REGS.cfgr1().write(|w| w.set_ucpden(false));
T::disable(); rcc::disable::<T>();
T::Interrupt::disable(); T::Interrupt::disable();
} }
} }

View File

@ -18,6 +18,7 @@ use super::{
use crate::gpio::AFType; use crate::gpio::AFType;
use crate::interrupt::typelevel::Interrupt as _; use crate::interrupt::typelevel::Interrupt as _;
use crate::interrupt::{self, InterruptExt}; use crate::interrupt::{self, InterruptExt};
use crate::rcc;
use crate::time::Hertz; use crate::time::Hertz;
/// Interrupt handler. /// Interrupt handler.
@ -206,7 +207,7 @@ impl<'d> BufferedUart<'d> {
rx_buffer: &'d mut [u8], rx_buffer: &'d mut [u8],
config: Config, config: Config,
) -> Result<Self, ConfigError> { ) -> Result<Self, ConfigError> {
T::enable_and_reset(); rcc::enable_and_reset::<T>();
Self::new_inner(peri, rx, tx, tx_buffer, rx_buffer, config) Self::new_inner(peri, rx, tx, tx_buffer, rx_buffer, config)
} }
@ -225,7 +226,7 @@ impl<'d> BufferedUart<'d> {
) -> Result<Self, ConfigError> { ) -> Result<Self, ConfigError> {
into_ref!(cts, rts); into_ref!(cts, rts);
T::enable_and_reset(); rcc::enable_and_reset::<T>();
rts.set_as_af(rts.af_num(), AFType::OutputPushPull); rts.set_as_af(rts.af_num(), AFType::OutputPushPull);
cts.set_as_af(cts.af_num(), AFType::Input); cts.set_as_af(cts.af_num(), AFType::Input);
@ -251,7 +252,7 @@ impl<'d> BufferedUart<'d> {
) -> Result<Self, ConfigError> { ) -> Result<Self, ConfigError> {
into_ref!(de); into_ref!(de);
T::enable_and_reset(); rcc::enable_and_reset::<T>();
de.set_as_af(de.af_num(), AFType::OutputPushPull); de.set_as_af(de.af_num(), AFType::OutputPushPull);
T::info().regs.cr3().write(|w| { T::info().regs.cr3().write(|w| {
@ -545,7 +546,7 @@ fn drop_tx_rx(info: &Info, state: &State) {
refcount == 1 refcount == 1
}); });
if is_last_drop { if is_last_drop {
info.enable_bit.disable(); info.rcc.disable();
} }
} }

View File

@ -28,7 +28,7 @@ use crate::pac::usart::Lpuart as Regs;
#[cfg(any(usart_v1, usart_v2))] #[cfg(any(usart_v1, usart_v2))]
use crate::pac::usart::Usart as Regs; use crate::pac::usart::Usart as Regs;
use crate::pac::usart::{regs, vals}; use crate::pac::usart::{regs, vals};
use crate::rcc::{ClockEnableBit, SealedRccPeripheral}; use crate::rcc::{self, RccInfo, SealedRccPeripheral};
use crate::time::Hertz; use crate::time::Hertz;
use crate::Peripheral; use crate::Peripheral;
@ -429,7 +429,7 @@ impl<'d, M: Mode> UartTx<'d, M> {
tx_dma: Option<ChannelAndRequest<'d>>, tx_dma: Option<ChannelAndRequest<'d>>,
config: Config, config: Config,
) -> Result<Self, ConfigError> { ) -> Result<Self, ConfigError> {
T::enable_and_reset(); rcc::enable_and_reset::<T>();
let info = T::info(); let info = T::info();
let state = T::state(); let state = T::state();
@ -775,7 +775,7 @@ impl<'d, M: Mode> UartRx<'d, M> {
rx_dma: Option<ChannelAndRequest<'d>>, rx_dma: Option<ChannelAndRequest<'d>>,
config: Config, config: Config,
) -> Result<Self, ConfigError> { ) -> Result<Self, ConfigError> {
T::enable_and_reset(); rcc::enable_and_reset::<T>();
let info = T::info(); let info = T::info();
let state = T::state(); let state = T::state();
@ -916,7 +916,7 @@ fn drop_tx_rx(info: &Info, state: &State) {
refcount == 1 refcount == 1
}); });
if is_last_drop { if is_last_drop {
info.enable_bit.disable(); info.rcc.disable();
} }
} }
@ -1228,7 +1228,7 @@ impl<'d, M: Mode> Uart<'d, M> {
rx_dma: Option<ChannelAndRequest<'d>>, rx_dma: Option<ChannelAndRequest<'d>>,
config: Config, config: Config,
) -> Result<Self, ConfigError> { ) -> Result<Self, ConfigError> {
T::enable_and_reset(); rcc::enable_and_reset::<T>();
let info = T::info(); let info = T::info();
let state = T::state(); let state = T::state();
@ -1718,7 +1718,7 @@ impl State {
struct Info { struct Info {
regs: Regs, regs: Regs,
enable_bit: ClockEnableBit, rcc: RccInfo,
interrupt: Interrupt, interrupt: Interrupt,
kind: Kind, kind: Kind,
} }
@ -1754,7 +1754,7 @@ macro_rules! impl_usart {
fn info() -> &'static Info { fn info() -> &'static Info {
static INFO: Info = Info { static INFO: Info = Info {
regs: unsafe { Regs::from_ptr(crate::pac::$inst.as_ptr()) }, regs: unsafe { Regs::from_ptr(crate::pac::$inst.as_ptr()) },
enable_bit: crate::peripherals::$inst::ENABLE_BIT, rcc: crate::peripherals::$inst::RCC_INFO,
interrupt: crate::interrupt::typelevel::$irq::IRQ, interrupt: crate::interrupt::typelevel::$irq::IRQ,
kind: $kind, kind: $kind,
}; };

View File

@ -6,7 +6,7 @@ mod _version;
pub use _version::*; pub use _version::*;
use crate::interrupt::typelevel::Interrupt; use crate::interrupt::typelevel::Interrupt;
use crate::rcc::SealedRccPeripheral; use crate::rcc;
/// clock, power initialization stuff that's common for USB and OTG. /// clock, power initialization stuff that's common for USB and OTG.
fn common_init<T: Instance>() { fn common_init<T: Instance>() {
@ -65,5 +65,5 @@ fn common_init<T: Instance>() {
T::Interrupt::unpend(); T::Interrupt::unpend();
unsafe { T::Interrupt::enable() }; unsafe { T::Interrupt::enable() };
<T as SealedRccPeripheral>::enable_and_reset(); rcc::enable_and_reset::<T>();
} }

View File

@ -13,7 +13,7 @@ use embassy_usb_synopsys_otg::{
use crate::gpio::AFType; use crate::gpio::AFType;
use crate::interrupt; use crate::interrupt;
use crate::interrupt::typelevel::Interrupt; use crate::interrupt::typelevel::Interrupt;
use crate::rcc::{RccPeripheral, SealedRccPeripheral}; use crate::rcc::{self, RccPeripheral};
const MAX_EP_COUNT: usize = 9; const MAX_EP_COUNT: usize = 9;
@ -246,7 +246,7 @@ impl<'d, T: Instance> Bus<'d, T> {
fn disable(&mut self) { fn disable(&mut self) {
T::Interrupt::disable(); T::Interrupt::disable();
<T as SealedRccPeripheral>::disable(); rcc::disable::<T>();
self.inited = false; self.inited = false;
#[cfg(stm32l4)] #[cfg(stm32l4)]