aboutsummaryrefslogtreecommitdiff
path: root/examples/stm32f4/src/bin
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2023-05-01 19:32:06 +0000
committerGitHub <[email protected]>2023-05-01 19:32:06 +0000
commit855c0d1423cb1aacd4f4f45e255b02b442afde34 (patch)
tree727d6409543c308d2e8cb48fc722c61ed753be9c /examples/stm32f4/src/bin
parent05c36e05f9f6b1a0a36982239b2e7c697f0d3734 (diff)
parent0d82ebea29d5bad6d1b40258419a215c44786e1d (diff)
Merge #1376
1376: rtc: cleanup and consolidate r=Dirbaio a=xoviat This removes an extra file that I left in, adds an example, and consolidates the files into one 'v2' file. Co-authored-by: xoviat <[email protected]>
Diffstat (limited to 'examples/stm32f4/src/bin')
-rw-r--r--examples/stm32f4/src/bin/rtc.rs30
1 files changed, 30 insertions, 0 deletions
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}