mirror of
https://github.com/embassy-rs/embassy.git
synced 2024-11-25 16:23:10 +00:00
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::rcc::vals::{Hpre, Ppre, Sw};
|
||||||
use crate::pac::{FLASH, PWR, RCC};
|
use crate::pac::{FLASH, PWR, RCC};
|
||||||
use crate::rcc::{set_freqs, Clocks};
|
use crate::rcc::{set_freqs, Clocks};
|
||||||
|
use crate::rtc::{Rtc, RtcClockSource};
|
||||||
use crate::time::Hertz;
|
use crate::time::Hertz;
|
||||||
use crate::{peripherals, Peripheral};
|
use crate::{peripherals, Peripheral};
|
||||||
|
|
||||||
@ -33,6 +34,7 @@ pub struct Config {
|
|||||||
pub plli2s: Option<Hertz>,
|
pub plli2s: Option<Hertz>,
|
||||||
|
|
||||||
pub pll48: bool,
|
pub pll48: bool,
|
||||||
|
pub rtc: Option<RtcClockSource>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(stm32f410)]
|
#[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 {
|
set_freqs(Clocks {
|
||||||
sys: Hertz(sysclk),
|
sys: Hertz(sysclk),
|
||||||
apb1: Hertz(pclk1),
|
apb1: Hertz(pclk1),
|
||||||
|
@ -10,13 +10,16 @@ use chrono::{NaiveDate, NaiveDateTime};
|
|||||||
use common::*;
|
use common::*;
|
||||||
use defmt::assert;
|
use defmt::assert;
|
||||||
use embassy_executor::Spawner;
|
use embassy_executor::Spawner;
|
||||||
use embassy_stm32::pac;
|
use embassy_stm32::rtc::{Rtc, RtcClockSource, RtcConfig};
|
||||||
use embassy_stm32::rtc::{Rtc, RtcConfig};
|
|
||||||
use embassy_time::{Duration, Timer};
|
use embassy_time::{Duration, Timer};
|
||||||
|
|
||||||
#[embassy_executor::main]
|
#[embassy_executor::main]
|
||||||
async fn main(_spawner: Spawner) {
|
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!");
|
info!("Hello World!");
|
||||||
|
|
||||||
let now = NaiveDate::from_ymd_opt(2020, 5, 15)
|
let now = NaiveDate::from_ymd_opt(2020, 5, 15)
|
||||||
@ -24,13 +27,6 @@ async fn main(_spawner: Spawner) {
|
|||||||
.and_hms_opt(10, 30, 15)
|
.and_hms_opt(10, 30, 15)
|
||||||
.unwrap();
|
.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());
|
let mut rtc = Rtc::new(p.RTC, RtcConfig::default());
|
||||||
|
|
||||||
rtc.set_datetime(now.into()).expect("datetime not set");
|
rtc.set_datetime(now.into()).expect("datetime not set");
|
||||||
|
Loading…
Reference in New Issue
Block a user