aboutsummaryrefslogtreecommitdiff
path: root/examples/stm32c0/src
diff options
context:
space:
mode:
authorAlan Rosenthal <[email protected]>2025-06-10 18:46:41 -0400
committerAlan Rosenthal <[email protected]>2025-06-10 18:46:41 -0400
commit5534a3650755ba7e5d406eb5c78d4f5f0d4d3716 (patch)
treed4b80d1c65000ff8a62ab168117bd4f9ae698cd2 /examples/stm32c0/src
parent6186d111a5c150946ee5b7e9e68d987a38c1a463 (diff)
Add RTC example for STM32C0
Tested on STM32C0116F6 Requries: https://github.com/embassy-rs/stm32-data/pull/617
Diffstat (limited to 'examples/stm32c0/src')
-rw-r--r--examples/stm32c0/src/bin/rtc.rs35
1 files changed, 35 insertions, 0 deletions
diff --git a/examples/stm32c0/src/bin/rtc.rs b/examples/stm32c0/src/bin/rtc.rs
new file mode 100644
index 000000000..82d8a37ba
--- /dev/null
+++ b/examples/stm32c0/src/bin/rtc.rs
@@ -0,0 +1,35 @@
1#![no_std]
2#![no_main]
3
4use chrono::{NaiveDate, NaiveDateTime};
5use defmt::*;
6use embassy_executor::Spawner;
7use embassy_stm32::rtc::{Rtc, RtcConfig};
8use embassy_stm32::Config;
9use embassy_time::Timer;
10use {defmt_rtt as _, panic_probe as _};
11
12#[embassy_executor::main]
13async fn main(_spawner: Spawner) {
14 let config = Config::default();
15 let p = embassy_stm32::init(config);
16
17 info!("Hello World!");
18
19 let now = NaiveDate::from_ymd_opt(2020, 5, 15)
20 .unwrap()
21 .and_hms_opt(10, 30, 15)
22 .unwrap();
23
24 let mut rtc = Rtc::new(p.RTC, RtcConfig::default());
25
26 rtc.set_datetime(now.into()).expect("datetime not set");
27
28 loop {
29 let now: NaiveDateTime = rtc.now().unwrap().into();
30
31 info!("{}", now.and_utc().timestamp());
32
33 Timer::after_millis(1000).await;
34 }
35}