From 6d402fe3932ac04ff939379e6520322476f683dc Mon Sep 17 00:00:00 2001 From: Henrik Berg Date: Wed, 12 Jul 2023 15:16:56 +0200 Subject: [PATCH] RP: Don't reset RTC in Clock::init. Updated example. --- embassy-rp/src/clocks.rs | 2 ++ examples/rp/src/bin/rtc.rs | 26 +++++++++----------------- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/embassy-rp/src/clocks.rs b/embassy-rp/src/clocks.rs index ddd61d224..acb21dce5 100644 --- a/embassy-rp/src/clocks.rs +++ b/embassy-rp/src/clocks.rs @@ -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 diff --git a/examples/rp/src/bin/rtc.rs b/examples/rp/src/bin/rtc.rs index 2ddde3257..d569f598f 100644 --- a/examples/rp/src/bin/rtc.rs +++ b/examples/rp/src/bin/rtc.rs @@ -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.");