pub fn init(config: Config) -> Peripherals {
    crate::soc::pre_init();

    system::disable_peripherals();

    let mut peripherals = Peripherals::take();

    // RTC domain must be enabled before we try to disable
    let mut rtc = crate::rtc_cntl::Rtc::new(peripherals.LPWR.reborrow());

    // Handle watchdog configuration with defaults
    cfg_if::cfg_if! {
        if #[cfg(feature = "unstable")]
        {
            #[cfg(not(any(esp32, esp32s2)))]
            if config.watchdog.swd() {
                rtc.swd.enable();
            } else {
                rtc.swd.disable();
            }

            match config.watchdog.rwdt() {
                WatchdogStatus::Enabled(duration) => {
                    rtc.rwdt.enable();
                    rtc.rwdt
                        .set_timeout(crate::rtc_cntl::RwdtStage::Stage0, duration);
                }
                WatchdogStatus::Disabled => {
                    rtc.rwdt.disable();
                }
            }

            #[cfg(timergroup_timg0)]
            match config.watchdog.timg0() {
                WatchdogStatus::Enabled(duration) => {
                    let mut timg0_wd = crate::timer::timg::Wdt::<crate::peripherals::TIMG0<'static>>::new();
                    timg0_wd.enable();
                    timg0_wd.set_timeout(crate::timer::timg::MwdtStage::Stage0, duration);
                }
                WatchdogStatus::Disabled => {
                    crate::timer::timg::Wdt::<crate::peripherals::TIMG0<'static>>::new().disable();
                }
            }

            #[cfg(timergroup_timg1)]
            match config.watchdog.timg1() {
                WatchdogStatus::Enabled(duration) => {
                    let mut timg1_wd = crate::timer::timg::Wdt::<crate::peripherals::TIMG1<'static>>::new();
                    timg1_wd.enable();
                    timg1_wd.set_timeout(crate::timer::timg::MwdtStage::Stage0, duration);
                }
                WatchdogStatus::Disabled => {
                    crate::timer::timg::Wdt::<crate::peripherals::TIMG1<'static>>::new().disable();
                }
            }
        }
        else
        {
            #[cfg(not(any(esp32, esp32s2)))]
            rtc.swd.disable();

            rtc.rwdt.disable();

            #[cfg(timergroup_timg0)]
            crate::timer::timg::Wdt::<crate::peripherals::TIMG0<'static>>::new().disable();

            #[cfg(timergroup_timg1)]
            crate::timer::timg::Wdt::<crate::peripherals::TIMG1<'static>>::new().disable();
        }
    }

    Clocks::init(config.cpu_clock);

    #[cfg(esp32)]
    crate::time::time_init();

    crate::gpio::interrupt::bind_default_interrupt_handler();

    #[cfg(feature = "psram")]
    crate::psram::init_psram(config.psram);

    peripherals
}
Initialize the system.

This function sets up the CPU clock and watchdog, then, returns the
peripherals and clocks.
esp-hal/src/lib.rs