@@ -105,6 +105,7 @@ const HSI: u32 = 8_000_000; // Hz
105
105
///
106
106
/// **NOTE**: Currently, it is not guaranteed that the exact frequencies selected will be
107
107
/// used, only frequencies close to it.
108
+ #[ derive( Debug , Default , PartialEq ) ]
108
109
pub struct CFGR {
109
110
hse : Option < u32 > ,
110
111
hclk : Option < u32 > ,
@@ -335,7 +336,7 @@ impl BKP {
335
336
///
336
337
/// let clocks = rcc.cfgr.freeze(&mut flash.acr);
337
338
/// ```
338
- #[ derive( Clone , Copy ) ]
339
+ #[ derive( Clone , Copy , Debug , PartialEq ) ]
339
340
pub struct Clocks {
340
341
hclk : Hertz ,
341
342
pclk1 : Hertz ,
@@ -702,3 +703,39 @@ impl Config {
702
703
}
703
704
}
704
705
}
706
+
707
+ #[ test]
708
+ fn rcc_config_usb ( ) {
709
+ use crate :: time:: U32Ext ;
710
+ let cfgr = CFGR :: default ( )
711
+ . use_hse ( 8 . mhz ( ) )
712
+ . sysclk ( 48 . mhz ( ) )
713
+ . pclk1 ( 24 . mhz ( ) ) ;
714
+
715
+ let config = Config :: from_cfgr ( cfgr) ;
716
+ let config_expected = Config {
717
+ hse : Some ( 8_000_000 ) ,
718
+ pllmul : Some ( 4 ) ,
719
+ hpre : HPre :: DIV1 ,
720
+ ppre1 : PPre :: DIV2 ,
721
+ ppre2 : PPre :: DIV1 ,
722
+ #[ cfg( any( feature = "stm32f103" , feature = "connectivity" ) ) ]
723
+ usbpre : UsbPre :: DIV1 ,
724
+ adcpre : AdcPre :: DIV8 ,
725
+ } ;
726
+ assert_eq ! ( config, config_expected) ;
727
+
728
+ let clocks = config. get_clocks ( ) ;
729
+ let clocks_expected = Clocks {
730
+ hclk : 48 . mhz ( ) . into ( ) ,
731
+ pclk1 : 24 . mhz ( ) . into ( ) ,
732
+ pclk2 : 48 . mhz ( ) . into ( ) ,
733
+ ppre1 : 2 ,
734
+ ppre2 : 1 ,
735
+ sysclk : 48 . mhz ( ) . into ( ) ,
736
+ adcclk : 6 . mhz ( ) . into ( ) ,
737
+ #[ cfg( any( feature = "stm32f103" , feature = "connectivity" ) ) ]
738
+ usbclk_valid : true ,
739
+ } ;
740
+ assert_eq ! ( clocks, clocks_expected) ;
741
+ }
0 commit comments