From f589247c1f80a6a9f95a16bedf7594cdef62185f Mon Sep 17 00:00:00 2001 From: xoviat Date: Mon, 17 Apr 2023 17:02:40 -0500 Subject: stm32/rtc: cleanup and consolidate --- examples/stm32f4/Cargo.toml | 1 + examples/stm32f4/src/bin/rtc.rs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 examples/stm32f4/src/bin/rtc.rs (limited to 'examples') diff --git a/examples/stm32f4/Cargo.toml b/examples/stm32f4/Cargo.toml index 69dcab64c..275c2c1a7 100644 --- a/examples/stm32f4/Cargo.toml +++ b/examples/stm32f4/Cargo.toml @@ -26,6 +26,7 @@ nb = "1.0.0" embedded-storage = "0.3.0" micromath = "2.0.0" static_cell = "1.0" +chrono = { version = "^0.4", default-features = false} [profile.release] debug = 2 diff --git a/examples/stm32f4/src/bin/rtc.rs b/examples/stm32f4/src/bin/rtc.rs new file mode 100644 index 000000000..0eca58203 --- /dev/null +++ b/examples/stm32f4/src/bin/rtc.rs @@ -0,0 +1,30 @@ +#![no_std] +#![no_main] +#![feature(type_alias_impl_trait)] + +use chrono::{NaiveDate, NaiveDateTime}; +use defmt::*; +use embassy_executor::Spawner; +use embassy_stm32::rtc::{Rtc, RtcConfig}; +use embassy_time::{Duration, Timer}; +use {defmt_rtt as _, panic_probe as _}; + +#[embassy_executor::main] +async fn main(_spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); + info!("Hello World!"); + + let now = NaiveDate::from_ymd_opt(2020, 5, 15) + .unwrap() + .and_hms_opt(10, 30, 15) + .unwrap(); + + let mut rtc = Rtc::new(p.RTC, RtcConfig::default()); + + rtc.set_datetime(now.into()).expect("datetime not set"); + + // In reality the delay would be much longer + Timer::after(Duration::from_millis(20000)).await; + + let _then: NaiveDateTime = rtc.now().unwrap().into(); +} -- cgit