tests/stm32: fix rtc test
This commit is contained in:
parent
6a73ab1afa
commit
32fdd4c787
@ -9,6 +9,7 @@ use crate::gpio::Speed;
|
||||
use crate::pac::rcc::vals::{Hpre, Ppre, Sw};
|
||||
use crate::pac::{FLASH, PWR, RCC};
|
||||
use crate::rcc::{set_freqs, Clocks};
|
||||
use crate::rtc::{Rtc, RtcClockSource};
|
||||
use crate::time::Hertz;
|
||||
use crate::{peripherals, Peripheral};
|
||||
|
||||
@ -33,6 +34,7 @@ pub struct Config {
|
||||
pub plli2s: Option<Hertz>,
|
||||
|
||||
pub pll48: bool,
|
||||
pub rtc: Option<RtcClockSource>,
|
||||
}
|
||||
|
||||
#[cfg(stm32f410)]
|
||||
@ -459,6 +461,18 @@ pub(crate) unsafe fn init(config: Config) {
|
||||
})
|
||||
});
|
||||
|
||||
match config.rtc {
|
||||
Some(RtcClockSource::LSI) => {
|
||||
RCC.csr().modify(|w| w.set_lsion(true));
|
||||
while !RCC.csr().read().lsirdy() {}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
config.rtc.map(|clock_source| {
|
||||
Rtc::set_clock_source(clock_source);
|
||||
});
|
||||
|
||||
set_freqs(Clocks {
|
||||
sys: Hertz(sysclk),
|
||||
apb1: Hertz(pclk1),
|
||||
|
@ -10,13 +10,16 @@ use chrono::{NaiveDate, NaiveDateTime};
|
||||
use common::*;
|
||||
use defmt::assert;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_stm32::pac;
|
||||
use embassy_stm32::rtc::{Rtc, RtcConfig};
|
||||
use embassy_stm32::rtc::{Rtc, RtcClockSource, RtcConfig};
|
||||
use embassy_time::{Duration, Timer};
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
let p = embassy_stm32::init(config());
|
||||
let mut config = config();
|
||||
|
||||
config.rcc.rtc = Some(RtcClockSource::LSI);
|
||||
|
||||
let p = embassy_stm32::init(config);
|
||||
info!("Hello World!");
|
||||
|
||||
let now = NaiveDate::from_ymd_opt(2020, 5, 15)
|
||||
@ -24,13 +27,6 @@ async fn main(_spawner: Spawner) {
|
||||
.and_hms_opt(10, 30, 15)
|
||||
.unwrap();
|
||||
|
||||
info!("Starting LSI");
|
||||
|
||||
pac::RCC.csr().modify(|w| w.set_lsion(true));
|
||||
while !pac::RCC.csr().read().lsirdy() {}
|
||||
|
||||
info!("Started LSI");
|
||||
|
||||
let mut rtc = Rtc::new(p.RTC, RtcConfig::default());
|
||||
|
||||
rtc.set_datetime(now.into()).expect("datetime not set");
|
||||
|
Loading…
Reference in New Issue
Block a user