diff options
| author | xoviat <[email protected]> | 2023-04-17 17:02:40 -0500 |
|---|---|---|
| committer | xoviat <[email protected]> | 2023-04-18 20:38:18 -0500 |
| commit | f589247c1f80a6a9f95a16bedf7594cdef62185f (patch) | |
| tree | 02efdcd78e99b8af772856d3a7c2cdd438e4dbd3 /examples | |
| parent | 46227bec1e948ea89de7d4e8a8dc98df5d7a25f0 (diff) | |
stm32/rtc: cleanup and consolidate
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/stm32f4/Cargo.toml | 1 | ||||
| -rw-r--r-- | examples/stm32f4/src/bin/rtc.rs | 30 |
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" | |||
| 26 | embedded-storage = "0.3.0" | 26 | embedded-storage = "0.3.0" |
| 27 | micromath = "2.0.0" | 27 | micromath = "2.0.0" |
| 28 | static_cell = "1.0" | 28 | static_cell = "1.0" |
| 29 | chrono = { version = "^0.4", default-features = false} | ||
| 29 | 30 | ||
| 30 | [profile.release] | 31 | [profile.release] |
| 31 | debug = 2 | 32 | 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 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | use chrono::{NaiveDate, NaiveDateTime}; | ||
| 6 | use defmt::*; | ||
| 7 | use embassy_executor::Spawner; | ||
| 8 | use embassy_stm32::rtc::{Rtc, RtcConfig}; | ||
| 9 | use embassy_time::{Duration, Timer}; | ||
| 10 | use {defmt_rtt as _, panic_probe as _}; | ||
| 11 | |||
| 12 | #[embassy_executor::main] | ||
| 13 | async 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 | } | ||
