RP: Don't reset RTC in Clock::init. Updated example.
This commit is contained in:
parent
466a391b52
commit
6d402fe393
@ -308,6 +308,7 @@ pub(crate) unsafe fn init(config: ClockConfig) {
|
|||||||
// - QSPI (we're using it to run this code!)
|
// - QSPI (we're using it to run this code!)
|
||||||
// - PLLs (it may be suicide if that's what's clocking us)
|
// - PLLs (it may be suicide if that's what's clocking us)
|
||||||
// - USB, SYSCFG (breaks usb-to-swd on core1)
|
// - USB, SYSCFG (breaks usb-to-swd on core1)
|
||||||
|
// - RTC (else there would be no more time...)
|
||||||
let mut peris = reset::ALL_PERIPHERALS;
|
let mut peris = reset::ALL_PERIPHERALS;
|
||||||
peris.set_io_qspi(false);
|
peris.set_io_qspi(false);
|
||||||
// peris.set_io_bank0(false); // might be suicide if we're clocked from gpin
|
// peris.set_io_bank0(false); // might be suicide if we're clocked from gpin
|
||||||
@ -317,6 +318,7 @@ pub(crate) unsafe fn init(config: ClockConfig) {
|
|||||||
// TODO investigate if usb should be unreset here
|
// TODO investigate if usb should be unreset here
|
||||||
peris.set_usbctrl(false);
|
peris.set_usbctrl(false);
|
||||||
peris.set_syscfg(false);
|
peris.set_syscfg(false);
|
||||||
|
peris.set_rtc(false);
|
||||||
reset::reset(peris);
|
reset::reset(peris);
|
||||||
|
|
||||||
// Disable resus that may be enabled from previous software
|
// Disable resus that may be enabled from previous software
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
use defmt::*;
|
use defmt::*;
|
||||||
use embassy_executor::Spawner;
|
use embassy_executor::Spawner;
|
||||||
use embassy_rp::pac::rtc::regs::{Rtc0, Rtc1};
|
|
||||||
use embassy_rp::rtc::{DateTime, DayOfWeek, Rtc};
|
use embassy_rp::rtc::{DateTime, DayOfWeek, Rtc};
|
||||||
use embassy_time::{Duration, Timer};
|
use embassy_time::{Duration, Timer};
|
||||||
use {defmt_rtt as _, panic_probe as _};
|
use {defmt_rtt as _, panic_probe as _};
|
||||||
@ -14,22 +13,18 @@ async fn main(_spawner: Spawner) {
|
|||||||
let p = embassy_rp::init(Default::default());
|
let p = embassy_rp::init(Default::default());
|
||||||
info!("Wait for 20s");
|
info!("Wait for 20s");
|
||||||
|
|
||||||
let mut watchdog = embassy_rp::watchdog::Watchdog::new(p.WATCHDOG);
|
|
||||||
let mut rtc = Rtc::new(p.RTC);
|
let mut rtc = Rtc::new(p.RTC);
|
||||||
|
|
||||||
let rtc0 = Rtc0(watchdog.get_scratch0());
|
if !rtc.is_running() {
|
||||||
let rtc1 = Rtc1(watchdog.get_scratch1());
|
info!("Start RTC");
|
||||||
if rtc1.year() >= 2020 {
|
|
||||||
rtc.restore(rtc1, rtc0);
|
|
||||||
} else {
|
|
||||||
let now = DateTime {
|
let now = DateTime {
|
||||||
year: 2020,
|
year: 2000,
|
||||||
month: 5,
|
month: 1,
|
||||||
day: 15,
|
day: 1,
|
||||||
day_of_week: DayOfWeek::Monday,
|
day_of_week: DayOfWeek::Saturday,
|
||||||
hour: 10,
|
hour: 0,
|
||||||
minute: 30,
|
minute: 0,
|
||||||
second: 50,
|
second: 0,
|
||||||
};
|
};
|
||||||
rtc.set_datetime(now).unwrap();
|
rtc.set_datetime(now).unwrap();
|
||||||
}
|
}
|
||||||
@ -41,9 +36,6 @@ async fn main(_spawner: Spawner) {
|
|||||||
"Now: {}-{:02}-{:02} {}:{:02}:{:02}",
|
"Now: {}-{:02}-{:02} {}:{:02}:{:02}",
|
||||||
dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second,
|
dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second,
|
||||||
);
|
);
|
||||||
let (rtc1, rtc0) = rtc.save();
|
|
||||||
watchdog.set_scratch0(rtc0.0);
|
|
||||||
watchdog.set_scratch1(rtc1.0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
info!("Reboot.");
|
info!("Reboot.");
|
||||||
|
Loading…
Reference in New Issue
Block a user