Skip to content

Commit 17ee16a

Browse files
committed
rcc_shared_m & rcc_i2s_apb features
1 parent 4f1caae commit 17ee16a

File tree

4 files changed

+57
-72
lines changed

4 files changed

+57
-72
lines changed

Cargo.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ gpio-f401 = [
167167
"tim9",
168168
"tim10",
169169
"tim11",
170+
"rcc_shared_m"
170171
]
171172
gpio-f410 = [
172173
"dac",
@@ -230,6 +231,7 @@ gpio-f412 = [
230231
"tim13",
231232
"tim14",
232233
"usart3",
234+
"rcc_i2s_apb",
233235
]
234236
gpio-f413 = [
235237
"gpiod",
@@ -275,6 +277,7 @@ gpio-f413 = [
275277
"uart8",
276278
"uart9",
277279
"uart10",
280+
"rcc_i2s_apb",
278281
]
279282
gpio-f417 = [
280283
"gpiod",
@@ -313,6 +316,7 @@ gpio-f417 = [
313316
"usart3",
314317
"uart4",
315318
"uart5",
319+
"rcc_shared_m"
316320
]
317321
gpio-f427 = [
318322
"gpiod",
@@ -360,6 +364,7 @@ gpio-f427 = [
360364
"uart5",
361365
"uart7",
362366
"uart8",
367+
"rcc_shared_m"
363368
]
364369
gpio-f446 = [
365370
"gpiod",
@@ -401,6 +406,7 @@ gpio-f446 = [
401406
"usart3",
402407
"uart4",
403408
"uart5",
409+
"rcc_i2s_apb",
404410
]
405411
gpio-f469 = [
406412
"gpiod",
@@ -451,6 +457,7 @@ gpio-f469 = [
451457
"uart5",
452458
"uart7",
453459
"uart8",
460+
"rcc_shared_m"
454461
]
455462

456463
## Support monotonic timers and other stuff that can be used by [RTICv1 framework](https://crates.io/crates/cortex-m-rtic)
@@ -490,8 +497,12 @@ fsmc_lcd = ["dep:display-interface", "dep:display-interface-04"]
490497
## SDIO peripheral support. See [sdio-host](https://crates.io/crates/sdio-host)
491498
sdio-host = ["dep:sdio-host"]
492499

500+
# Next features are for internal use only!!!
501+
493502
dfsdm = []
494503
sai = []
504+
rcc_shared_m = []
505+
rcc_i2s_apb = []
495506

496507
adc2 = []
497508
adc3 = []

src/i2s.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ where
5656

5757
impl I2sFreq for rcc::APB1 {
5858
fn try_i2s_freq(clocks: &Clocks) -> Option<Hertz> {
59-
#[cfg(not(any(feature = "gpio-f412", feature = "gpio-f413", feature = "gpio-f446")))]
59+
#[cfg(not(feature = "rcc_i2s_apb"))]
6060
{
6161
clocks.i2s_clk()
6262
}
63-
#[cfg(any(feature = "gpio-f412", feature = "gpio-f413", feature = "gpio-f446"))]
63+
#[cfg(feature = "rcc_i2s_apb")]
6464
{
6565
clocks.i2s_apb1_clk()
6666
}
@@ -69,11 +69,11 @@ impl I2sFreq for rcc::APB1 {
6969

7070
impl I2sFreq for rcc::APB2 {
7171
fn try_i2s_freq(clocks: &Clocks) -> Option<Hertz> {
72-
#[cfg(not(any(feature = "gpio-f412", feature = "gpio-f413", feature = "gpio-f446")))]
72+
#[cfg(not(feature = "rcc_i2s_apb"))]
7373
{
7474
clocks.i2s_clk()
7575
}
76-
#[cfg(any(feature = "gpio-f412", feature = "gpio-f413", feature = "gpio-f446"))]
76+
#[cfg(feature = "rcc_i2s_apb")]
7777
{
7878
clocks.i2s_apb2_clk()
7979
}

src/rcc/f4/mod.rs

Lines changed: 29 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -217,15 +217,11 @@ impl RccExt for RCC {
217217
pll48clk: false,
218218
i2s_ckin: None,
219219

220-
#[cfg(not(any(
221-
feature = "gpio-f412",
222-
feature = "gpio-f413",
223-
feature = "gpio-f446"
224-
)))]
220+
#[cfg(not(feature = "rcc_i2s_apb"))]
225221
i2s_clk: None,
226-
#[cfg(any(feature = "gpio-f412", feature = "gpio-f413", feature = "gpio-f446"))]
222+
#[cfg(feature = "rcc_i2s_apb")]
227223
i2s_apb1_clk: None,
228-
#[cfg(any(feature = "gpio-f412", feature = "gpio-f413", feature = "gpio-f446"))]
224+
#[cfg(feature = "rcc_i2s_apb")]
229225
i2s_apb2_clk: None,
230226

231227
#[cfg(feature = "sai")]
@@ -317,11 +313,11 @@ pub struct CFGR {
317313

318314
i2s_ckin: Option<u32>,
319315

320-
#[cfg(not(any(feature = "gpio-f412", feature = "gpio-f413", feature = "gpio-f446")))]
316+
#[cfg(not(feature = "rcc_i2s_apb"))]
321317
i2s_clk: Option<u32>,
322-
#[cfg(any(feature = "gpio-f412", feature = "gpio-f413", feature = "gpio-f446"))]
318+
#[cfg(feature = "rcc_i2s_apb")]
323319
i2s_apb1_clk: Option<u32>,
324-
#[cfg(any(feature = "gpio-f412", feature = "gpio-f413", feature = "gpio-f446"))]
320+
#[cfg(feature = "rcc_i2s_apb")]
325321
i2s_apb2_clk: Option<u32>,
326322

327323
#[cfg(feature = "sai")]
@@ -387,7 +383,7 @@ impl CFGR {
387383
}
388384
}
389385

390-
#[cfg(not(any(feature = "gpio-f412", feature = "gpio-f413", feature = "gpio-f446")))]
386+
#[cfg(not(feature = "rcc_i2s_apb"))]
391387
impl CFGR {
392388
/// Selects an I2S clock frequency and enables the I2S clock.
393389
pub fn i2s_clk(mut self, freq: Hertz) -> Self {
@@ -396,7 +392,7 @@ impl CFGR {
396392
}
397393
}
398394

399-
#[cfg(any(feature = "gpio-f412", feature = "gpio-f413", feature = "gpio-f446"))]
395+
#[cfg(feature = "rcc_i2s_apb")]
400396
impl CFGR {
401397
/// Selects an I2S clock frequency for the first set of I2S instancesand enables the I2S clock.
402398
pub fn i2s_apb1_clk(mut self, freq: Hertz) -> Self {
@@ -468,7 +464,7 @@ impl CFGR {
468464
}
469465

470466
impl CFGR {
471-
#[cfg(any(feature = "gpio-f412", feature = "gpio-f413", feature = "gpio-f446"))]
467+
#[cfg(feature = "rcc_i2s_apb")]
472468
fn i2s_clocks(&self) -> I2sClocks {
473469
let i2s_apb1_ext = self.i2s_apb1_clk.is_some() && self.i2s_apb1_clk == self.i2s_ckin;
474470
let i2s_apb2_ext = self.i2s_apb2_clk.is_some() && self.i2s_apb2_clk == self.i2s_ckin;
@@ -492,7 +488,7 @@ impl CFGR {
492488
}
493489
}
494490

495-
#[cfg(not(any(feature = "gpio-f412", feature = "gpio-f413", feature = "gpio-f446")))]
491+
#[cfg(not(feature = "rcc_i2s_apb"))]
496492
fn i2s_clocks(&self) -> I2sClocks {
497493
let i2s_ext = self.i2s_clk.is_some() && self.i2s_clk == self.i2s_ckin;
498494
let pll_i2s_clk = if i2s_ext { None } else { self.i2s_clk };
@@ -716,11 +712,11 @@ impl CFGR {
716712
sysclk: sysclk.Hz(),
717713
pll48clk: plls.pll48clk.map(Hertz::from_raw),
718714

719-
#[cfg(not(any(feature = "gpio-f412", feature = "gpio-f413", feature = "gpio-f446")))]
715+
#[cfg(not(feature = "rcc_i2s_apb"))]
720716
i2s_clk: plls.i2s.i2s_clk.map(Hertz::from_raw),
721-
#[cfg(any(feature = "gpio-f412", feature = "gpio-f413", feature = "gpio-f446"))]
717+
#[cfg(feature = "rcc_i2s_apb")]
722718
i2s_apb1_clk: plls.i2s.apb1.i2s_clk.map(Hertz::from_raw),
723-
#[cfg(any(feature = "gpio-f412", feature = "gpio-f413", feature = "gpio-f446"))]
719+
#[cfg(feature = "rcc_i2s_apb")]
724720
i2s_apb2_clk: plls.i2s.apb2.i2s_clk.map(Hertz::from_raw),
725721

726722
#[cfg(feature = "sai")]
@@ -747,21 +743,21 @@ impl CFGR {
747743
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
748744
struct I2sClocks {
749745
/// True if the clock for the APB1 I2S instances is identical to I2S_CKIN.
750-
#[cfg(any(feature = "gpio-f412", feature = "gpio-f413", feature = "gpio-f446"))]
746+
#[cfg(feature = "rcc_i2s_apb")]
751747
i2s_apb1_ext: bool,
752748
/// True if the clock for the APB2 I2S instances is identical to I2S_CKIN.
753-
#[cfg(any(feature = "gpio-f412", feature = "gpio-f413", feature = "gpio-f446"))]
749+
#[cfg(feature = "rcc_i2s_apb")]
754750
i2s_apb2_ext: bool,
755751
/// True if the clock for I2S is identical to I2S_CKIN.
756-
#[cfg(not(any(feature = "gpio-f412", feature = "gpio-f413", feature = "gpio-f446")))]
752+
#[cfg(not(feature = "rcc_i2s_apb"))]
757753
i2s_ext: bool,
758754
/// Target for the I2S PLL output.
759755
pll_i2s_clk: Option<u32>,
760756
}
761757

762758
impl I2sClocks {
763759
fn real(&self, pll_i2s_clk: Option<u32>, i2s_ckin: Option<u32>) -> RealI2sClocks {
764-
#[cfg(any(feature = "gpio-f412", feature = "gpio-f413", feature = "gpio-f446"))]
760+
#[cfg(feature = "rcc_i2s_apb")]
765761
let clk = RealI2sClocks {
766762
apb1: RealI2sClock {
767763
i2s_ext: self.i2s_apb1_ext,
@@ -780,7 +776,7 @@ impl I2sClocks {
780776
},
781777
},
782778
};
783-
#[cfg(not(any(feature = "gpio-f412", feature = "gpio-f413", feature = "gpio-f446")))]
779+
#[cfg(not(feature = "rcc_i2s_apb"))]
784780
let clk = RealI2sClocks {
785781
i2s_ext: self.i2s_ext,
786782
i2s_clk: if self.i2s_ext { i2s_ckin } else { pll_i2s_clk },
@@ -796,27 +792,23 @@ struct RealI2sClock {
796792
i2s_clk: Option<u32>,
797793
}
798794

799-
#[cfg(any(feature = "gpio-f412", feature = "gpio-f413", feature = "gpio-f446"))]
795+
#[cfg(feature = "rcc_i2s_apb")]
800796
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
801797
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
802798
struct RealI2sClocks {
803799
apb1: RealI2sClock,
804800
apb2: RealI2sClock,
805801
}
806802

807-
#[cfg(not(any(feature = "gpio-f412", feature = "gpio-f413", feature = "gpio-f446")))]
803+
#[cfg(not(feature = "rcc_i2s_apb"))]
808804
use RealI2sClock as RealI2sClocks;
809805

810806
impl RealI2sClocks {
811807
fn config_clocksel(&self) {
812808
let rcc = unsafe { &*RCC::ptr() };
813809

814-
#[cfg(not(any(
815-
feature = "gpio-f410",
816-
feature = "gpio-f412",
817-
feature = "gpio-f413",
818-
feature = "gpio-f446",
819-
)))]
810+
#[cfg(not(feature = "gpio-f410"))]
811+
#[cfg(not(feature = "rcc_i2s_apb"))]
820812
rcc.cfgr().modify(|_, w| {
821813
if self.i2s_ext {
822814
w.i2ssrc().ckin()
@@ -832,7 +824,7 @@ impl RealI2sClocks {
832824
w.i2ssrc().pllclkr()
833825
}
834826
});
835-
#[cfg(any(feature = "gpio-f412", feature = "gpio-f413", feature = "gpio-f446"))]
827+
#[cfg(feature = "rcc_i2s_apb")]
836828
rcc.dckcfgr().modify(|_, w| {
837829
if self.apb1.i2s_ext {
838830
w.i2s1src().i2s_ckin()
@@ -933,11 +925,11 @@ pub struct Clocks {
933925
sysclk: Hertz,
934926
pll48clk: Option<Hertz>,
935927

936-
#[cfg(not(any(feature = "gpio-f412", feature = "gpio-f413", feature = "gpio-f446")))]
928+
#[cfg(not(feature = "rcc_i2s_apb"))]
937929
i2s_clk: Option<Hertz>,
938-
#[cfg(any(feature = "gpio-f412", feature = "gpio-f413", feature = "gpio-f446"))]
930+
#[cfg(feature = "rcc_i2s_apb")]
939931
i2s_apb1_clk: Option<Hertz>,
940-
#[cfg(any(feature = "gpio-f412", feature = "gpio-f413", feature = "gpio-f446"))]
932+
#[cfg(feature = "rcc_i2s_apb")]
941933
i2s_apb2_clk: Option<Hertz>,
942934

943935
#[cfg(feature = "sai")]
@@ -998,17 +990,17 @@ impl Clocks {
998990
}
999991

1000992
/// Returns the frequency of the I2S clock.
1001-
#[cfg(not(any(feature = "gpio-f412", feature = "gpio-f413", feature = "gpio-f446")))]
993+
#[cfg(not(feature = "rcc_i2s_apb"))]
1002994
pub fn i2s_clk(&self) -> Option<Hertz> {
1003995
self.i2s_clk
1004996
}
1005997
/// Returns the frequency of the first I2S clock (for the I2S peripherals on APB1).
1006-
#[cfg(any(feature = "gpio-f412", feature = "gpio-f413", feature = "gpio-f446"))]
998+
#[cfg(feature = "rcc_i2s_apb")]
1007999
pub fn i2s_apb1_clk(&self) -> Option<Hertz> {
10081000
self.i2s_apb1_clk
10091001
}
10101002
/// Returns the frequency of the second I2S clock (for the I2S peripherals on APB2).
1011-
#[cfg(any(feature = "gpio-f412", feature = "gpio-f413", feature = "gpio-f446"))]
1003+
#[cfg(feature = "rcc_i2s_apb")]
10121004
pub fn i2s_apb2_clk(&self) -> Option<Hertz> {
10131005
self.i2s_apb2_clk
10141006
}

src/rcc/f4/pll.rs

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -126,20 +126,17 @@ impl PllSetup {
126126
// All PLLs are completely independent.
127127
let main_pll = MainPll::fast_setup(pllsrcclk, cfgr.hse.is_some(), pllsysclk, cfgr.pll48clk);
128128

129-
#[cfg(any(feature = "gpio-f411", feature = "gpio-f412", feature = "gpio-f446"))]
129+
#[cfg(not(feature = "rcc_shared_m"))]
130130
let i2s_pll = I2sPll::setup(pllsrcclk, i2s_clocks.pll_i2s_clk);
131-
#[cfg(any(
132-
feature = "gpio-f401",
133-
feature = "gpio-f417",
134-
feature = "gpio-f427",
135-
feature = "gpio-f469",
136-
))]
131+
#[cfg(feature = "rcc_shared_m")]
137132
// We have separate PLLs, but they share the "M" divider.
138133
let i2s_pll = I2sPll::setup_shared_m(pllsrcclk, main_pll.m(), i2s_clocks.pll_i2s_clk);
139134

140-
#[cfg(any(feature = "gpio-f446"))]
135+
#[cfg(feature = "sai")]
136+
#[cfg(not(feature = "rcc_shared_m"))]
141137
let sai_pll = SaiPll::setup(pllsrcclk, sai_clocks.pll_sai_clk);
142-
#[cfg(any(feature = "gpio-f427", feature = "gpio-f469"))]
138+
#[cfg(feature = "sai")]
139+
#[cfg(feature = "rcc_shared_m")]
143140
let sai_pll = SaiPll::setup_shared_m(
144141
pllsrcclk,
145142
main_pll.m().or(i2s_pll.m()),
@@ -391,7 +388,7 @@ impl MainPll {
391388
}
392389
let div = crate::min_u32(crate::max_u32(div, min_div), max_div);
393390
let output = vco_out / div;
394-
let error = (output as i32 - target as i32).abs() as u32;
391+
let error = (output as i32 - target as i32).unsigned_abs();
395392
Some((div, output, error))
396393
}
397394
}
@@ -447,12 +444,7 @@ impl I2sPll {
447444
pll
448445
}
449446

450-
#[cfg(any(
451-
feature = "gpio-f401",
452-
feature = "gpio-f417",
453-
feature = "gpio-f427",
454-
feature = "gpio-f469",
455-
))]
447+
#[cfg(feature = "rcc_shared_m")]
456448
fn setup_shared_m(pllsrcclk: u32, m: Option<u32>, plli2sclk: Option<u32>) -> Self {
457449
// "m" is None if the main PLL is not in use.
458450
let Some(m) = m else {
@@ -483,21 +475,11 @@ impl I2sPll {
483475
fn apply_config(config: SingleOutputPll) {
484476
let rcc = unsafe { &*RCC::ptr() };
485477
// "M" may have been written before, but the value is identical.
486-
#[cfg(any(
487-
feature = "gpio-f401",
488-
feature = "gpio-f417",
489-
feature = "gpio-f427",
490-
feature = "gpio-f469",
491-
))]
478+
#[cfg(feature = "rcc_shared_m")]
492479
rcc.pllcfgr()
493480
.modify(|_, w| unsafe { w.pllm().bits(config.m) });
494481
rcc.plli2scfgr().modify(|_, w| unsafe {
495-
#[cfg(any(
496-
feature = "gpio-f411",
497-
feature = "gpio-f412",
498-
feature = "gpio-f413",
499-
feature = "gpio-f446",
500-
))]
482+
#[cfg(not(feature = "rcc_shared_m"))]
501483
w.plli2sm().bits(config.m);
502484
w.plli2sn().bits(config.n);
503485
w.plli2sr().bits(config.outdiv)
@@ -547,7 +529,7 @@ impl SaiPll {
547529
pll
548530
}
549531

550-
#[cfg(any(feature = "gpio-f427", feature = "gpio-f469"))]
532+
#[cfg(feature = "rcc_shared_m")]
551533
fn setup_shared_m(pllsrcclk: u32, m: Option<u32>, sai_clk: Option<u32>) -> Self {
552534
// "m" is None if both other PLLs are not in use.
553535
let Some(m) = m else {
@@ -592,11 +574,11 @@ impl SaiPll {
592574
rcc.dckcfgr()
593575
.modify(|_, w| w.pllsaidivq().set(saidiv as u8 - 1));
594576
// "M" may have been written before, but the value is identical.
595-
#[cfg(any(feature = "gpio-f427", feature = "gpio-f469"))]
577+
#[cfg(feature = "rcc_shared_m")]
596578
rcc.pllcfgr()
597579
.modify(|_, w| unsafe { w.pllm().bits(config.m) });
598580
rcc.pllsaicfgr().modify(|_, w| unsafe {
599-
#[cfg(feature = "gpio-f446")]
581+
#[cfg(not(feature = "rcc_shared_m"))]
600582
w.pllsaim().bits(config.m);
601583
w.pllsain().bits(config.n);
602584
w.pllsaiq().bits(config.outdiv)

0 commit comments

Comments
 (0)