@@ -21,13 +21,7 @@ impl RccExt for RCC {
21
21
apb1 : APB1 { _0 : ( ) } ,
22
22
apb2 : APB2 { _0 : ( ) } ,
23
23
bdcr : BDCR { _0 : ( ) } ,
24
- cfgr : CFGR {
25
- hse : None ,
26
- hclk : None ,
27
- pclk1 : None ,
28
- pclk2 : None ,
29
- sysclk : None ,
30
- } ,
24
+ cfgr : CFGR :: default ( ) ,
31
25
}
32
26
}
33
27
}
@@ -87,7 +81,7 @@ impl AHB {
87
81
/// ```
88
82
/// let dp = pac::Peripherals::take().unwrap();
89
83
/// let rcc = dp.RCC.constrain();
90
- /// use_ahb (&mut rcc.apb1)
84
+ /// use_apb1 (&mut rcc.apb1)
91
85
/// ```
92
86
pub struct APB1 {
93
87
_0 : ( ) ,
@@ -112,7 +106,7 @@ impl APB1 {
112
106
/// ```
113
107
/// let dp = pac::Peripherals::take().unwrap();
114
108
/// let rcc = dp.RCC.constrain();
115
- /// use_ahb (&mut rcc.apb2)
109
+ /// use_apb2 (&mut rcc.apb2)
116
110
/// ```
117
111
pub struct APB2 {
118
112
_0 : ( ) ,
@@ -212,10 +206,13 @@ impl BDCR {
212
206
/// ```
213
207
/// let dp = pac::Peripherals::take().unwrap();
214
208
/// let rcc = dp.RCC.constrain();
215
- /// use_ahb (&mut rcc.cfgr)
209
+ /// use_cfgr (&mut rcc.cfgr)
216
210
/// ```
211
+ #[ derive( Default ) ]
217
212
pub struct CFGR {
218
213
hse : Option < u32 > ,
214
+ hse_bypass : bool ,
215
+ css : bool ,
219
216
hclk : Option < u32 > ,
220
217
pclk1 : Option < u32 > ,
221
218
pclk2 : Option < u32 > ,
@@ -296,6 +293,24 @@ impl CFGR {
296
293
self
297
294
}
298
295
296
+ /// Enable HSE bypass.
297
+ /// Uses user provided clock signal instead of an external oscillator.
298
+ /// OSC_OUT pin is free and can be used as GPIO.
299
+ /// No effect if HSE is not enabled.
300
+ pub fn bypass_hse ( mut self ) -> Self {
301
+ self . hse_bypass = true ;
302
+ self
303
+ }
304
+
305
+ /// Enable CSS (Clock Security System).
306
+ /// System clock is automatically switched to HSI and an interrupt (CSSI) is generated
307
+ /// when HSE clock failure is detected.
308
+ /// No effect if HSE is not enabled.
309
+ pub fn enable_css ( mut self ) -> Self {
310
+ self . css = true ;
311
+ self
312
+ }
313
+
299
314
/// Sets a frequency for the AHB bus
300
315
pub fn hclk < F > ( mut self , freq : F ) -> Self
301
316
where
@@ -376,10 +391,11 @@ impl CFGR {
376
391
}
377
392
378
393
// PLL_MUL maximal value is 16
379
- assert ! ( divisor <= 16 ) ;
380
- // PRE_DIV maximal value is 16
381
394
assert ! ( multiplier <= 16 ) ;
382
395
396
+ // PRE_DIV maximal value is 16
397
+ assert ! ( divisor <= 16 ) ;
398
+
383
399
( multiplier, Some ( divisor) )
384
400
}
385
401
// HSI division is always divided by 2 and has no adjustable division
@@ -583,9 +599,13 @@ impl CFGR {
583
599
584
600
let rcc = unsafe { & * RCC :: ptr ( ) } ;
585
601
602
+ // enable HSE and wait for it to be ready
586
603
if self . hse . is_some ( ) {
587
- // enable HSE and wait for it to be ready
588
- rcc. cr . modify ( |_, w| w. hseon ( ) . on ( ) ) ;
604
+ rcc. cr . modify ( |_, w| {
605
+ w. hsebyp ( ) . bit ( self . hse_bypass ) ;
606
+ w. csson ( ) . bit ( self . css ) ;
607
+ w. hseon ( ) . on ( )
608
+ } ) ;
589
609
590
610
while rcc. cr . read ( ) . hserdy ( ) . is_not_ready ( ) { }
591
611
}
0 commit comments