565: stm32: RCC cleanups r=Dirbaio a=Dirbaio



Co-authored-by: Dario Nieuwenhuis <dirbaio@dirbaio.net>
This commit is contained in:
bors[bot] 2022-01-04 12:31:55 +00:00 committed by GitHub
commit b2a85ee519
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 42 additions and 256 deletions

View File

@ -102,10 +102,10 @@ impl Into<u8> for AHBPrescaler {
/// Clocks configutation /// Clocks configutation
pub struct Config { pub struct Config {
mux: ClockSrc, pub mux: ClockSrc,
ahb_pre: AHBPrescaler, pub ahb_pre: AHBPrescaler,
apb_pre: APBPrescaler, pub apb_pre: APBPrescaler,
low_power_run: bool, pub low_power_run: bool,
} }
impl Default for Config { impl Default for Config {
@ -120,32 +120,6 @@ impl Default for Config {
} }
} }
impl Config {
#[inline]
pub fn clock_src(mut self, mux: ClockSrc) -> Self {
self.mux = mux;
self
}
#[inline]
pub fn ahb_pre(mut self, pre: AHBPrescaler) -> Self {
self.ahb_pre = pre;
self
}
#[inline]
pub fn apb_pre(mut self, pre: APBPrescaler) -> Self {
self.apb_pre = pre;
self
}
#[inline]
pub fn low_power_run(mut self, on: bool) -> Self {
self.low_power_run = on;
self
}
}
/// RCC peripheral /// RCC peripheral
pub struct Rcc<'d> { pub struct Rcc<'d> {
_rb: peripherals::RCC, _rb: peripherals::RCC,

View File

@ -74,11 +74,11 @@ impl Into<u8> for AHBPrescaler {
/// Clocks configutation /// Clocks configutation
pub struct Config { pub struct Config {
mux: ClockSrc, pub mux: ClockSrc,
ahb_pre: AHBPrescaler, pub ahb_pre: AHBPrescaler,
apb1_pre: APBPrescaler, pub apb1_pre: APBPrescaler,
apb2_pre: APBPrescaler, pub apb2_pre: APBPrescaler,
low_power_run: bool, pub low_power_run: bool,
} }
impl Default for Config { impl Default for Config {
@ -94,38 +94,6 @@ impl Default for Config {
} }
} }
impl Config {
#[inline]
pub fn clock_src(mut self, mux: ClockSrc) -> Self {
self.mux = mux;
self
}
#[inline]
pub fn ahb_pre(mut self, pre: AHBPrescaler) -> Self {
self.ahb_pre = pre;
self
}
#[inline]
pub fn apb1_pre(mut self, pre: APBPrescaler) -> Self {
self.apb1_pre = pre;
self
}
#[inline]
pub fn apb2_pre(mut self, pre: APBPrescaler) -> Self {
self.apb2_pre = pre;
self
}
#[inline]
pub fn low_power_run(mut self, on: bool) -> Self {
self.low_power_run = on;
self
}
}
/// RCC peripheral /// RCC peripheral
pub struct Rcc<'d> { pub struct Rcc<'d> {
_rb: peripherals::RCC, _rb: peripherals::RCC,

View File

@ -72,8 +72,6 @@ pub struct Config {
pub pll1: PllConfig, pub pll1: PllConfig,
pub pll2: PllConfig, pub pll2: PllConfig,
pub pll3: PllConfig, pub pll3: PllConfig,
pub enable_dma1: bool,
pub enable_dma2: bool,
} }
pub struct Rcc<'d> { pub struct Rcc<'d> {
@ -331,14 +329,6 @@ impl<'d> Rcc<'d> {
}); });
while !SYSCFG.cccsr().read().ready() {} while !SYSCFG.cccsr().read().ready() {}
if self.config.enable_dma1 {
RCC.ahb1enr().modify(|w| w.set_dma1en(true));
}
if self.config.enable_dma2 {
RCC.ahb1enr().modify(|w| w.set_dma2en(true));
}
CoreClocks { CoreClocks {
hclk: Hertz(rcc_hclk), hclk: Hertz(rcc_hclk),
pclk1: Hertz(rcc_pclk1), pclk1: Hertz(rcc_pclk1),

View File

@ -183,10 +183,10 @@ impl Into<Msirange> for MSIRange {
/// Clocks configutation /// Clocks configutation
pub struct Config { pub struct Config {
mux: ClockSrc, pub mux: ClockSrc,
ahb_pre: AHBPrescaler, pub ahb_pre: AHBPrescaler,
apb1_pre: APBPrescaler, pub apb1_pre: APBPrescaler,
apb2_pre: APBPrescaler, pub apb2_pre: APBPrescaler,
} }
impl Default for Config { impl Default for Config {
@ -201,32 +201,6 @@ impl Default for Config {
} }
} }
impl Config {
#[inline]
pub fn clock_src(mut self, mux: ClockSrc) -> Self {
self.mux = mux;
self
}
#[inline]
pub fn ahb_pre(mut self, pre: AHBPrescaler) -> Self {
self.ahb_pre = pre;
self
}
#[inline]
pub fn apb1_pre(mut self, pre: APBPrescaler) -> Self {
self.apb1_pre = pre;
self
}
#[inline]
pub fn apb2_pre(mut self, pre: APBPrescaler) -> Self {
self.apb2_pre = pre;
self
}
}
/// RCC peripheral /// RCC peripheral
pub struct Rcc<'d> { pub struct Rcc<'d> {
_rb: peripherals::RCC, _rb: peripherals::RCC,

View File

@ -118,10 +118,10 @@ impl Into<u8> for MSIRange {
/// Clocks configutation /// Clocks configutation
pub struct Config { pub struct Config {
mux: ClockSrc, pub mux: ClockSrc,
ahb_pre: AHBPrescaler, pub ahb_pre: AHBPrescaler,
apb1_pre: APBPrescaler, pub apb1_pre: APBPrescaler,
apb2_pre: APBPrescaler, pub apb2_pre: APBPrescaler,
} }
impl Default for Config { impl Default for Config {
@ -136,32 +136,6 @@ impl Default for Config {
} }
} }
impl Config {
#[inline]
pub fn clock_src(mut self, mux: ClockSrc) -> Self {
self.mux = mux;
self
}
#[inline]
pub fn ahb_pre(mut self, pre: AHBPrescaler) -> Self {
self.ahb_pre = pre;
self
}
#[inline]
pub fn apb1_pre(mut self, pre: APBPrescaler) -> Self {
self.apb1_pre = pre;
self
}
#[inline]
pub fn apb2_pre(mut self, pre: APBPrescaler) -> Self {
self.apb2_pre = pre;
self
}
}
/// RCC peripheral /// RCC peripheral
pub struct Rcc<'d> { pub struct Rcc<'d> {
_rb: peripherals::RCC, _rb: peripherals::RCC,

View File

@ -269,10 +269,10 @@ impl Into<u8> for AHBPrescaler {
/// Clocks configutation /// Clocks configutation
pub struct Config { pub struct Config {
mux: ClockSrc, pub mux: ClockSrc,
ahb_pre: AHBPrescaler, pub ahb_pre: AHBPrescaler,
apb1_pre: APBPrescaler, pub apb1_pre: APBPrescaler,
apb2_pre: APBPrescaler, pub apb2_pre: APBPrescaler,
} }
impl Default for Config { impl Default for Config {
@ -287,32 +287,6 @@ impl Default for Config {
} }
} }
impl Config {
#[inline]
pub fn clock_src(mut self, mux: ClockSrc) -> Self {
self.mux = mux;
self
}
#[inline]
pub fn ahb_pre(mut self, pre: AHBPrescaler) -> Self {
self.ahb_pre = pre;
self
}
#[inline]
pub fn apb1_pre(mut self, pre: APBPrescaler) -> Self {
self.apb1_pre = pre;
self
}
#[inline]
pub fn apb2_pre(mut self, pre: APBPrescaler) -> Self {
self.apb2_pre = pre;
self
}
}
/// RCC peripheral /// RCC peripheral
pub struct Rcc<'d> { pub struct Rcc<'d> {
_rb: peripherals::RCC, _rb: peripherals::RCC,

View File

@ -274,16 +274,16 @@ impl Default for MSIRange {
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub struct Config { pub struct Config {
mux: ClockSrc, pub mux: ClockSrc,
ahb_pre: AHBPrescaler, pub ahb_pre: AHBPrescaler,
apb1_pre: APBPrescaler, pub apb1_pre: APBPrescaler,
apb2_pre: APBPrescaler, pub apb2_pre: APBPrescaler,
apb3_pre: APBPrescaler, pub apb3_pre: APBPrescaler,
} }
impl Config { impl Default for Config {
pub fn new() -> Self { fn default() -> Self {
Config { Self {
mux: ClockSrc::MSI(MSIRange::default()), mux: ClockSrc::MSI(MSIRange::default()),
ahb_pre: Default::default(), ahb_pre: Default::default(),
apb1_pre: Default::default(), apb1_pre: Default::default(),
@ -293,12 +293,6 @@ impl Config {
} }
} }
impl Default for Config {
fn default() -> Self {
Config::new()
}
}
/// Extension trait that freezes the `RCC` peripheral with provided clocks configuration /// Extension trait that freezes the `RCC` peripheral with provided clocks configuration
pub trait RccExt { pub trait RccExt {
fn freeze(self, config: Config, power: &Power) -> Clocks; fn freeze(self, config: Config, power: &Power) -> Clocks;

View File

@ -86,10 +86,10 @@ impl Into<u8> for AHBPrescaler {
/// Clocks configutation /// Clocks configutation
pub struct Config { pub struct Config {
mux: ClockSrc, pub mux: ClockSrc,
ahb_pre: AHBPrescaler, pub ahb_pre: AHBPrescaler,
apb1_pre: APBPrescaler, pub apb1_pre: APBPrescaler,
apb2_pre: APBPrescaler, pub apb2_pre: APBPrescaler,
} }
impl Default for Config { impl Default for Config {
@ -104,32 +104,6 @@ impl Default for Config {
} }
} }
impl Config {
#[inline]
pub fn clock_src(mut self, mux: ClockSrc) -> Self {
self.mux = mux;
self
}
#[inline]
pub fn ahb_pre(mut self, pre: AHBPrescaler) -> Self {
self.ahb_pre = pre;
self
}
#[inline]
pub fn apb1_pre(mut self, pre: APBPrescaler) -> Self {
self.apb1_pre = pre;
self
}
#[inline]
pub fn apb2_pre(mut self, pre: APBPrescaler) -> Self {
self.apb2_pre = pre;
self
}
}
/// RCC peripheral /// RCC peripheral
pub struct Rcc<'d> { pub struct Rcc<'d> {
_rb: peripherals::RCC, _rb: peripherals::RCC,

View File

@ -87,10 +87,10 @@ impl Into<u8> for AHBPrescaler {
/// Clocks configutation /// Clocks configutation
pub struct Config { pub struct Config {
mux: ClockSrc, pub mux: ClockSrc,
ahb_pre: AHBPrescaler, pub ahb_pre: AHBPrescaler,
apb1_pre: APBPrescaler, pub apb1_pre: APBPrescaler,
apb2_pre: APBPrescaler, pub apb2_pre: APBPrescaler,
} }
impl Default for Config { impl Default for Config {
@ -105,32 +105,6 @@ impl Default for Config {
} }
} }
impl Config {
#[inline]
pub fn clock_src(mut self, mux: ClockSrc) -> Self {
self.mux = mux;
self
}
#[inline]
pub fn ahb_pre(mut self, pre: AHBPrescaler) -> Self {
self.ahb_pre = pre;
self
}
#[inline]
pub fn apb1_pre(mut self, pre: APBPrescaler) -> Self {
self.apb1_pre = pre;
self
}
#[inline]
pub fn apb2_pre(mut self, pre: APBPrescaler) -> Self {
self.apb2_pre = pre;
self
}
}
/// RCC peripheral /// RCC peripheral
pub struct Rcc<'d> { pub struct Rcc<'d> {
_rb: peripherals::RCC, _rb: peripherals::RCC,
@ -257,13 +231,6 @@ impl RccExt for RCC {
pub unsafe fn init(config: Config) { pub unsafe fn init(config: Config) {
let r = <peripherals::RCC as embassy::util::Steal>::steal(); let r = <peripherals::RCC as embassy::util::Steal>::steal();
let rcc = pac::RCC;
rcc.ahb2enr().write(|w| {
w.set_gpioaen(true);
w.set_gpioben(true);
w.set_gpiocen(true);
w.set_gpiohen(true);
});
let clocks = r.freeze(config); let clocks = r.freeze(config);
set_freqs(clocks); set_freqs(clocks);
} }

View File

@ -34,8 +34,6 @@ pub fn config() -> Config {
config.rcc.sys_ck = Some(400.mhz().into()); config.rcc.sys_ck = Some(400.mhz().into());
config.rcc.hclk = Some(400.mhz().into()); config.rcc.hclk = Some(400.mhz().into());
config.rcc.pll1.q_ck = Some(100.mhz().into()); config.rcc.pll1.q_ck = Some(100.mhz().into());
config.rcc.enable_dma1 = true;
config.rcc.enable_dma2 = true;
config.rcc.pclk1 = Some(100.mhz().into()); config.rcc.pclk1 = Some(100.mhz().into());
config.rcc.pclk2 = Some(100.mhz().into()); config.rcc.pclk2 = Some(100.mhz().into());
config.rcc.pclk3 = Some(100.mhz().into()); config.rcc.pclk3 = Some(100.mhz().into());

View File

@ -23,6 +23,5 @@ pub fn config() -> Config {
let mut config = Config::default(); let mut config = Config::default();
config.rcc.sys_ck = Some(400.mhz().into()); config.rcc.sys_ck = Some(400.mhz().into());
config.rcc.pll1.q_ck = Some(100.mhz().into()); config.rcc.pll1.q_ck = Some(100.mhz().into());
config.rcc.enable_dma1 = true;
config config
} }

View File

@ -25,7 +25,7 @@ use lorawan_encoding::default_crypto::DefaultFactory as Crypto;
fn config() -> embassy_stm32::Config { fn config() -> embassy_stm32::Config {
let mut config = embassy_stm32::Config::default(); let mut config = embassy_stm32::Config::default();
config.rcc = config.rcc.clock_src(embassy_stm32::rcc::ClockSrc::HSI16); config.rcc.mux = embassy_stm32::rcc::ClockSrc::HSI16;
config config
} }

View File

@ -14,13 +14,13 @@ use example_common::*;
fn config() -> Config { fn config() -> Config {
let mut config = Config::default(); let mut config = Config::default();
config.rcc = config.rcc.clock_src(ClockSrc::PLL( config.rcc.mux = ClockSrc::PLL(
PLLSource::HSI16, PLLSource::HSI16,
PLLClkDiv::Div2, PLLClkDiv::Div2,
PLLSrcDiv::Div1, PLLSrcDiv::Div1,
PLLMul::Mul8, PLLMul::Mul8,
Some(PLLClkDiv::Div2), Some(PLLClkDiv::Div2),
)); );
config config
} }

View File

@ -23,7 +23,7 @@ use lorawan_encoding::default_crypto::DefaultFactory as Crypto;
fn config() -> embassy_stm32::Config { fn config() -> embassy_stm32::Config {
let mut config = embassy_stm32::Config::default(); let mut config = embassy_stm32::Config::default();
config.rcc = config.rcc.clock_src(embassy_stm32::rcc::ClockSrc::HSI16); config.rcc.mux = embassy_stm32::rcc::ClockSrc::HSI16;
config config
} }

View File

@ -66,7 +66,7 @@ const TX_PARAMS: TxParams = TxParams::new()
fn config() -> embassy_stm32::Config { fn config() -> embassy_stm32::Config {
let mut config = embassy_stm32::Config::default(); let mut config = embassy_stm32::Config::default();
config.rcc = config.rcc.clock_src(embassy_stm32::rcc::ClockSrc::HSE32); config.rcc.mux = embassy_stm32::rcc::ClockSrc::HSE32;
config config
} }