aboutsummaryrefslogtreecommitdiff
path: root/examples/stm32wl/src
diff options
context:
space:
mode:
authorPhil Markgraf <[email protected]>2023-07-15 04:40:23 -0700
committerGitHub <[email protected]>2023-07-15 13:40:23 +0200
commit3bae53306683a57020ba751afaf631ec169deeed (patch)
tree529e02e65c7186d1e26f514f36bd349f8e331ca3 /examples/stm32wl/src
parent7b36fe049dbb2b7c816a80d2238c2169bbc716d0 (diff)
Enable RTC on STM32WL chips (#1645)
* Add clippy allow to not report if same then branch * Support enabling RTC clock on STM32WL * Add clippy allow to not report if same then branch * Support enabling RTC clock on STM32WL * Add rtc example for stm32wl * Address code review feedback
Diffstat (limited to 'examples/stm32wl/src')
-rw-r--r--examples/stm32wl/src/bin/rtc.rs43
1 files changed, 43 insertions, 0 deletions
diff --git a/examples/stm32wl/src/bin/rtc.rs b/examples/stm32wl/src/bin/rtc.rs
new file mode 100644
index 000000000..e11825499
--- /dev/null
+++ b/examples/stm32wl/src/bin/rtc.rs
@@ -0,0 +1,43 @@
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::{self, ClockSrc};
9use embassy_stm32::rtc::{Rtc, 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.mux = ClockSrc::HSE32;
19 config.rcc.rtc_mux = rcc::RtcClockSource::LSE32;
20 config.rcc.enable_rtc_apb = true;
21 embassy_stm32::init(config)
22 };
23 info!("Hello World!");
24
25 let now = NaiveDate::from_ymd_opt(2020, 5, 15)
26 .unwrap()
27 .and_hms_opt(10, 30, 15)
28 .unwrap();
29
30 let mut rtc = Rtc::new(
31 p.RTC,
32 RtcConfig::default().clock_config(embassy_stm32::rtc::RtcClockSource::LSE),
33 );
34 info!("Got RTC! {:?}", now.timestamp());
35
36 rtc.set_datetime(now.into()).expect("datetime not set");
37
38 // In reality the delay would be much longer
39 Timer::after(Duration::from_millis(20000)).await;
40
41 let then: NaiveDateTime = rtc.now().unwrap().into();
42 info!("Got RTC! {:?}", then.timestamp());
43}