aboutsummaryrefslogtreecommitdiff
path: root/examples/stm32h7/src
diff options
context:
space:
mode:
authorMatt Ickstadt <[email protected]>2023-10-03 16:45:05 -0500
committerMatt Ickstadt <[email protected]>2023-10-06 13:28:30 -0500
commitf01609036ff757ef3f04e568c646a467289d5440 (patch)
tree1a1f974ba94cb5f9fe59de9c89b6f3682ed4766a /examples/stm32h7/src
parent65ed19aae272d6d6320554446f9187ec2ef8bf39 (diff)
h7: implement RTC and LSE clock configuration
Diffstat (limited to 'examples/stm32h7/src')
-rw-r--r--examples/stm32h7/src/bin/rtc.rs39
1 files changed, 39 insertions, 0 deletions
diff --git a/examples/stm32h7/src/bin/rtc.rs b/examples/stm32h7/src/bin/rtc.rs
new file mode 100644
index 000000000..eeb94073b
--- /dev/null
+++ b/examples/stm32h7/src/bin/rtc.rs
@@ -0,0 +1,39 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5use chrono::{NaiveDate, NaiveDateTime};
6use defmt::*;
7use embassy_executor::Spawner;
8use embassy_stm32::rcc::Lse;
9use embassy_stm32::rtc::{Rtc, RtcClockSource, RtcConfig};
10use embassy_stm32::Config;
11use embassy_time::{Duration, Timer};
12use {defmt_rtt as _, panic_probe as _};
13
14#[embassy_executor::main]
15async fn main(_spawner: Spawner) {
16 let p = {
17 let mut config = Config::default();
18 config.rcc.lse = Some(Lse::Oscillator);
19 config.rcc.rtc_mux = Some(RtcClockSource::LSE);
20 embassy_stm32::init(config)
21 };
22 info!("Hello World!");
23
24 let now = NaiveDate::from_ymd_opt(2020, 5, 15)
25 .unwrap()
26 .and_hms_opt(10, 30, 15)
27 .unwrap();
28
29 let mut rtc = Rtc::new(p.RTC, RtcConfig::default());
30 info!("Got RTC! {:?}", now.timestamp());
31
32 rtc.set_datetime(now.into()).expect("datetime not set");
33
34 // In reality the delay would be much longer
35 Timer::after(Duration::from_millis(20000)).await;
36
37 let then: NaiveDateTime = rtc.now().unwrap().into();
38 info!("Got RTC! {:?}", then.timestamp());
39}