Skip to content

Commit fca3989

Browse files
authored
allow selecting any clock source when freezing rcc configuration (#148)
1 parent 69a9c70 commit fca3989

File tree

3 files changed

+26
-25
lines changed

3 files changed

+26
-25
lines changed

src/can.rs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,6 @@ mod sealed {
1111
pub trait Rx<CAN> {}
1212
}
1313

14-
/// Select an FDCAN Clock Source
15-
#[allow(clippy::upper_case_acronyms)]
16-
#[allow(dead_code)]
17-
enum FdCanClockSource {
18-
/// Select HSE as the FDCAN clock source
19-
HSE = 0b00,
20-
/// Select PLL "Q" clock as the FDCAN clock source
21-
PLLQ = 0b01,
22-
/// Select "P" clock as the FDCAN clock source
23-
PCLK = 0b10,
24-
//Reserved = 0b10,
25-
}
26-
2714
/// Storage type for the CAN controller
2815
#[derive(Debug)]
2916
pub struct Can<FDCAN> {
@@ -55,18 +42,6 @@ where
5542
{
5643
Self::enable(&rcc.rb);
5744

58-
if rcc.rb.ccipr.read().fdcansel().is_hse() {
59-
// Select P clock as FDCAN clock source
60-
rcc.rb.ccipr.modify(|_, w| {
61-
// This is sound, as `FdCanClockSource` only contains valid values for this field.
62-
unsafe {
63-
w.fdcansel().bits(FdCanClockSource::PCLK as u8);
64-
}
65-
66-
w
67-
});
68-
}
69-
7045
self.fdcan_unchecked()
7146
}
7247

src/rcc/config.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,18 @@ impl Default for PllConfig {
325325
}
326326
}
327327

328+
/// FDCAN Clock Source
329+
#[allow(clippy::upper_case_acronyms)]
330+
pub enum FdCanClockSource {
331+
/// Select HSE as the FDCAN clock source
332+
HSE = 0b00,
333+
/// Select PLL "Q" clock as the FDCAN clock source
334+
PLLQ = 0b01,
335+
/// Select "P" clock as the FDCAN clock source
336+
PCLK = 0b10,
337+
//Reserved = 0b10,
338+
}
339+
328340
/// Clocks configutation
329341
pub struct Config {
330342
pub(crate) sys_mux: SysClockSrc,
@@ -335,6 +347,8 @@ pub struct Config {
335347

336348
/// Required for f_sys > 150MHz
337349
pub(crate) enable_boost: bool,
350+
351+
pub(crate) fdcansel: FdCanClockSource,
338352
}
339353

340354
impl Config {
@@ -379,6 +393,11 @@ impl Config {
379393
self.enable_boost = enable_boost;
380394
self
381395
}
396+
397+
pub fn fdcan_src(mut self, mux: FdCanClockSource) -> Self {
398+
self.fdcansel = mux;
399+
self
400+
}
382401
}
383402

384403
impl Default for Config {
@@ -390,6 +409,7 @@ impl Default for Config {
390409
apb1_psc: Prescaler::NotDivided,
391410
apb2_psc: Prescaler::NotDivided,
392411
enable_boost: false,
412+
fdcansel: FdCanClockSource::HSE,
393413
}
394414
}
395415
}

src/rcc/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,12 @@ impl Rcc {
216216
_ => apb2_freq * 2,
217217
};
218218

219+
// Configure FDCAN clock source.
220+
self.rb.ccipr.modify(|_, w| unsafe {
221+
// This is sound, as `FdCanClockSource` only contains valid values for this field.
222+
w.fdcansel().bits(rcc_cfg.fdcansel as u8)
223+
});
224+
219225
Rcc {
220226
rb: self.rb,
221227
clocks: Clocks {

0 commit comments

Comments
 (0)