2023-07-01 12:16:23 +02:00
|
|
|
#![no_std]
|
|
|
|
#![no_main]
|
|
|
|
#![feature(type_alias_impl_trait)]
|
|
|
|
|
|
|
|
use chrono::{NaiveDate, NaiveDateTime};
|
|
|
|
use defmt::*;
|
|
|
|
use embassy_executor::Spawner;
|
2023-10-15 03:08:14 +02:00
|
|
|
use embassy_stm32::rcc::{ClockSrc, LsConfig, PLLSource, Pll, PllMul, PllPreDiv, PllRDiv};
|
2023-07-01 12:16:23 +02:00
|
|
|
use embassy_stm32::rtc::{Rtc, RtcConfig};
|
|
|
|
use embassy_stm32::time::Hertz;
|
|
|
|
use embassy_stm32::Config;
|
2023-10-15 01:57:25 +02:00
|
|
|
use embassy_time::Timer;
|
2023-07-01 12:16:23 +02:00
|
|
|
use {defmt_rtt as _, panic_probe as _};
|
|
|
|
|
|
|
|
#[embassy_executor::main]
|
|
|
|
async fn main(_spawner: Spawner) {
|
2023-10-15 03:08:14 +02:00
|
|
|
let mut config = Config::default();
|
|
|
|
config.rcc.mux = ClockSrc::PLL;
|
|
|
|
config.rcc.hse = Some(Hertz::mhz(8));
|
|
|
|
config.rcc.pll_src = PLLSource::HSE;
|
|
|
|
config.rcc.pll = Some(Pll {
|
|
|
|
prediv: PllPreDiv::DIV1,
|
|
|
|
mul: PllMul::MUL20,
|
|
|
|
divp: None,
|
|
|
|
divq: None,
|
|
|
|
divr: Some(PllRDiv::DIV2), // sysclk 80Mhz clock (8 / 1 * 20 / 2)
|
|
|
|
});
|
|
|
|
config.rcc.ls = LsConfig::default_lse();
|
|
|
|
let p = embassy_stm32::init(config);
|
|
|
|
|
2023-07-01 12:16:23 +02:00
|
|
|
info!("Hello World!");
|
|
|
|
|
|
|
|
let now = NaiveDate::from_ymd_opt(2020, 5, 15)
|
|
|
|
.unwrap()
|
|
|
|
.and_hms_opt(10, 30, 15)
|
|
|
|
.unwrap();
|
|
|
|
|
2023-08-09 02:58:03 +02:00
|
|
|
let mut rtc = Rtc::new(p.RTC, RtcConfig::default());
|
2023-07-01 12:16:23 +02:00
|
|
|
info!("Got RTC! {:?}", now.timestamp());
|
|
|
|
|
|
|
|
rtc.set_datetime(now.into()).expect("datetime not set");
|
|
|
|
|
|
|
|
// In reality the delay would be much longer
|
2023-10-15 01:57:25 +02:00
|
|
|
Timer::after_millis(20000).await;
|
2023-07-01 12:16:23 +02:00
|
|
|
|
|
|
|
let then: NaiveDateTime = rtc.now().unwrap().into();
|
|
|
|
info!("Got RTC! {:?}", then.timestamp());
|
|
|
|
}
|