File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed
Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -451,6 +451,26 @@ impl CFGR {
451451 pub fn freeze ( & self , acr : & mut ACR , pwr : & mut Pwr ) -> Clocks {
452452 let rcc = unsafe { & * RCC :: ptr ( ) } ;
453453
454+ // Switch to MSI to prevent problems with PLL configuration.
455+ if rcc. cr . read ( ) . msion ( ) . bit_is_clear ( ) {
456+ // Turn on MSI and configure it to 4MHz.
457+ rcc. cr . modify ( |_, w| {
458+ w. msirgsel ( ) . set_bit ( ) ; // MSI Range is provided by MSIRANGE[3:0].
459+ w. msirange ( ) . range4m ( ) ;
460+ w. msipllen ( ) . clear_bit ( ) ;
461+ w. msion ( ) . set_bit ( )
462+ } ) ;
463+
464+ // Wait until MSI is running
465+ while rcc. cr . read ( ) . msirdy ( ) . bit_is_clear ( ) { }
466+ }
467+ if rcc. cfgr . read ( ) . sws ( ) . bits ( ) != 0 {
468+ // Set MSI as a clock source, reset prescalers.
469+ rcc. cfgr . reset ( ) ;
470+ // Wait for clock switch status bits to change.
471+ while rcc. cfgr . read ( ) . sws ( ) . bits ( ) != 0 { }
472+ }
473+
454474 //
455475 // 1. Setup clocks
456476 //
You can’t perform that action at this time.
0 commit comments