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 {
11
11
pub trait Rx < CAN > { }
12
12
}
13
13
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
-
27
14
/// Storage type for the CAN controller
28
15
#[ derive( Debug ) ]
29
16
pub struct Can < FDCAN > {
55
42
{
56
43
Self :: enable ( & rcc. rb ) ;
57
44
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
-
70
45
self . fdcan_unchecked ( )
71
46
}
72
47
Original file line number Diff line number Diff line change @@ -325,6 +325,18 @@ impl Default for PllConfig {
325
325
}
326
326
}
327
327
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
+
328
340
/// Clocks configutation
329
341
pub struct Config {
330
342
pub ( crate ) sys_mux : SysClockSrc ,
@@ -335,6 +347,8 @@ pub struct Config {
335
347
336
348
/// Required for f_sys > 150MHz
337
349
pub ( crate ) enable_boost : bool ,
350
+
351
+ pub ( crate ) fdcansel : FdCanClockSource ,
338
352
}
339
353
340
354
impl Config {
@@ -379,6 +393,11 @@ impl Config {
379
393
self . enable_boost = enable_boost;
380
394
self
381
395
}
396
+
397
+ pub fn fdcan_src ( mut self , mux : FdCanClockSource ) -> Self {
398
+ self . fdcansel = mux;
399
+ self
400
+ }
382
401
}
383
402
384
403
impl Default for Config {
@@ -390,6 +409,7 @@ impl Default for Config {
390
409
apb1_psc : Prescaler :: NotDivided ,
391
410
apb2_psc : Prescaler :: NotDivided ,
392
411
enable_boost : false ,
412
+ fdcansel : FdCanClockSource :: HSE ,
393
413
}
394
414
}
395
415
}
Original file line number Diff line number Diff line change @@ -216,6 +216,12 @@ impl Rcc {
216
216
_ => apb2_freq * 2 ,
217
217
} ;
218
218
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
+
219
225
Rcc {
220
226
rb : self . rb ,
221
227
clocks : Clocks {
You can’t perform that action at this time.
0 commit comments