aboutsummaryrefslogtreecommitdiff
path: root/examples
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
parent65ed19aae272d6d6320554446f9187ec2ef8bf39 (diff)
h7: implement RTC and LSE clock configuration
Diffstat (limited to 'examples')
-rw-r--r--examples/stm32h7/Cargo.toml3
-rw-r--r--examples/stm32h7/src/bin/rtc.rs39
2 files changed, 41 insertions, 1 deletions
diff --git a/examples/stm32h7/Cargo.toml b/examples/stm32h7/Cargo.toml
index 3a3927a9a..7bcdf2b3e 100644
--- a/examples/stm32h7/Cargo.toml
+++ b/examples/stm32h7/Cargo.toml
@@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0"
6 6
7[dependencies] 7[dependencies]
8# Change stm32h743bi to your chip name, if necessary. 8# Change stm32h743bi to your chip name, if necessary.
9embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32h743bi", "time-driver-any", "exti", "memory-x", "unstable-pac", "unstable-traits"] } 9embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32h743bi", "time-driver-any", "exti", "memory-x", "unstable-pac", "unstable-traits", "chrono"] }
10embassy-sync = { version = "0.3.0", path = "../../embassy-sync", features = ["defmt"] } 10embassy-sync = { version = "0.3.0", path = "../../embassy-sync", features = ["defmt"] }
11embassy-executor = { version = "0.3.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } 11embassy-executor = { version = "0.3.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
12embassy-time = { version = "0.1.3", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-hz-32_768"] } 12embassy-time = { version = "0.1.3", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-hz-32_768"] }
@@ -32,6 +32,7 @@ micromath = "2.0.0"
32stm32-fmc = "0.3.0" 32stm32-fmc = "0.3.0"
33embedded-storage = "0.3.0" 33embedded-storage = "0.3.0"
34static_cell = { version = "1.1", features = ["nightly"]} 34static_cell = { version = "1.1", features = ["nightly"]}
35chrono = { version = "^0.4", default-features = false }
35 36
36# cargo build/run 37# cargo build/run
37[profile.dev] 38[profile.dev]
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}