aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-stm32/src/rcc/f4.rs14
-rw-r--r--tests/stm32/src/bin/rtc.rs16
2 files changed, 20 insertions, 10 deletions
diff --git a/embassy-stm32/src/rcc/f4.rs b/embassy-stm32/src/rcc/f4.rs
index 7aa9f0fd2..2ae0d15cb 100644
--- a/embassy-stm32/src/rcc/f4.rs
+++ b/embassy-stm32/src/rcc/f4.rs
@@ -9,6 +9,7 @@ use crate::gpio::Speed;
9use crate::pac::rcc::vals::{Hpre, Ppre, Sw}; 9use crate::pac::rcc::vals::{Hpre, Ppre, Sw};
10use crate::pac::{FLASH, PWR, RCC}; 10use crate::pac::{FLASH, PWR, RCC};
11use crate::rcc::{set_freqs, Clocks}; 11use crate::rcc::{set_freqs, Clocks};
12use crate::rtc::{Rtc, RtcClockSource};
12use crate::time::Hertz; 13use crate::time::Hertz;
13use crate::{peripherals, Peripheral}; 14use crate::{peripherals, Peripheral};
14 15
@@ -33,6 +34,7 @@ pub struct Config {
33 pub plli2s: Option<Hertz>, 34 pub plli2s: Option<Hertz>,
34 35
35 pub pll48: bool, 36 pub pll48: bool,
37 pub rtc: Option<RtcClockSource>,
36} 38}
37 39
38#[cfg(stm32f410)] 40#[cfg(stm32f410)]
@@ -459,6 +461,18 @@ pub(crate) unsafe fn init(config: Config) {
459 }) 461 })
460 }); 462 });
461 463
464 match config.rtc {
465 Some(RtcClockSource::LSI) => {
466 RCC.csr().modify(|w| w.set_lsion(true));
467 while !RCC.csr().read().lsirdy() {}
468 }
469 _ => {}
470 }
471
472 config.rtc.map(|clock_source| {
473 Rtc::set_clock_source(clock_source);
474 });
475
462 set_freqs(Clocks { 476 set_freqs(Clocks {
463 sys: Hertz(sysclk), 477 sys: Hertz(sysclk),
464 apb1: Hertz(pclk1), 478 apb1: Hertz(pclk1),
diff --git a/tests/stm32/src/bin/rtc.rs b/tests/stm32/src/bin/rtc.rs
index 194b153d5..7df415b44 100644
--- a/tests/stm32/src/bin/rtc.rs
+++ b/tests/stm32/src/bin/rtc.rs
@@ -10,13 +10,16 @@ use chrono::{NaiveDate, NaiveDateTime};
10use common::*; 10use common::*;
11use defmt::assert; 11use defmt::assert;
12use embassy_executor::Spawner; 12use embassy_executor::Spawner;
13use embassy_stm32::pac; 13use embassy_stm32::rtc::{Rtc, RtcClockSource, RtcConfig};
14use embassy_stm32::rtc::{Rtc, RtcConfig};
15use embassy_time::{Duration, Timer}; 14use embassy_time::{Duration, Timer};
16 15
17#[embassy_executor::main] 16#[embassy_executor::main]
18async fn main(_spawner: Spawner) { 17async fn main(_spawner: Spawner) {
19 let p = embassy_stm32::init(config()); 18 let mut config = config();
19
20 config.rcc.rtc = Some(RtcClockSource::LSI);
21
22 let p = embassy_stm32::init(config);
20 info!("Hello World!"); 23 info!("Hello World!");
21 24
22 let now = NaiveDate::from_ymd_opt(2020, 5, 15) 25 let now = NaiveDate::from_ymd_opt(2020, 5, 15)
@@ -24,13 +27,6 @@ async fn main(_spawner: Spawner) {
24 .and_hms_opt(10, 30, 15) 27 .and_hms_opt(10, 30, 15)
25 .unwrap(); 28 .unwrap();
26 29
27 info!("Starting LSI");
28
29 pac::RCC.csr().modify(|w| w.set_lsion(true));
30 while !pac::RCC.csr().read().lsirdy() {}
31
32 info!("Started LSI");
33
34 let mut rtc = Rtc::new(p.RTC, RtcConfig::default()); 30 let mut rtc = Rtc::new(p.RTC, RtcConfig::default());
35 31
36 rtc.set_datetime(now.into()).expect("datetime not set"); 32 rtc.set_datetime(now.into()).expect("datetime not set");