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