aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorxoviat <[email protected]>2023-04-17 17:02:40 -0500
committerxoviat <[email protected]>2023-04-18 20:38:18 -0500
commitf589247c1f80a6a9f95a16bedf7594cdef62185f (patch)
tree02efdcd78e99b8af772856d3a7c2cdd438e4dbd3 /examples
parent46227bec1e948ea89de7d4e8a8dc98df5d7a25f0 (diff)
stm32/rtc: cleanup and consolidate
Diffstat (limited to 'examples')
-rw-r--r--examples/stm32f4/Cargo.toml1
-rw-r--r--examples/stm32f4/src/bin/rtc.rs30
2 files changed, 31 insertions, 0 deletions
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"
26embedded-storage = "0.3.0" 26embedded-storage = "0.3.0"
27micromath = "2.0.0" 27micromath = "2.0.0"
28static_cell = "1.0" 28static_cell = "1.0"
29chrono = { version = "^0.4", default-features = false}
29 30
30[profile.release] 31[profile.release]
31debug = 2 32debug = 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 @@
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::rtc::{Rtc, RtcConfig};
9use embassy_time::{Duration, Timer};
10use {defmt_rtt as _, panic_probe as _};
11
12#[embassy_executor::main]
13async fn main(_spawner: Spawner) {
14 let p = embassy_stm32::init(Default::default());
15 info!("Hello World!");
16
17 let now = NaiveDate::from_ymd_opt(2020, 5, 15)
18 .unwrap()
19 .and_hms_opt(10, 30, 15)
20 .unwrap();
21
22 let mut rtc = Rtc::new(p.RTC, RtcConfig::default());
23
24 rtc.set_datetime(now.into()).expect("datetime not set");
25
26 // In reality the delay would be much longer
27 Timer::after(Duration::from_millis(20000)).await;
28
29 let _then: NaiveDateTime = rtc.now().unwrap().into();
30}