@@ -22,6 +22,7 @@ impl RccExt for RCC {
22
22
Rcc {
23
23
cfgr : CFGR {
24
24
hse : None ,
25
+ hse_bypass : false ,
25
26
hclk : None ,
26
27
pclk1 : None ,
27
28
pclk2 : None ,
@@ -110,6 +111,7 @@ const HSI: u32 = 8_000_000; // Hz
110
111
#[ derive( Debug , Default , PartialEq , Eq ) ]
111
112
pub struct CFGR {
112
113
hse : Option < u32 > ,
114
+ hse_bypass : bool ,
113
115
hclk : Option < u32 > ,
114
116
pclk1 : Option < u32 > ,
115
117
pclk2 : Option < u32 > ,
@@ -127,6 +129,20 @@ impl CFGR {
127
129
self
128
130
}
129
131
132
+ /// Bypasses the high-speed external oscillator and uses an external clock input on the OSC_IN
133
+ /// pin.
134
+ ///
135
+ /// For this configuration, the OSC_IN pin should be connected to a clock source with a
136
+ /// frequency specified in the call to use_hse(), and the OSC_OUT pin should not be connected.
137
+ ///
138
+ /// This function has no effect unless use_hse() is also called.
139
+ pub fn bypass_hse_oscillator ( self ) -> Self {
140
+ Self {
141
+ hse_bypass : true ,
142
+ ..self
143
+ }
144
+ }
145
+
130
146
/// Sets the desired frequency for the HCLK clock
131
147
#[ inline( always) ]
132
148
pub fn hclk ( mut self , freq : Hertz ) -> Self {
@@ -208,7 +224,12 @@ impl CFGR {
208
224
if cfg. hse . is_some ( ) {
209
225
// enable HSE and wait for it to be ready
210
226
211
- rcc. cr . modify ( |_, w| w. hseon ( ) . set_bit ( ) ) ;
227
+ rcc. cr . modify ( |_, w| {
228
+ if cfg. hse_bypass {
229
+ w. hsebyp ( ) . bypassed ( ) ;
230
+ }
231
+ w. hseon ( ) . set_bit ( )
232
+ } ) ;
212
233
213
234
while rcc. cr . read ( ) . hserdy ( ) . bit_is_clear ( ) { }
214
235
}
@@ -478,6 +499,7 @@ pub trait Reset: RccBus {
478
499
#[ derive( Clone , Copy , Debug , PartialEq ) ]
479
500
pub struct Config {
480
501
pub hse : Option < u32 > ,
502
+ pub hse_bypass : bool ,
481
503
pub pllmul : Option < u8 > ,
482
504
pub hpre : HPre ,
483
505
pub ppre1 : PPre ,
@@ -491,6 +513,7 @@ impl Default for Config {
491
513
fn default ( ) -> Self {
492
514
Self {
493
515
hse : None ,
516
+ hse_bypass : false ,
494
517
pllmul : None ,
495
518
hpre : HPre :: Div1 ,
496
519
ppre1 : PPre :: Div1 ,
@@ -549,6 +572,7 @@ pub type AdcPre = rcc::cfgr::ADCPRE_A;
549
572
impl Config {
550
573
pub const fn from_cfgr ( cfgr : CFGR ) -> Self {
551
574
let hse = cfgr. hse ;
575
+ let hse_bypass = cfgr. hse_bypass ;
552
576
let pllsrcclk = if let Some ( hse) = hse { hse } else { HSI / 2 } ;
553
577
554
578
let pllmul = if let Some ( sysclk) = cfgr. sysclk {
@@ -649,6 +673,7 @@ impl Config {
649
673
650
674
Self {
651
675
hse,
676
+ hse_bypass,
652
677
pllmul : pllmul_bits,
653
678
hpre : hpre_bits,
654
679
ppre1 : ppre1_bits,
@@ -730,6 +755,7 @@ fn rcc_config_usb() {
730
755
let config = Config :: from_cfgr ( cfgr) ;
731
756
let config_expected = Config {
732
757
hse : Some ( 8_000_000 ) ,
758
+ hse_bypass : false ,
733
759
pllmul : Some ( 4 ) ,
734
760
hpre : HPre :: Div1 ,
735
761
ppre1 : PPre :: Div2 ,
0 commit comments