diff options
| author | Henrik Berg <[email protected]> | 2023-07-12 15:16:56 +0200 |
|---|---|---|
| committer | Henrik Berg <[email protected]> | 2023-07-12 15:16:56 +0200 |
| commit | 6d402fe3932ac04ff939379e6520322476f683dc (patch) | |
| tree | bee3cccfc32f3e426ee12fe55984e7d9aa392ed0 | |
| parent | 466a391b52836f79fafad5780ad2eb0a07d82513 (diff) | |
RP: Don't reset RTC in Clock::init. Updated example.
| -rw-r--r-- | embassy-rp/src/clocks.rs | 2 | ||||
| -rw-r--r-- | 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) { | |||
| 308 | // - QSPI (we're using it to run this code!) | 308 | // - QSPI (we're using it to run this code!) |
| 309 | // - PLLs (it may be suicide if that's what's clocking us) | 309 | // - PLLs (it may be suicide if that's what's clocking us) |
| 310 | // - USB, SYSCFG (breaks usb-to-swd on core1) | 310 | // - USB, SYSCFG (breaks usb-to-swd on core1) |
| 311 | // - RTC (else there would be no more time...) | ||
| 311 | let mut peris = reset::ALL_PERIPHERALS; | 312 | let mut peris = reset::ALL_PERIPHERALS; |
| 312 | peris.set_io_qspi(false); | 313 | peris.set_io_qspi(false); |
| 313 | // peris.set_io_bank0(false); // might be suicide if we're clocked from gpin | 314 | // 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) { | |||
| 317 | // TODO investigate if usb should be unreset here | 318 | // TODO investigate if usb should be unreset here |
| 318 | peris.set_usbctrl(false); | 319 | peris.set_usbctrl(false); |
| 319 | peris.set_syscfg(false); | 320 | peris.set_syscfg(false); |
| 321 | peris.set_rtc(false); | ||
| 320 | reset::reset(peris); | 322 | reset::reset(peris); |
| 321 | 323 | ||
| 322 | // Disable resus that may be enabled from previous software | 324 | // 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 @@ | |||
| 4 | 4 | ||
| 5 | use defmt::*; | 5 | use defmt::*; |
| 6 | use embassy_executor::Spawner; | 6 | use embassy_executor::Spawner; |
| 7 | use embassy_rp::pac::rtc::regs::{Rtc0, Rtc1}; | ||
| 8 | use embassy_rp::rtc::{DateTime, DayOfWeek, Rtc}; | 7 | use embassy_rp::rtc::{DateTime, DayOfWeek, Rtc}; |
| 9 | use embassy_time::{Duration, Timer}; | 8 | use embassy_time::{Duration, Timer}; |
| 10 | use {defmt_rtt as _, panic_probe as _}; | 9 | use {defmt_rtt as _, panic_probe as _}; |
| @@ -14,22 +13,18 @@ async fn main(_spawner: Spawner) { | |||
| 14 | let p = embassy_rp::init(Default::default()); | 13 | let p = embassy_rp::init(Default::default()); |
| 15 | info!("Wait for 20s"); | 14 | info!("Wait for 20s"); |
| 16 | 15 | ||
| 17 | let mut watchdog = embassy_rp::watchdog::Watchdog::new(p.WATCHDOG); | ||
| 18 | let mut rtc = Rtc::new(p.RTC); | 16 | let mut rtc = Rtc::new(p.RTC); |
| 19 | 17 | ||
| 20 | let rtc0 = Rtc0(watchdog.get_scratch0()); | 18 | if !rtc.is_running() { |
| 21 | let rtc1 = Rtc1(watchdog.get_scratch1()); | 19 | info!("Start RTC"); |
| 22 | if rtc1.year() >= 2020 { | ||
| 23 | rtc.restore(rtc1, rtc0); | ||
| 24 | } else { | ||
| 25 | let now = DateTime { | 20 | let now = DateTime { |
| 26 | year: 2020, | 21 | year: 2000, |
| 27 | month: 5, | 22 | month: 1, |
| 28 | day: 15, | 23 | day: 1, |
| 29 | day_of_week: DayOfWeek::Monday, | 24 | day_of_week: DayOfWeek::Saturday, |
| 30 | hour: 10, | 25 | hour: 0, |
| 31 | minute: 30, | 26 | minute: 0, |
| 32 | second: 50, | 27 | second: 0, |
| 33 | }; | 28 | }; |
| 34 | rtc.set_datetime(now).unwrap(); | 29 | rtc.set_datetime(now).unwrap(); |
| 35 | } | 30 | } |
| @@ -41,9 +36,6 @@ async fn main(_spawner: Spawner) { | |||
| 41 | "Now: {}-{:02}-{:02} {}:{:02}:{:02}", | 36 | "Now: {}-{:02}-{:02} {}:{:02}:{:02}", |
| 42 | dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second, | 37 | dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second, |
| 43 | ); | 38 | ); |
| 44 | let (rtc1, rtc0) = rtc.save(); | ||
| 45 | watchdog.set_scratch0(rtc0.0); | ||
| 46 | watchdog.set_scratch1(rtc1.0); | ||
| 47 | } | 39 | } |
| 48 | 40 | ||
| 49 | info!("Reboot."); | 41 | info!("Reboot."); |
