@@ -40,6 +40,10 @@ impl RccExt for RCC {
4040 plln : 50 ,
4141 pllp : PLLP :: Div2 ,
4242 pllq : 2 ,
43+ use_plli2s : false ,
44+ plli2sr : 2 ,
45+ plli2sq : 2 ,
46+ plli2sn : 192 ,
4347 } ,
4448 }
4549 }
@@ -257,6 +261,10 @@ pub struct CFGR {
257261 plln : u16 ,
258262 pllp : PLLP ,
259263 pllq : u8 ,
264+ use_plli2s : bool ,
265+ plli2sr : u8 ,
266+ plli2sq : u8 ,
267+ plli2sn : u16 ,
260268}
261269
262270impl CFGR {
@@ -394,6 +402,45 @@ impl CFGR {
394402 self
395403 }
396404
405+ /// Enables the Plli2S clock source.
406+ pub fn use_plli2s ( mut self ) -> Self {
407+ self . use_plli2s = true ;
408+ self
409+ }
410+
411+ /// Sets the PLLI2SN multiplication factor for PLLI2S.
412+ ///
413+ /// # Panics
414+ ///
415+ /// Panics if the multiplication factor isn't between 50 and 432.
416+ pub fn plli2sn ( mut self , plli2sn : u16 ) -> Self {
417+ assert ! ( ( 50 ..=432 ) . contains( & plli2sn) ) ;
418+ self . plli2sn = plli2sn;
419+ self
420+ }
421+
422+ /// Sets the PLLI2SQ division factor for PLLI2S.
423+ ///
424+ /// # Panics
425+ ///
426+ /// Panics if the division factor isn't between 2 and 15.
427+ pub fn plli2sq ( mut self , plli2sq : u8 ) -> Self {
428+ assert ! ( ( 2 ..=15 ) . contains( & plli2sq) ) ;
429+ self . plli2sq = plli2sq;
430+ self
431+ }
432+
433+ /// Sets the PLLI2SR division factor for PLLI2S.
434+ ///
435+ /// # Panics
436+ ///
437+ /// Panics if the division factor isn't between 2 and 7.
438+ pub fn plli2sr ( mut self , plli2sr : u8 ) -> Self {
439+ assert ! ( ( 2 ..=7 ) . contains( & plli2sr) ) ;
440+ self . plli2sr = plli2sr;
441+ self
442+ }
443+
397444 /// Output clock calculation
398445 fn calculate_clocks ( & self ) -> ( Clocks , InternalRCCConfig ) {
399446 let mut config = InternalRCCConfig :: default ( ) ;
@@ -827,6 +874,26 @@ impl CFGR {
827874 rcc. dckcfgr2 . modify ( |_, w| w. ck48msel ( ) . bit ( false ) ) ;
828875 }
829876
877+ if self . use_plli2s {
878+ let plli2sn_freq = match self . hse . as_ref ( ) {
879+ Some ( hse) => hse. freq . integer ( ) as u64 / self . pllm as u64 * self . plli2sn as u64 ,
880+ None => 16_000_000 / self . pllm as u64 * self . plli2sn as u64 ,
881+ } ;
882+ let plli2sr_freq = plli2sn_freq / self . plli2sr as u64 ;
883+ let plli2sq_freq = plli2sn_freq / self . plli2sq as u64 ;
884+
885+ assert ! ( ( 192_000_000 ..=432_000_000 ) . contains( & plli2sn_freq) ) ;
886+ assert ! ( plli2sr_freq <= 216_000_000 ) ;
887+ assert ! ( plli2sq_freq <= 216_000_000 ) ;
888+
889+ rcc. plli2scfgr . modify ( |_, w| unsafe {
890+ w. plli2sn ( ) . bits ( self . plli2sn ) ;
891+ w. plli2sr ( ) . bits ( self . plli2sr ) ;
892+ w. plli2sq ( ) . bits ( self . plli2sq )
893+ } ) ;
894+ rcc. cr . modify ( |_, w| w. plli2son ( ) . on ( ) ) ;
895+ }
896+
830897 flash
831898 . acr
832899 . write ( |w| w. latency ( ) . bits ( config. flash_waitstates ) ) ;
@@ -1213,6 +1280,10 @@ mod tests {
12131280 plln : 50 ,
12141281 pllp : PLLP :: Div2 ,
12151282 pllq : 2 ,
1283+ use_plli2s : false ,
1284+ plli2sr : 2 ,
1285+ plli2sq : 2 ,
1286+ plli2sn : 192 ,
12161287 } ;
12171288
12181289 let mut cfgr = cfgr
@@ -1245,6 +1316,10 @@ mod tests {
12451316 plln : 50 ,
12461317 pllp : PLLP :: Div2 ,
12471318 pllq : 2 ,
1319+ use_plli2s : false ,
1320+ plli2sr : 2 ,
1321+ plli2sq : 2 ,
1322+ plli2sn : 192 ,
12481323 } ;
12491324
12501325 let mut cfgr = cfgr
@@ -1276,6 +1351,10 @@ mod tests {
12761351 plln : 50 ,
12771352 pllp : PLLP :: Div2 ,
12781353 pllq : 2 ,
1354+ use_plli2s : false ,
1355+ plli2sr : 2 ,
1356+ plli2sq : 2 ,
1357+ plli2sn : 192 ,
12791358 } ;
12801359
12811360 let mut cfgr = cfgr
@@ -1307,6 +1386,10 @@ mod tests {
13071386 plln : 50 ,
13081387 pllp : PLLP :: Div2 ,
13091388 pllq : 2 ,
1389+ use_plli2s : false ,
1390+ plli2sr : 2 ,
1391+ plli2sq : 2 ,
1392+ plli2sn : 192 ,
13101393 } ;
13111394
13121395 cfgr. pll_configure ( ) ;
0 commit comments