2023-04-18 00:02:40 +02:00
|
|
|
#![no_std]
|
|
|
|
#![no_main]
|
|
|
|
#![feature(type_alias_impl_trait)]
|
|
|
|
|
|
|
|
use chrono::{NaiveDate, NaiveDateTime};
|
|
|
|
use defmt::*;
|
|
|
|
use embassy_executor::Spawner;
|
2023-08-27 22:25:12 +02:00
|
|
|
use embassy_stm32::rtc::{Rtc, RtcClockSource, RtcConfig};
|
|
|
|
use embassy_stm32::Config;
|
2023-04-18 00:02:40 +02:00
|
|
|
use embassy_time::{Duration, Timer};
|
|
|
|
use {defmt_rtt as _, panic_probe as _};
|
|
|
|
|
|
|
|
#[embassy_executor::main]
|
|
|
|
async fn main(_spawner: Spawner) {
|
2023-08-27 10:37:10 +02:00
|
|
|
let mut config = Config::default();
|
2023-09-24 07:11:58 +02:00
|
|
|
config.rcc.lsi = true;
|
2023-08-27 10:37:10 +02:00
|
|
|
config.rcc.rtc = Option::Some(RtcClockSource::LSI);
|
|
|
|
let p = embassy_stm32::init(config);
|
|
|
|
|
2023-04-18 00:02:40 +02:00
|
|
|
info!("Hello World!");
|
|
|
|
|
|
|
|
let now = NaiveDate::from_ymd_opt(2020, 5, 15)
|
|
|
|
.unwrap()
|
|
|
|
.and_hms_opt(10, 30, 15)
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let mut rtc = Rtc::new(p.RTC, RtcConfig::default());
|
|
|
|
|
|
|
|
rtc.set_datetime(now.into()).expect("datetime not set");
|
|
|
|
|
2023-08-27 10:37:10 +02:00
|
|
|
loop {
|
|
|
|
let now: NaiveDateTime = rtc.now().unwrap().into();
|
|
|
|
|
|
|
|
info!("{}", now.timestamp());
|
2023-04-18 00:02:40 +02:00
|
|
|
|
2023-08-27 10:37:10 +02:00
|
|
|
Timer::after(Duration::from_millis(1000)).await;
|
|
|
|
}
|
2023-04-18 00:02:40 +02:00
|
|
|
}
|