@@ -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
}
@@ -214,8 +208,11 @@ impl BDCR {
214
208
/// let rcc = dp.RCC.constrain();
215
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 > ,
@@ -286,13 +283,34 @@ fn into_pre_div(div: u8) -> cfgr2::PREDIV_A {
286
283
}
287
284
288
285
impl CFGR {
289
- /// Uses HSE (external oscillator) instead of HSI (internal RC oscillator) as the clock source.
286
+ /// Enable HSE (external clock) in crystal mode.
287
+ /// Uses external oscillator instead of HSI (internal RC oscillator) as the clock source.
290
288
/// Will result in a hang if an external oscillator is not connected or it fails to start.
291
289
pub fn use_hse < F > ( mut self , freq : F ) -> Self
292
290
where
293
291
F : Into < Hertz > ,
294
292
{
295
293
self . hse = Some ( freq. into ( ) . 0 ) ;
294
+ self . hse_bypass = false ;
295
+ self
296
+ }
297
+
298
+ /// Enable HSE (external clock) in bypass mode.
299
+ /// Uses user provided clock instead of HSI (internal RC oscillator) as the clock source.
300
+ /// Will result in a hang if an external clock source is not connected.
301
+ pub fn use_hse_bypass < F > ( mut self , freq : F ) -> Self
302
+ where
303
+ F : Into < Hertz > ,
304
+ {
305
+ self . hse = Some ( freq. into ( ) . 0 ) ;
306
+ self . hse_bypass = true ;
307
+ self
308
+ }
309
+
310
+ /// Enable CSS (Clock Security System).
311
+ /// No effect if HSE is not enabled.
312
+ pub fn enable_css ( mut self ) -> Self {
313
+ self . css = true ;
296
314
self
297
315
}
298
316
@@ -584,9 +602,17 @@ impl CFGR {
584
602
585
603
let rcc = unsafe { & * RCC :: ptr ( ) } ;
586
604
605
+ // enable HSE and wait for it to be ready
587
606
if self . hse . is_some ( ) {
588
- // enable HSE and wait for it to be ready
589
- rcc. cr . modify ( |_, w| w. hseon ( ) . on ( ) ) ;
607
+ rcc. cr . modify ( |_, w| {
608
+ if self . css {
609
+ w. csson ( ) . on ( ) ;
610
+ }
611
+ if self . hse_bypass {
612
+ w. hsebyp ( ) . bypassed ( ) ;
613
+ }
614
+ w. hseon ( ) . on ( )
615
+ } ) ;
590
616
591
617
while rcc. cr . read ( ) . hserdy ( ) . is_not_ready ( ) { }
592
618
}
0 commit comments