aboutsummaryrefslogtreecommitdiff
path: root/examples/stm32g0/src/bin/rtc.rs
blob: 50fb6398e7053296dd2af2d5e951f861afb565ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#![no_std]
#![no_main]

use defmt::*;
use embassy_executor::Spawner;
use embassy_stm32::rtc::{DateTime, DayOfWeek, Rtc, RtcConfig};
use embassy_stm32::Config;
use embassy_time::Timer;
use {defmt_rtt as _, panic_probe as _};

#[embassy_executor::main]
async fn main(_spawner: Spawner) {
    let config = Config::default();
    let p = embassy_stm32::init(config);

    info!("Hello World!");

    let now = DateTime::from(2023, 6, 14, DayOfWeek::Friday, 15, 59, 10, 0);

    let mut rtc = Rtc::new(p.RTC, RtcConfig::default());

    rtc.set_datetime(now.unwrap()).expect("datetime not set");

    loop {
        let now: DateTime = rtc.now().unwrap().into();

        info!("{}:{}:{}", now.hour(), now.minute(), now.second());

        Timer::after_millis(1000).await;
    }
}