File tree Expand file tree Collapse file tree 3 files changed +26
-25
lines changed
Expand file tree Collapse file tree 3 files changed +26
-25
lines changed Original file line number Diff line number Diff 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 ) ]
2916pub struct Can < FDCAN > {
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
Original file line number Diff line number Diff 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
329341pub 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
340354impl 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
384403impl 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}
Original file line number Diff line number Diff 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 {
You can’t perform that action at this time.
0 commit comments