@@ -261,17 +261,32 @@ impl BDCR {
261
261
/// let rcc = dp.RCC.constrain();
262
262
/// use_cfgr(&mut rcc.cfgr)
263
263
/// ```
264
- #[ derive( Default ) ]
265
264
pub struct CFGR {
266
265
hse : Option < u32 > ,
267
266
hse_bypass : bool ,
267
+ pll_bypass : bool ,
268
268
css : bool ,
269
269
hclk : Option < u32 > ,
270
270
pclk1 : Option < u32 > ,
271
271
pclk2 : Option < u32 > ,
272
272
sysclk : Option < u32 > ,
273
273
}
274
274
275
+ impl Default for CFGR {
276
+ fn default ( ) -> Self {
277
+ Self {
278
+ hse : None ,
279
+ hse_bypass : false ,
280
+ pll_bypass : true ,
281
+ css : false ,
282
+ hclk : None ,
283
+ pclk1 : None ,
284
+ pclk2 : None ,
285
+ sysclk : None ,
286
+ }
287
+ }
288
+ }
289
+
275
290
pub ( crate ) struct PllConfig {
276
291
src : cfgr:: PLLSRC_A ,
277
292
mul : cfgr:: PLLMUL_A ,
@@ -350,6 +365,12 @@ impl CFGR {
350
365
self
351
366
}
352
367
368
+ /// Set this to disallow bypass the PLLCLK for the systemclock generation.
369
+ pub fn use_pll ( mut self ) -> Self {
370
+ self . pll_bypass = false ;
371
+ self
372
+ }
373
+
353
374
/// Enable `HSE` bypass.
354
375
///
355
376
/// Uses user provided clock signal instead of an external oscillator.
@@ -602,9 +623,11 @@ impl CFGR {
602
623
// because the two valid USB clocks, 72 Mhz and 48 Mhz, can't be generated
603
624
// directly from neither the internal rc (8 Mhz) nor the external
604
625
// Oscillator (max 32 Mhz), without using the PLL.
605
- ( Some ( sysclk) , Some ( hse) ) if sysclk == hse => ( hse, cfgr:: SW_A :: HSE , None ) ,
626
+ ( Some ( sysclk) , Some ( hse) ) if sysclk == hse && self . pll_bypass => {
627
+ ( hse, cfgr:: SW_A :: HSE , None )
628
+ }
606
629
// No need to use the PLL
607
- ( Some ( sysclk) , None ) if sysclk == HSI . integer ( ) => {
630
+ ( Some ( sysclk) , None ) if sysclk == HSI . integer ( ) && self . pll_bypass => {
608
631
( HSI . integer ( ) , cfgr:: SW_A :: HSI , None )
609
632
}
610
633
( Some ( sysclk) , _) => {
@@ -758,6 +781,7 @@ impl CFGR {
758
781
ppre2,
759
782
sysclk : Hertz ( sysclk) ,
760
783
usbclk_valid,
784
+ pll_bypass : self . pll_bypass ,
761
785
}
762
786
}
763
787
}
@@ -775,6 +799,7 @@ pub struct Clocks {
775
799
ppre2 : u8 ,
776
800
sysclk : Hertz ,
777
801
usbclk_valid : bool ,
802
+ pll_bypass : bool ,
778
803
}
779
804
780
805
// TODO(Sh3Rm4n) Add defmt support for embedded-time!
@@ -784,14 +809,15 @@ impl defmt::Format for Clocks {
784
809
// Format as hexadecimal.
785
810
defmt:: write!(
786
811
f,
787
- "Clocks {{ hclk: {} Hz, pclk1: {} Hz, pclk2: {} Hz, ppre1: {:b}, ppre2: {:b}, sysclk: {} Hz, usbclk_valid: {} }}" ,
812
+ "Clocks {{ hclk: {} Hz, pclk1: {} Hz, pclk2: {} Hz, ppre1: {:b}, ppre2: {:b}, sysclk: {} Hz, usbclk_valid: {}, pll_bypass: {} }}" ,
788
813
self . hclk. integer( ) ,
789
814
self . pclk1. integer( ) ,
790
815
self . pclk2. integer( ) ,
791
816
self . ppre1,
792
817
self . ppre2,
793
818
self . sysclk. integer( ) ,
794
819
self . usbclk_valid,
820
+ self . pll_bypass,
795
821
) ;
796
822
}
797
823
}
@@ -830,6 +856,19 @@ impl Clocks {
830
856
self . sysclk
831
857
}
832
858
859
+ /// Returns the PLL clock if configured, else it returns `None`.
860
+ ///
861
+ /// The PLL clock is a source of the system clock, but it is not necessarily configured to be one.
862
+ pub fn pllclk ( & self ) -> Option < Hertz > {
863
+ if self . pll_bypass {
864
+ None
865
+ } else {
866
+ // The PLLCLK is the same as the sysclk, beccause
867
+ // the sysclk is using it as a source.
868
+ Some ( self . sysclk ( ) )
869
+ }
870
+ }
871
+
833
872
/// Returns whether the USBCLK clock frequency is valid for the USB peripheral
834
873
///
835
874
/// If the microcontroller does support USB, 48 Mhz or 72 Mhz have to be used
0 commit comments