aboutsummaryrefslogtreecommitdiff
path: root/examples
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
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')
-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 511a1fa8c..f5f8b632d 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}