@@ -54,11 +54,10 @@ impl RccExt for RCC {
5454 apb2 : APB2 { _0 : ( ) } ,
5555 bdcr : BDCR { _0 : ( ) } ,
5656 csr : CSR { _0 : ( ) } ,
57- #[ cfg( not( feature = "stm32l47x " ) ) ]
57+ #[ cfg( not( feature = "stm32l4x6 " ) ) ]
5858 crrcr : CRRCR { _0 : ( ) } ,
5959 cfgr : CFGR {
6060 hclk : None ,
61- #[ cfg( not( feature = "stm32l47x" ) ) ]
6261 hsi48 : false ,
6362 msi : None ,
6463 lsi : false ,
@@ -92,7 +91,7 @@ pub struct Rcc {
9291 /// Control/Status Register
9392 pub csr : CSR ,
9493 /// Clock recovery RC register
95- #[ cfg( not( feature = "stm32l47x " ) ) ]
94+ #[ cfg( not( feature = "stm32l4x6 " ) ) ]
9695 pub crrcr : CRRCR ,
9796}
9897
@@ -111,12 +110,12 @@ impl CSR {
111110}
112111
113112/// Clock recovery RC register
114- #[ cfg( not( feature = "stm32l47x " ) ) ]
113+ #[ cfg( not( feature = "stm32l4x6 " ) ) ]
115114pub struct CRRCR {
116115 _0 : ( ) ,
117116}
118117
119- #[ cfg( not( feature = "stm32l47x " ) ) ]
118+ #[ cfg( not( feature = "stm32l4x6 " ) ) ]
120119impl CRRCR {
121120 // TODO remove `allow`
122121 #[ allow( dead_code) ]
@@ -263,8 +262,6 @@ const HSI: u32 = 16_000_000; // Hz
263262/// Clock configuration
264263pub struct CFGR {
265264 hclk : Option < u32 > ,
266- // should we use an option? it can really only be on/off
267- #[ cfg( not( feature = "stm32l47x" ) ) ]
268265 hsi48 : bool ,
269266 msi : Option < MsiFreq > ,
270267 lsi : bool ,
@@ -284,8 +281,8 @@ impl CFGR {
284281 self
285282 }
286283
287- /// Enable the 48Mh USB, RNG, SDMMC clock source.
288- #[ cfg( not( feature = "stm32l47x " ) ) ]
284+ /// Enable the 48Mh USB, RNG, SDMMC clock source. Not available on stm32l4x6 series
285+ #[ cfg( not( feature = "stm32l4x6 " ) ) ]
289286 pub fn hsi48 ( mut self , on : bool ) -> Self
290287 {
291288 self . hsi48 = on;
@@ -343,7 +340,7 @@ impl CFGR {
343340 }
344341
345342 /// Freezes the clock configuration, making it effective
346- pub fn common_freeze ( & self , acr : & mut ACR ) -> ( Hertz , Hertz , Hertz , u8 , u8 , Hertz ) {
343+ pub fn freeze ( & self , acr : & mut ACR ) -> Clocks {
347344
348345 let pllconf = if self . pllcfg . is_none ( ) {
349346 let plln = ( 2 * self . sysclk . unwrap_or ( HSI ) ) / HSI ;
@@ -507,64 +504,33 @@ impl CFGR {
507504 while rcc. cr . read ( ) . msirdy ( ) . bit_is_clear ( ) { }
508505 }
509506
510- ( Hertz ( hclk) , Hertz ( pclk1) , Hertz ( pclk2) , ppre1, ppre2, Hertz ( sysclk) )
511- }
512-
513-
514- #[ cfg( not( feature = "stm32l47x" ) ) ]
515- pub fn freeze ( self , acr : & mut ACR ) -> Clocks {
516-
517- let ( hclk, pclk1, pclk2, ppre1, ppre2, sysclk) = self . common_freeze ( acr) ;
518- let mut usb_rng = false ;
519-
520- let rcc = unsafe { & * RCC :: ptr ( ) } ;
521- // Turn on USB, RNG Clock using the HSI48CLK source (default)
522- if !cfg ! ( feature = "stm32l47x" ) && self . hsi48 {
523- // p. 180 in ref-manual
524- rcc. crrcr . modify ( |_, w| w. hsi48on ( ) . set_bit ( ) ) ;
525- // Wait until HSI48 is running
526- while rcc. crrcr . read ( ) . hsi48rdy ( ) . bit_is_clear ( ) { }
527- usb_rng = true ;
528- }
529-
530- Clocks {
531- hclk,
532- lsi : self . lsi ,
533- hsi48 : self . hsi48 ,
534- usb_rng,
535- msi : self . msi ,
536- pclk1,
537- pclk2,
538- ppre1,
539- ppre2,
540- sysclk,
507+ #[ cfg( not( feature = "stm32l4x6" ) ) ]
508+ {
509+ // Turn on USB, RNG Clock using the HSI48 CLK source (default)
510+ if self . hsi48 {
511+ // p. 180 in ref-manual
512+ rcc. crrcr . modify ( |_, w| w. hsi48on ( ) . set_bit ( ) ) ;
513+ // Wait until HSI48 is running
514+ while rcc. crrcr . read ( ) . hsi48rdy ( ) . bit_is_clear ( ) { }
515+ }
541516 }
542- }
543-
544- #[ cfg( feature = "stm32l47x" ) ]
545- pub fn freeze ( self , acr : & mut ACR ) -> Clocks {
546517
547- let ( hclk, pclk1, pclk2, ppre1, ppre2, sysclk) = self . common_freeze ( acr) ;
548-
549- let mut usb_rng = false ;
550-
551- let rcc = unsafe { & * RCC :: ptr ( ) } ;
552518 // Select MSI as clock source for usb48, rng ...
553519 if let Some ( MsiFreq :: RANGE48M ) = self . msi {
554- unsafe { rcc. ccipr . modify ( |_, w| w. clk48sel ( ) . bits ( 0b11 ) ) } ;
555- usb_rng = true ;
520+ unsafe { rcc. ccipr . modify ( |_, w| w. clk48sel ( ) . bits ( MsiFreq :: RANGE48M as u8 ) ) } ;
556521 }
522+ //TODO proper clk48sel and other selects
557523
558524 Clocks {
559- hclk,
525+ hclk : Hertz ( hclk ) ,
560526 lsi : self . lsi ,
561- usb_rng,
562527 msi : self . msi ,
563- pclk1,
564- pclk2,
565- ppre1,
566- ppre2,
567- sysclk,
528+ hsi48 : self . hsi48 ,
529+ pclk1 : Hertz ( pclk1) ,
530+ pclk2 : Hertz ( pclk2) ,
531+ ppre1 : ppre1,
532+ ppre2 : ppre2,
533+ sysclk : Hertz ( sysclk) ,
568534 }
569535 }
570536
@@ -587,9 +553,7 @@ pub struct PllConfig {
587553#[ derive( Clone , Copy , Debug ) ]
588554pub struct Clocks {
589555 hclk : Hertz ,
590- #[ cfg( not( feature = "stm32l47x" ) ) ]
591556 hsi48 : bool ,
592- usb_rng : bool ,
593557 msi : Option < MsiFreq > ,
594558 lsi : bool ,
595559 pclk1 : Hertz ,
@@ -608,14 +572,13 @@ impl Clocks {
608572 }
609573
610574 /// Returns status of HSI48
611- #[ cfg( not( feature = "stm32l47x" ) ) ]
612575 pub fn hsi48 ( & self ) -> bool {
613576 self . hsi48
614577 }
615578
616- /// Returns if usb rng clock is available
617- pub fn usb_rng ( & self ) -> bool {
618- self . usb_rng
579+ // Returns the status of the MSI
580+ pub fn msi ( & self ) -> Option < MsiFreq > {
581+ self . msi
619582 }
620583
621584 /// Returns status of HSI48
0 commit comments