Add RWDT disable in RTC_CNTL for ESP32/S2/S3
This commit is contained in:
parent
9982e38766
commit
f2884bd3b8
@ -35,6 +35,8 @@ pub mod gpio;
|
|||||||
#[cfg_attr(feature = "esp32c3", path = "interrupt/riscv.rs")]
|
#[cfg_attr(feature = "esp32c3", path = "interrupt/riscv.rs")]
|
||||||
pub mod interrupt;
|
pub mod interrupt;
|
||||||
pub mod prelude;
|
pub mod prelude;
|
||||||
|
#[cfg(not(feature = "esp32c3"))]
|
||||||
|
pub mod rtc_cntl;
|
||||||
pub mod serial;
|
pub mod serial;
|
||||||
pub mod timer;
|
pub mod timer;
|
||||||
|
|
||||||
@ -43,6 +45,8 @@ pub use gpio::*;
|
|||||||
pub use interrupt::*;
|
pub use interrupt::*;
|
||||||
use procmacros;
|
use procmacros;
|
||||||
pub use procmacros::ram;
|
pub use procmacros::ram;
|
||||||
|
#[cfg(not(feature = "esp32c3"))]
|
||||||
|
pub use rtc_cntl::RtcCntl;
|
||||||
pub use serial::Serial;
|
pub use serial::Serial;
|
||||||
pub use timer::Timer;
|
pub use timer::Timer;
|
||||||
|
|
||||||
|
|||||||
29
esp-hal-common/src/rtc_cntl.rs
Normal file
29
esp-hal-common/src/rtc_cntl.rs
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
use crate::pac::RTC_CNTL;
|
||||||
|
|
||||||
|
pub struct RtcCntl {
|
||||||
|
rtc_cntl: RTC_CNTL,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RtcCntl {
|
||||||
|
pub fn new(rtc_cntl: RTC_CNTL) -> Self {
|
||||||
|
Self { rtc_cntl }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Enable/disable write protection for WDT registers
|
||||||
|
fn set_wdt_write_protection(&mut self, enable: bool) {
|
||||||
|
let wkey = if enable { 0u32 } else { 0x50D8_3AA1 };
|
||||||
|
|
||||||
|
self.rtc_cntl.wdtwprotect.write(|w| unsafe { w.bits(wkey) });
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Global switch for RTC_CNTL watchdog functionality
|
||||||
|
pub fn set_wdt_global_enable(&mut self, enable: bool) {
|
||||||
|
self.set_wdt_write_protection(false);
|
||||||
|
|
||||||
|
self.rtc_cntl
|
||||||
|
.wdtconfig0
|
||||||
|
.modify(|_, w| w.wdt_en().bit(enable).wdt_flashboot_mod_en().clear_bit());
|
||||||
|
|
||||||
|
self.set_wdt_write_protection(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,7 +1,7 @@
|
|||||||
#![no_std]
|
#![no_std]
|
||||||
#![no_main]
|
#![no_main]
|
||||||
|
|
||||||
use esp32_hal::{gpio::IO, pac::Peripherals, prelude::*, Delay, Timer};
|
use esp32_hal::{gpio::IO, pac::Peripherals, prelude::*, Delay, RtcCntl, Timer};
|
||||||
use panic_halt as _;
|
use panic_halt as _;
|
||||||
use xtensa_lx_rt::entry;
|
use xtensa_lx_rt::entry;
|
||||||
|
|
||||||
@ -9,10 +9,12 @@ use xtensa_lx_rt::entry;
|
|||||||
fn main() -> ! {
|
fn main() -> ! {
|
||||||
let peripherals = Peripherals::take().unwrap();
|
let peripherals = Peripherals::take().unwrap();
|
||||||
|
|
||||||
// Disable the TIMG watchdog timer.
|
|
||||||
let mut timer0 = Timer::new(peripherals.TIMG0);
|
let mut timer0 = Timer::new(peripherals.TIMG0);
|
||||||
|
let mut rtc_cntl = RtcCntl::new(peripherals.RTC_CNTL);
|
||||||
|
|
||||||
|
// Disable MWDT and RWDT (Watchdog) flash boot protection
|
||||||
timer0.disable();
|
timer0.disable();
|
||||||
|
rtc_cntl.set_wdt_global_enable(false);
|
||||||
|
|
||||||
// Set GPIO15 as an output, and set its state high initially.
|
// Set GPIO15 as an output, and set its state high initially.
|
||||||
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
|
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||||
|
|||||||
@ -8,6 +8,7 @@ use esp32_hal::{
|
|||||||
pac::{self, Peripherals, UART0},
|
pac::{self, Peripherals, UART0},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
Delay,
|
Delay,
|
||||||
|
RtcCntl,
|
||||||
Serial,
|
Serial,
|
||||||
Timer,
|
Timer,
|
||||||
};
|
};
|
||||||
@ -34,8 +35,11 @@ fn main() -> ! {
|
|||||||
// Disable the TIMG watchdog timer.
|
// Disable the TIMG watchdog timer.
|
||||||
let mut timer0 = Timer::new(peripherals.TIMG0);
|
let mut timer0 = Timer::new(peripherals.TIMG0);
|
||||||
let serial0 = Serial::new(peripherals.UART0).unwrap();
|
let serial0 = Serial::new(peripherals.UART0).unwrap();
|
||||||
|
let mut rtc_cntl = RtcCntl::new(peripherals.RTC_CNTL);
|
||||||
|
|
||||||
|
// Disable MWDT and RWDT (Watchdog) flash boot protection
|
||||||
timer0.disable();
|
timer0.disable();
|
||||||
|
rtc_cntl.set_wdt_global_enable(false);
|
||||||
|
|
||||||
// Set GPIO15 as an output, and set its state high initially.
|
// Set GPIO15 as an output, and set its state high initially.
|
||||||
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
|
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
use core::fmt::Write;
|
use core::fmt::Write;
|
||||||
|
|
||||||
use esp32_hal::{pac::Peripherals, prelude::*, Serial, Timer};
|
use esp32_hal::{pac::Peripherals, prelude::*, RtcCntl, Serial, Timer};
|
||||||
use nb::block;
|
use nb::block;
|
||||||
use panic_halt as _;
|
use panic_halt as _;
|
||||||
use xtensa_lx_rt::entry;
|
use xtensa_lx_rt::entry;
|
||||||
@ -14,9 +14,11 @@ fn main() -> ! {
|
|||||||
|
|
||||||
let mut timer0 = Timer::new(peripherals.TIMG0);
|
let mut timer0 = Timer::new(peripherals.TIMG0);
|
||||||
let mut serial0 = Serial::new(peripherals.UART0).unwrap();
|
let mut serial0 = Serial::new(peripherals.UART0).unwrap();
|
||||||
|
let mut rtc_cntl = RtcCntl::new(peripherals.RTC_CNTL);
|
||||||
|
|
||||||
// Disable watchdog timer
|
// Disable MWDT and RWDT (Watchdog) flash boot protection
|
||||||
timer0.disable();
|
timer0.disable();
|
||||||
|
rtc_cntl.set_wdt_global_enable(false);
|
||||||
|
|
||||||
timer0.start(10_000_000u64);
|
timer0.start(10_000_000u64);
|
||||||
|
|
||||||
|
|||||||
@ -7,6 +7,7 @@ use esp32_hal::{
|
|||||||
pac::{Peripherals, UART0},
|
pac::{Peripherals, UART0},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
ram,
|
ram,
|
||||||
|
RtcCntl,
|
||||||
Serial,
|
Serial,
|
||||||
Timer,
|
Timer,
|
||||||
};
|
};
|
||||||
@ -29,9 +30,11 @@ fn main() -> ! {
|
|||||||
|
|
||||||
let mut timer0 = Timer::new(peripherals.TIMG0);
|
let mut timer0 = Timer::new(peripherals.TIMG0);
|
||||||
let mut serial0 = Serial::new(peripherals.UART0).unwrap();
|
let mut serial0 = Serial::new(peripherals.UART0).unwrap();
|
||||||
|
let mut rtc_cntl = RtcCntl::new(peripherals.RTC_CNTL);
|
||||||
|
|
||||||
// Disable watchdog timer
|
// Disable MWDT and RWDT (Watchdog) flash boot protection
|
||||||
timer0.disable();
|
timer0.disable();
|
||||||
|
rtc_cntl.set_wdt_global_enable(false);
|
||||||
|
|
||||||
timer0.start(10_000_000u64);
|
timer0.start(10_000_000u64);
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
#![no_std]
|
#![no_std]
|
||||||
|
|
||||||
pub use embedded_hal as ehal;
|
pub use embedded_hal as ehal;
|
||||||
pub use esp_hal_common::{pac, prelude, Delay, Serial, Timer};
|
pub use esp_hal_common::{pac, prelude, Delay, RtcCntl, Serial, Timer};
|
||||||
|
|
||||||
pub use self::gpio::IO;
|
pub use self::gpio::IO;
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
#![no_std]
|
#![no_std]
|
||||||
#![no_main]
|
#![no_main]
|
||||||
|
|
||||||
use esp32s2_hal::{gpio::IO, pac::Peripherals, prelude::*, Delay, Timer};
|
use esp32s2_hal::{gpio::IO, pac::Peripherals, prelude::*, Delay, RtcCntl, Timer};
|
||||||
use panic_halt as _;
|
use panic_halt as _;
|
||||||
use xtensa_lx_rt::entry;
|
use xtensa_lx_rt::entry;
|
||||||
|
|
||||||
@ -9,10 +9,12 @@ use xtensa_lx_rt::entry;
|
|||||||
fn main() -> ! {
|
fn main() -> ! {
|
||||||
let peripherals = Peripherals::take().unwrap();
|
let peripherals = Peripherals::take().unwrap();
|
||||||
|
|
||||||
// Disable the TIMG watchdog timer.
|
|
||||||
let mut timer0 = Timer::new(peripherals.TIMG0);
|
let mut timer0 = Timer::new(peripherals.TIMG0);
|
||||||
|
let mut rtc_cntl = RtcCntl::new(peripherals.RTC_CNTL);
|
||||||
|
|
||||||
|
// Disable MWDT and RWDT (Watchdog) flash boot protection
|
||||||
timer0.disable();
|
timer0.disable();
|
||||||
|
rtc_cntl.set_wdt_global_enable(false);
|
||||||
|
|
||||||
// Set GPIO4 as an output, and set its state high initially.
|
// Set GPIO4 as an output, and set its state high initially.
|
||||||
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
|
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||||
|
|||||||
@ -8,6 +8,7 @@ use esp32s2_hal::{
|
|||||||
pac::{self, Peripherals, UART0},
|
pac::{self, Peripherals, UART0},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
Delay,
|
Delay,
|
||||||
|
RtcCntl,
|
||||||
Serial,
|
Serial,
|
||||||
Timer,
|
Timer,
|
||||||
};
|
};
|
||||||
@ -31,11 +32,13 @@ static mut BUTTON: CriticalSectionMutex<RefCell<Option<Gpio0<Input<PullDown>>>>>
|
|||||||
fn main() -> ! {
|
fn main() -> ! {
|
||||||
let peripherals = Peripherals::take().unwrap();
|
let peripherals = Peripherals::take().unwrap();
|
||||||
|
|
||||||
// Disable the TIMG watchdog timer.
|
|
||||||
let mut timer0 = Timer::new(peripherals.TIMG0);
|
let mut timer0 = Timer::new(peripherals.TIMG0);
|
||||||
|
let mut rtc_cntl = RtcCntl::new(peripherals.RTC_CNTL);
|
||||||
let serial0 = Serial::new(peripherals.UART0).unwrap();
|
let serial0 = Serial::new(peripherals.UART0).unwrap();
|
||||||
|
|
||||||
|
// Disable MWDT and RWDT (Watchdog) flash boot protection
|
||||||
timer0.disable();
|
timer0.disable();
|
||||||
|
rtc_cntl.set_wdt_global_enable(false);
|
||||||
|
|
||||||
// Set GPIO4 as an output, and set its state high initially.
|
// Set GPIO4 as an output, and set its state high initially.
|
||||||
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
|
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
use core::fmt::Write;
|
use core::fmt::Write;
|
||||||
|
|
||||||
use esp32s2_hal::{pac::Peripherals, prelude::*, Serial, Timer};
|
use esp32s2_hal::{pac::Peripherals, prelude::*, RtcCntl, Serial, Timer};
|
||||||
use nb::block;
|
use nb::block;
|
||||||
use panic_halt as _;
|
use panic_halt as _;
|
||||||
use xtensa_lx_rt::entry;
|
use xtensa_lx_rt::entry;
|
||||||
@ -13,10 +13,12 @@ fn main() -> ! {
|
|||||||
let peripherals = Peripherals::take().unwrap();
|
let peripherals = Peripherals::take().unwrap();
|
||||||
|
|
||||||
let mut timer0 = Timer::new(peripherals.TIMG0);
|
let mut timer0 = Timer::new(peripherals.TIMG0);
|
||||||
|
let mut rtc_cntl = RtcCntl::new(peripherals.RTC_CNTL);
|
||||||
let mut serial0 = Serial::new(peripherals.UART0).unwrap();
|
let mut serial0 = Serial::new(peripherals.UART0).unwrap();
|
||||||
|
|
||||||
// Disable watchdog timer
|
// Disable MWDT and RWDT (Watchdog) flash boot protection
|
||||||
timer0.disable();
|
timer0.disable();
|
||||||
|
rtc_cntl.set_wdt_global_enable(false);
|
||||||
|
|
||||||
timer0.start(40_000_000u64);
|
timer0.start(40_000_000u64);
|
||||||
|
|
||||||
|
|||||||
@ -7,6 +7,7 @@ use esp32s2_hal::{
|
|||||||
pac::{Peripherals, UART0},
|
pac::{Peripherals, UART0},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
ram,
|
ram,
|
||||||
|
RtcCntl,
|
||||||
Serial,
|
Serial,
|
||||||
Timer,
|
Timer,
|
||||||
};
|
};
|
||||||
@ -28,10 +29,12 @@ fn main() -> ! {
|
|||||||
let peripherals = Peripherals::take().unwrap();
|
let peripherals = Peripherals::take().unwrap();
|
||||||
|
|
||||||
let mut timer0 = Timer::new(peripherals.TIMG0);
|
let mut timer0 = Timer::new(peripherals.TIMG0);
|
||||||
|
let mut rtc_cntl = RtcCntl::new(peripherals.RTC_CNTL);
|
||||||
let mut serial0 = Serial::new(peripherals.UART0).unwrap();
|
let mut serial0 = Serial::new(peripherals.UART0).unwrap();
|
||||||
|
|
||||||
// Disable watchdog timer
|
// Disable MWDT and RWDT (Watchdog) flash boot protection
|
||||||
timer0.disable();
|
timer0.disable();
|
||||||
|
rtc_cntl.set_wdt_global_enable(false);
|
||||||
|
|
||||||
timer0.start(10_000_000u64);
|
timer0.start(10_000_000u64);
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
#![no_std]
|
#![no_std]
|
||||||
|
|
||||||
pub use embedded_hal as ehal;
|
pub use embedded_hal as ehal;
|
||||||
pub use esp_hal_common::{pac, prelude, ram, Delay, Serial, Timer};
|
pub use esp_hal_common::{pac, prelude, ram, Delay, RtcCntl, Serial, Timer};
|
||||||
|
|
||||||
pub use self::gpio::IO;
|
pub use self::gpio::IO;
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
#![no_std]
|
#![no_std]
|
||||||
#![no_main]
|
#![no_main]
|
||||||
|
|
||||||
use esp32s3_hal::{gpio::IO, pac::Peripherals, prelude::*, Delay, Timer};
|
use esp32s3_hal::{gpio::IO, pac::Peripherals, prelude::*, Delay, RtcCntl, Timer};
|
||||||
use panic_halt as _;
|
use panic_halt as _;
|
||||||
use xtensa_lx_rt::entry;
|
use xtensa_lx_rt::entry;
|
||||||
|
|
||||||
@ -9,10 +9,12 @@ use xtensa_lx_rt::entry;
|
|||||||
fn main() -> ! {
|
fn main() -> ! {
|
||||||
let peripherals = Peripherals::take().unwrap();
|
let peripherals = Peripherals::take().unwrap();
|
||||||
|
|
||||||
// Disable the TIMG watchdog timer.
|
|
||||||
let mut timer0 = Timer::new(peripherals.TIMG0);
|
let mut timer0 = Timer::new(peripherals.TIMG0);
|
||||||
|
let mut rtc_cntl = RtcCntl::new(peripherals.RTC_CNTL);
|
||||||
|
|
||||||
|
// Disable MWDT and RWDT (Watchdog) flash boot protection
|
||||||
timer0.disable();
|
timer0.disable();
|
||||||
|
rtc_cntl.set_wdt_global_enable(false);
|
||||||
|
|
||||||
// Set GPIO4 as an output, and set its state high initially.
|
// Set GPIO4 as an output, and set its state high initially.
|
||||||
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
|
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||||
|
|||||||
@ -8,6 +8,7 @@ use esp32s3_hal::{
|
|||||||
pac::{self, Peripherals, UART0},
|
pac::{self, Peripherals, UART0},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
Delay,
|
Delay,
|
||||||
|
RtcCntl,
|
||||||
Serial,
|
Serial,
|
||||||
Timer,
|
Timer,
|
||||||
};
|
};
|
||||||
@ -31,11 +32,13 @@ static mut BUTTON: SpinLockMutex<RefCell<Option<Gpio0<Input<PullDown>>>>> =
|
|||||||
fn main() -> ! {
|
fn main() -> ! {
|
||||||
let peripherals = Peripherals::take().unwrap();
|
let peripherals = Peripherals::take().unwrap();
|
||||||
|
|
||||||
// Disable the TIMG watchdog timer.
|
|
||||||
let mut timer0 = Timer::new(peripherals.TIMG0);
|
let mut timer0 = Timer::new(peripherals.TIMG0);
|
||||||
|
let mut rtc_cntl = RtcCntl::new(peripherals.RTC_CNTL);
|
||||||
let serial0 = Serial::new(peripherals.UART0).unwrap();
|
let serial0 = Serial::new(peripherals.UART0).unwrap();
|
||||||
|
|
||||||
|
// Disable MWDT and RWDT (Watchdog) flash boot protection
|
||||||
timer0.disable();
|
timer0.disable();
|
||||||
|
rtc_cntl.set_wdt_global_enable(false);
|
||||||
|
|
||||||
// Set GPIO4 as an output, and set its state high initially.
|
// Set GPIO4 as an output, and set its state high initially.
|
||||||
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
|
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
use core::fmt::Write;
|
use core::fmt::Write;
|
||||||
|
|
||||||
use esp32s3_hal::{pac::Peripherals, prelude::*, Serial, Timer};
|
use esp32s3_hal::{pac::Peripherals, prelude::*, RtcCntl, Serial, Timer};
|
||||||
use nb::block;
|
use nb::block;
|
||||||
use panic_halt as _;
|
use panic_halt as _;
|
||||||
use xtensa_lx_rt::entry;
|
use xtensa_lx_rt::entry;
|
||||||
@ -13,10 +13,12 @@ fn main() -> ! {
|
|||||||
let peripherals = Peripherals::take().unwrap();
|
let peripherals = Peripherals::take().unwrap();
|
||||||
|
|
||||||
let mut timer0 = Timer::new(peripherals.TIMG0);
|
let mut timer0 = Timer::new(peripherals.TIMG0);
|
||||||
|
let mut rtc_cntl = RtcCntl::new(peripherals.RTC_CNTL);
|
||||||
let mut serial0 = Serial::new(peripherals.UART0).unwrap();
|
let mut serial0 = Serial::new(peripherals.UART0).unwrap();
|
||||||
|
|
||||||
// Disable watchdog timer
|
// Disable MWDT and RWDT (Watchdog) flash boot protection
|
||||||
timer0.disable();
|
timer0.disable();
|
||||||
|
rtc_cntl.set_wdt_global_enable(false);
|
||||||
|
|
||||||
timer0.start(40_000_000u64);
|
timer0.start(40_000_000u64);
|
||||||
|
|
||||||
|
|||||||
@ -7,6 +7,7 @@ use esp32s3_hal::{
|
|||||||
pac::{Peripherals, UART0},
|
pac::{Peripherals, UART0},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
ram,
|
ram,
|
||||||
|
RtcCntl,
|
||||||
Serial,
|
Serial,
|
||||||
Timer,
|
Timer,
|
||||||
};
|
};
|
||||||
@ -28,10 +29,12 @@ fn main() -> ! {
|
|||||||
let peripherals = Peripherals::take().unwrap();
|
let peripherals = Peripherals::take().unwrap();
|
||||||
|
|
||||||
let mut timer0 = Timer::new(peripherals.TIMG0);
|
let mut timer0 = Timer::new(peripherals.TIMG0);
|
||||||
|
let mut rtc_cntl = RtcCntl::new(peripherals.RTC_CNTL);
|
||||||
let mut serial0 = Serial::new(peripherals.UART0).unwrap();
|
let mut serial0 = Serial::new(peripherals.UART0).unwrap();
|
||||||
|
|
||||||
// Disable watchdog timer
|
// Disable MWDT and RWDT (Watchdog) flash boot protection
|
||||||
timer0.disable();
|
timer0.disable();
|
||||||
|
rtc_cntl.set_wdt_global_enable(false);
|
||||||
|
|
||||||
timer0.start(10_000_000u64);
|
timer0.start(10_000_000u64);
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
#![no_std]
|
#![no_std]
|
||||||
|
|
||||||
pub use embedded_hal as ehal;
|
pub use embedded_hal as ehal;
|
||||||
pub use esp_hal_common::{pac, prelude, ram, Delay, Serial, Timer};
|
pub use esp_hal_common::{pac, prelude, ram, Delay, RtcCntl, Serial, Timer};
|
||||||
|
|
||||||
pub use self::gpio::IO;
|
pub use self::gpio::IO;
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user