RP: Don't reset RTC in Clock::init. Updated example.

This commit is contained in:
Henrik Berg 2023-07-12 15:16:56 +02:00
parent 466a391b52
commit 6d402fe393
2 changed files with 11 additions and 17 deletions

View File

@ -308,6 +308,7 @@ pub(crate) unsafe fn init(config: ClockConfig) {
// - QSPI (we're using it to run this code!)
// - PLLs (it may be suicide if that's what's clocking us)
// - USB, SYSCFG (breaks usb-to-swd on core1)
// - RTC (else there would be no more time...)
let mut peris = reset::ALL_PERIPHERALS;
peris.set_io_qspi(false);
// 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
peris.set_usbctrl(false);
peris.set_syscfg(false);
peris.set_rtc(false);
reset::reset(peris);
// Disable resus that may be enabled from previous software

View File

@ -4,7 +4,6 @@
use defmt::*;
use embassy_executor::Spawner;
use embassy_rp::pac::rtc::regs::{Rtc0, Rtc1};
use embassy_rp::rtc::{DateTime, DayOfWeek, Rtc};
use embassy_time::{Duration, Timer};
use {defmt_rtt as _, panic_probe as _};
@ -14,22 +13,18 @@ async fn main(_spawner: Spawner) {
let p = embassy_rp::init(Default::default());
info!("Wait for 20s");
let mut watchdog = embassy_rp::watchdog::Watchdog::new(p.WATCHDOG);
let mut rtc = Rtc::new(p.RTC);
let rtc0 = Rtc0(watchdog.get_scratch0());
let rtc1 = Rtc1(watchdog.get_scratch1());
if rtc1.year() >= 2020 {
rtc.restore(rtc1, rtc0);
} else {
if !rtc.is_running() {
info!("Start RTC");
let now = DateTime {
year: 2020,
month: 5,
day: 15,
day_of_week: DayOfWeek::Monday,
hour: 10,
minute: 30,
second: 50,
year: 2000,
month: 1,
day: 1,
day_of_week: DayOfWeek::Saturday,
hour: 0,
minute: 0,
second: 0,
};
rtc.set_datetime(now).unwrap();
}
@ -41,9 +36,6 @@ async fn main(_spawner: Spawner) {
"Now: {}-{:02}-{:02} {}:{:02}:{:02}",
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.");