#![no_main]
#![no_std]
use core::{
cell::{Cell, RefCell},
sync::atomic::{AtomicUsize, Ordering},
};
use cortex_m::{self, peripheral::NVIC};
use cortex_m_rt::entry;
use critical_section::{with, Mutex};
use stm32_hal::{
clocks::Clocks,
low_power::{self, StopMode},
pac,
rtc::{Rtc, RtcClockSource, RtcConfig},
};
make_globals!((RTC, Rtc));
#[entry]
fn main() -> ! {
let mut cp = cortex_m::Peripherals::take().unwrap();
let mut dp = pac::Peripherals::take().unwrap();
let clock_cfg = Clocks::default();
clock_cfg.setup().unwrap();
let mut rtc = Rtc::new(
dp.RTC,
RtcConfig {
clock_source: RtcClockSource::Lse,
bypass_lse_output: true, ..Default::default()
},
);
rtc.set_12h_fmt();
rtc.set_wakeup(30.);
with(|cs| {
RTC.borrow(cs).replace(Some(rtc));
});
unsafe {
NVIC::unmask(pac::Interrupt::RTC_WKUP);
}
loop {
let date = rtc.get_date();
let time = rtc.get_time();
let dt = rtc.get_datetime();
let hours = rtc.get_hours();
low_power::stop(StopMode::One);
clock_cfg.reselect_input();
}
}
#[interrupt]
fn RTC_WKUP() {
with(|cs| {
unsafe {
(*pac::EXTI::ptr()).pr1.modify(|_, w| w.pr20().set_bit());
}
access_global!(RTC, rtc, cs);
rtc.clear_wakeup_flag();
});
}
#[defmt::panic_handler]
fn panic() -> ! {
cortex_m::asm::udf()
}