Skip to content

join Rcc::freeze and freeze_raw #538

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
Add `RInto` trait and `Rmp` peripheral wrapper, add `remap` for peripherals. [#514] [#520]
Remove `RemapStruct`s. [#462] [#506] [#509]
- Use independent `Spi` and `SpiSlave` structures instead of `OP` generic [#462]
- Include `Clocks` in `Rcc`. Take `&mut Rcc/RCC` where possible [#498] [#536]
- Include `Clocks` in `Rcc`. Take `&mut Rcc/RCC` where possible, `freeze` takes `Config` or `RawConfig` [#498] [#536]
- Update to `stm32f1` v0.16.0 [#503] [#534]
- `Spi` now takes `Option<PIN>` for `SCK`, `MISO`, `MOSI` [#514],
add `SPIx::NoSck`, etc. [#537]
Expand Down
2 changes: 1 addition & 1 deletion examples/adc_temperature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn main() -> ! {

/*
// Alternative configuration using dividers and multipliers directly
let rcc = p.RCC.freeze_raw(
let rcc = p.RCC.freeze(
rcc::RawConfig {
hse: Some(8_000_000),
pllmul: Some(7),
Expand Down
27 changes: 11 additions & 16 deletions src/rcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@
fn constrain(self) -> Rcc;

/// Constrains the `RCC` peripheral and apply clock configuration
fn freeze(self, rcc_cfg: Config, acr: &mut ACR) -> Rcc;

/// Constrains the `RCC` peripheral and apply clock configuration
fn freeze_raw(self, rcc_cfg: RawConfig, acr: &mut ACR) -> Rcc;
fn freeze(self, rcc_cfg: impl Into<RawConfig>, acr: &mut ACR) -> Rcc;
}

impl RccExt for RCC {
Expand All @@ -36,13 +33,9 @@
}
}

fn freeze(self, rcc_cfg: Config, acr: &mut ACR) -> Rcc {
fn freeze(self, rcc_cfg: impl Into<RawConfig>, acr: &mut ACR) -> Rcc {
self.constrain().freeze(rcc_cfg, acr)
}

fn freeze_raw(self, rcc_cfg: RawConfig, acr: &mut ACR) -> Rcc {
self.constrain().freeze_raw(rcc_cfg, acr)
}
}

/// Constrained RCC peripheral
Expand Down Expand Up @@ -214,13 +207,8 @@
/// let clocks = rcc.cfgr.freeze(&mut flash.acr);
/// ```
#[inline(always)]
pub fn freeze(self, config: Config, acr: &mut ACR) -> Self {
let cfg = RawConfig::from_cfgr(config);
self.freeze_raw(cfg, acr)
}

#[inline(always)]
pub fn freeze_raw(self, cfg: RawConfig, acr: &mut ACR) -> Self {
pub fn freeze(self, cfg: impl Into<RawConfig>, acr: &mut ACR) -> Self {

Check warning on line 210 in src/rcc.rs

View workflow job for this annotation

GitHub Actions / check (stm32f100, stable)

unused variable: `acr`

Check warning on line 210 in src/rcc.rs

View workflow job for this annotation

GitHub Actions / check (stm32f100, stable)

unused variable: `acr`

Check warning on line 210 in src/rcc.rs

View workflow job for this annotation

GitHub Actions / check (stm32f101, stable)

unused variable: `acr`

Check warning on line 210 in src/rcc.rs

View workflow job for this annotation

GitHub Actions / check (stm32f101, stable)

unused variable: `acr`
let cfg = cfg.into();
let clocks = cfg.get_clocks();
// adjust flash wait states
#[cfg(any(feature = "stm32f103", feature = "connectivity"))]
Expand Down Expand Up @@ -631,6 +619,13 @@
pub type UsbPre = rcc::cfgr::OTGFSPRE;
pub type AdcPre = rcc::cfgr::ADCPRE;

impl From<Config> for RawConfig {
#[inline(always)]
fn from(cfgr: Config) -> Self {
Self::from_cfgr(cfgr)
}
}

impl RawConfig {
pub const fn from_cfgr(cfgr: Config) -> Self {
let hse = cfgr.hse;
Expand Down
Loading