53 lines
1.2 KiB
Rust
Executable file
53 lines
1.2 KiB
Rust
Executable file
#![no_main]
|
|
#![no_std]
|
|
|
|
use defmt::info;
|
|
use hal::pwr::PWR;
|
|
use hal::rtc::{Datelike, NaiveDateTime, Rtc, Timelike};
|
|
use panic_probe as _;
|
|
|
|
use defmt_rtt as _; // global logger
|
|
|
|
use cortex_m_rt::entry;
|
|
use hal::{pac, prelude::*, rcc::Config};
|
|
|
|
#[entry]
|
|
fn main() -> ! {
|
|
let dp = pac::Peripherals::take().unwrap();
|
|
let cp = cortex_m::Peripherals::take().unwrap();
|
|
|
|
// Configure the clock.
|
|
let mut rcc = dp.RCC.freeze(Config::hsi16());
|
|
let pwr = PWR::new(dp.PWR, &mut rcc);
|
|
|
|
let gpioa = dp.GPIOA.split(&mut rcc);
|
|
let mut led = gpioa.pa5.into_push_pull_output();
|
|
|
|
let mut delay = cp.SYST.delay(rcc.clocks);
|
|
|
|
let mut rtc = Rtc::new(dp.RTC, &mut rcc, &pwr, None).unwrap(); // starts at time 0
|
|
|
|
#[allow(clippy::never_loop)]
|
|
loop {
|
|
led.set_high().unwrap();
|
|
delay.delay_ms(500_u16);
|
|
|
|
led.set_low().unwrap();
|
|
delay.delay_ms(500_u16);
|
|
|
|
ptime(&mut rtc);
|
|
}
|
|
}
|
|
|
|
fn ptime(rtc: &mut Rtc) {
|
|
let time: NaiveDateTime = rtc.now();
|
|
info!(
|
|
"Time: {:04}-{:02}-{:02} {:02}:{:02}:{:02}",
|
|
time.year(),
|
|
time.month(),
|
|
time.day(),
|
|
time.hour(),
|
|
time.minute(),
|
|
time.second()
|
|
)
|
|
}
|