@@ -54,11 +54,9 @@ impl RccExt for RCC {
54
54
apb2 : APB2 { _0 : ( ) } ,
55
55
bdcr : BDCR { _0 : ( ) } ,
56
56
csr : CSR { _0 : ( ) } ,
57
- #[ cfg( not( feature = "stm32l47x" ) ) ]
58
57
crrcr : CRRCR { _0 : ( ) } ,
59
58
cfgr : CFGR {
60
59
hclk : None ,
61
- #[ cfg( not( feature = "stm32l47x" ) ) ]
62
60
hsi48 : false ,
63
61
msi : None ,
64
62
lsi : false ,
@@ -92,7 +90,6 @@ pub struct Rcc {
92
90
/// Control/Status Register
93
91
pub csr : CSR ,
94
92
/// Clock recovery RC register
95
- #[ cfg( not( feature = "stm32l47x" ) ) ]
96
93
pub crrcr : CRRCR ,
97
94
}
98
95
@@ -111,12 +108,10 @@ impl CSR {
111
108
}
112
109
113
110
/// Clock recovery RC register
114
- #[ cfg( not( feature = "stm32l47x" ) ) ]
115
111
pub struct CRRCR {
116
112
_0 : ( ) ,
117
113
}
118
114
119
- #[ cfg( not( feature = "stm32l47x" ) ) ]
120
115
impl CRRCR {
121
116
// TODO remove `allow`
122
117
#[ allow( dead_code) ]
@@ -263,8 +258,6 @@ const HSI: u32 = 16_000_000; // Hz
263
258
/// Clock configuration
264
259
pub struct CFGR {
265
260
hclk : Option < u32 > ,
266
- // should we use an option? it can really only be on/off
267
- #[ cfg( not( feature = "stm32l47x" ) ) ]
268
261
hsi48 : bool ,
269
262
msi : Option < MsiFreq > ,
270
263
lsi : bool ,
@@ -284,8 +277,7 @@ impl CFGR {
284
277
self
285
278
}
286
279
287
- /// Enable the 48Mh USB, RNG, SDMMC clock source.
288
- #[ cfg( not( feature = "stm32l47x" ) ) ]
280
+ /// Enable the 48Mh USB, RNG, SDMMC clock source. Not available on all stm32l4x6 series
289
281
pub fn hsi48 ( mut self , on : bool ) -> Self
290
282
{
291
283
self . hsi48 = on;
@@ -343,7 +335,7 @@ impl CFGR {
343
335
}
344
336
345
337
/// Freezes the clock configuration, making it effective
346
- pub fn common_freeze ( & self , acr : & mut ACR ) -> ( Hertz , Hertz , Hertz , u8 , u8 , Hertz ) {
338
+ pub fn freeze ( & self , acr : & mut ACR ) -> Clocks {
347
339
348
340
let pllconf = if self . pllcfg . is_none ( ) {
349
341
let plln = ( 2 * self . sysclk . unwrap_or ( HSI ) ) / HSI ;
@@ -507,64 +499,32 @@ impl CFGR {
507
499
while rcc. cr . read ( ) . msirdy ( ) . bit_is_clear ( ) { }
508
500
}
509
501
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,
502
+ {
503
+ // Turn on USB, RNG Clock using the HSI48 CLK source (default)
504
+ if self . hsi48 {
505
+ // p. 180 in ref-manual
506
+ rcc. crrcr . modify ( |_, w| w. hsi48on ( ) . set_bit ( ) ) ;
507
+ // Wait until HSI48 is running
508
+ while rcc. crrcr . read ( ) . hsi48rdy ( ) . bit_is_clear ( ) { }
509
+ }
541
510
}
542
- }
543
-
544
- #[ cfg( feature = "stm32l47x" ) ]
545
- pub fn freeze ( self , acr : & mut ACR ) -> Clocks {
546
511
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 ( ) } ;
552
512
// Select MSI as clock source for usb48, rng ...
553
513
if let Some ( MsiFreq :: RANGE48M ) = self . msi {
554
- unsafe { rcc. ccipr . modify ( |_, w| w. clk48sel ( ) . bits ( 0b11 ) ) } ;
555
- usb_rng = true ;
514
+ unsafe { rcc. ccipr . modify ( |_, w| w. clk48sel ( ) . bits ( MsiFreq :: RANGE48M as u8 ) ) } ;
556
515
}
516
+ //TODO proper clk48sel and other selects
557
517
558
518
Clocks {
559
- hclk,
519
+ hclk : Hertz ( hclk ) ,
560
520
lsi : self . lsi ,
561
- usb_rng,
562
521
msi : self . msi ,
563
- pclk1,
564
- pclk2,
565
- ppre1,
566
- ppre2,
567
- sysclk,
522
+ hsi48 : self . hsi48 ,
523
+ pclk1 : Hertz ( pclk1) ,
524
+ pclk2 : Hertz ( pclk2) ,
525
+ ppre1 : ppre1,
526
+ ppre2 : ppre2,
527
+ sysclk : Hertz ( sysclk) ,
568
528
}
569
529
}
570
530
@@ -587,9 +547,7 @@ pub struct PllConfig {
587
547
#[ derive( Clone , Copy , Debug ) ]
588
548
pub struct Clocks {
589
549
hclk : Hertz ,
590
- #[ cfg( not( feature = "stm32l47x" ) ) ]
591
550
hsi48 : bool ,
592
- usb_rng : bool ,
593
551
msi : Option < MsiFreq > ,
594
552
lsi : bool ,
595
553
pclk1 : Hertz ,
@@ -608,14 +566,13 @@ impl Clocks {
608
566
}
609
567
610
568
/// Returns status of HSI48
611
- #[ cfg( not( feature = "stm32l47x" ) ) ]
612
569
pub fn hsi48 ( & self ) -> bool {
613
570
self . hsi48
614
571
}
615
572
616
- /// Returns if usb rng clock is available
617
- pub fn usb_rng ( & self ) -> bool {
618
- self . usb_rng
573
+ // Returns the status of the MSI
574
+ pub fn msi ( & self ) -> Option < MsiFreq > {
575
+ self . msi
619
576
}
620
577
621
578
/// Returns status of HSI48
0 commit comments