Skip to content

Commit 9582c4a

Browse files
authored
add clock bypass (#126)
1 parent 9d1e3fe commit 9582c4a

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

src/rcc/config.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,11 @@ pub enum PLLSrc {
5353
/// RTC clock input source
5454
#[derive(Clone, Copy)]
5555
pub enum RTCSrc {
56-
LSE = 0b01,
57-
LSI = 0b10,
58-
HSE = 0b11,
56+
LSE,
57+
LSE_BYPASS,
58+
LSI,
59+
HSE,
60+
HSE_BYPASS,
5961
}
6062

6163
/// PLL divider

src/rcc/mod.rs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -301,19 +301,37 @@ impl Rcc {
301301
}
302302

303303
pub(crate) fn enable_rtc(&self, src: RTCSrc) {
304-
match src {
305-
RTCSrc::LSI => self.enable_lsi(),
306-
RTCSrc::HSE => self.enable_hse(false),
307-
RTCSrc::LSE => self.enable_lse(false),
308-
}
304+
let rtc_sel = match src {
305+
RTCSrc::LSE => {
306+
self.enable_lse(false);
307+
0b01
308+
}
309+
RTCSrc::LSE_BYPASS => {
310+
self.enable_lse(true);
311+
0b01
312+
}
313+
RTCSrc::LSI => {
314+
self.enable_lsi();
315+
0b10
316+
}
317+
RTCSrc::HSE => {
318+
self.enable_hse(false);
319+
0b11
320+
}
321+
RTCSrc::HSE_BYPASS => {
322+
self.enable_hse(true);
323+
0b11
324+
}
325+
};
326+
309327
self.apbenr1
310328
.modify(|_, w| w.rtcapben().set_bit().pwren().set_bit());
311329
self.apbsmenr1.modify(|_, w| w.rtcapbsmen().set_bit());
312330
self.unlock_rtc();
313331
self.bdcr.modify(|_, w| w.bdrst().set_bit());
314332
self.bdcr.modify(|_, w| unsafe {
315333
w.rtcsel()
316-
.bits(src as u8)
334+
.bits(rtc_sel)
317335
.rtcen()
318336
.set_bit()
319337
.bdrst()

0 commit comments

Comments
 (0)