diff options
| -rw-r--r-- | embassy-stm32/src/rtc/datetime.rs | 2 | ||||
| -rw-r--r-- | examples/stm32f4/src/bin/rtc.rs | 19 |
2 files changed, 15 insertions, 6 deletions
diff --git a/embassy-stm32/src/rtc/datetime.rs b/embassy-stm32/src/rtc/datetime.rs index a9c48d88d..3efe9be5d 100644 --- a/embassy-stm32/src/rtc/datetime.rs +++ b/embassy-stm32/src/rtc/datetime.rs | |||
| @@ -89,7 +89,7 @@ pub enum DayOfWeek { | |||
| 89 | #[cfg(feature = "chrono")] | 89 | #[cfg(feature = "chrono")] |
| 90 | impl From<chrono::Weekday> for DayOfWeek { | 90 | impl From<chrono::Weekday> for DayOfWeek { |
| 91 | fn from(weekday: Weekday) -> Self { | 91 | fn from(weekday: Weekday) -> Self { |
| 92 | day_of_week_from_u8(weekday.number_from_monday() as u8).unwrap() | 92 | day_of_week_from_u8(weekday.num_days_from_monday() as u8).unwrap() |
| 93 | } | 93 | } |
| 94 | } | 94 | } |
| 95 | 95 | ||
diff --git a/examples/stm32f4/src/bin/rtc.rs b/examples/stm32f4/src/bin/rtc.rs index 0eca58203..33c4ebfdb 100644 --- a/examples/stm32f4/src/bin/rtc.rs +++ b/examples/stm32f4/src/bin/rtc.rs | |||
| @@ -5,13 +5,19 @@ | |||
| 5 | use chrono::{NaiveDate, NaiveDateTime}; | 5 | use chrono::{NaiveDate, NaiveDateTime}; |
| 6 | use defmt::*; | 6 | use defmt::*; |
| 7 | use embassy_executor::Spawner; | 7 | use embassy_executor::Spawner; |
| 8 | use embassy_stm32::rtc::{Rtc, RtcConfig}; | 8 | use embassy_stm32::{ |
| 9 | rtc::{Rtc, RtcClockSource, RtcConfig}, | ||
| 10 | Config, | ||
| 11 | }; | ||
| 9 | use embassy_time::{Duration, Timer}; | 12 | use embassy_time::{Duration, Timer}; |
| 10 | use {defmt_rtt as _, panic_probe as _}; | 13 | use {defmt_rtt as _, panic_probe as _}; |
| 11 | 14 | ||
| 12 | #[embassy_executor::main] | 15 | #[embassy_executor::main] |
| 13 | async fn main(_spawner: Spawner) { | 16 | async fn main(_spawner: Spawner) { |
| 14 | let p = embassy_stm32::init(Default::default()); | 17 | let mut config = Config::default(); |
| 18 | config.rcc.rtc = Option::Some(RtcClockSource::LSI); | ||
| 19 | let p = embassy_stm32::init(config); | ||
| 20 | |||
| 15 | info!("Hello World!"); | 21 | info!("Hello World!"); |
| 16 | 22 | ||
| 17 | let now = NaiveDate::from_ymd_opt(2020, 5, 15) | 23 | let now = NaiveDate::from_ymd_opt(2020, 5, 15) |
| @@ -23,8 +29,11 @@ async fn main(_spawner: Spawner) { | |||
| 23 | 29 | ||
| 24 | rtc.set_datetime(now.into()).expect("datetime not set"); | 30 | rtc.set_datetime(now.into()).expect("datetime not set"); |
| 25 | 31 | ||
| 26 | // In reality the delay would be much longer | 32 | loop { |
| 27 | Timer::after(Duration::from_millis(20000)).await; | 33 | let now: NaiveDateTime = rtc.now().unwrap().into(); |
| 34 | |||
| 35 | info!("{}", now.timestamp()); | ||
| 28 | 36 | ||
| 29 | let _then: NaiveDateTime = rtc.now().unwrap().into(); | 37 | Timer::after(Duration::from_millis(1000)).await; |
| 38 | } | ||
| 30 | } | 39 | } |
