@@ -438,32 +438,23 @@ impl CFGR {
438
438
fn get_sysclk ( & self ) -> ( u32 , cfgr:: SW_A , Option < PllConfig > ) {
439
439
// If a sysclk is given, check if the PLL has to be used,
440
440
// else select the system clock source, which is either HSI or HSE.
441
- if let Some ( sysclk) = self . sysclk {
442
- if let Some ( hseclk) = self . hse {
443
- if sysclk == hseclk {
444
- // No need to use the PLL
445
- // PLL is needed for USB, but we can make this assumption, to not use PLL here,
446
- // because the two valid USB clocks, 72 Mhz and 48 Mhz, can't be generated
447
- // directly from neither the internal rc (8 Mhz) nor the external
448
- // Oscillator (max 32 Mhz), without using the PLL.
449
- ( hseclk, cfgr:: SW_A :: HSE , None )
450
- } else {
451
- let clock_with_pll = self . calc_pll ( sysclk) ;
452
- ( clock_with_pll. 0 , cfgr:: SW_A :: PLL , Some ( clock_with_pll. 1 ) )
453
- }
454
- } else if sysclk == HSI {
455
- // No need to use the PLL
456
- ( HSI , cfgr:: SW_A :: HSE , None )
457
- } else {
458
- let clock_with_pll = self . calc_pll ( sysclk) ;
459
- ( clock_with_pll. 0 , cfgr:: SW_A :: PLL , Some ( clock_with_pll. 1 ) )
441
+ match ( self . sysclk , self . hse ) {
442
+ // No need to use the PLL
443
+ // PLL is needed for USB, but we can make this assumption, to not use PLL here,
444
+ // because the two valid USB clocks, 72 Mhz and 48 Mhz, can't be generated
445
+ // directly from neither the internal rc (8 Mhz) nor the external
446
+ // Oscillator (max 32 Mhz), without using the PLL.
447
+ ( Some ( sysclk) , Some ( hse) ) if sysclk == hse => ( hse, cfgr:: SW_A :: HSE , None ) ,
448
+ // No need to use the PLL
449
+ ( Some ( sysclk) , None ) if sysclk == HSI => ( HSI , cfgr:: SW_A :: HSI , None ) ,
450
+ ( Some ( sysclk) , _) => {
451
+ let ( sysclk, pll_config) = self . calc_pll ( sysclk) ;
452
+ ( sysclk, cfgr:: SW_A :: PLL , Some ( pll_config) )
460
453
}
461
- } else if let Some ( hseclk) = self . hse {
462
454
// Use HSE as system clock
463
- ( hseclk, cfgr:: SW_A :: HSE , None )
464
- } else {
455
+ ( None , Some ( hse) ) => ( hse, cfgr:: SW_A :: HSE , None ) ,
465
456
// Use HSI as system clock
466
- ( HSI , cfgr:: SW_A :: HSI , None )
457
+ ( None , None ) => ( HSI , cfgr:: SW_A :: HSI , None ) ,
467
458
}
468
459
}
469
460
0 commit comments