diff --git a/components/bootloader_support/src/bootloader_random.c b/components/bootloader_support/src/bootloader_random.c index b58ebe941d..5a00d0cf5a 100644 --- a/components/bootloader_support/src/bootloader_random.c +++ b/components/bootloader_support/src/bootloader_random.c @@ -135,4 +135,8 @@ void bootloader_random_disable(void) /* Reset i2s peripheral */ SET_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_I2S0_RST); CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_I2S0_RST); + + /* Disable pull supply voltage to SAR ADC */ + CLEAR_PERI_REG_MASK(RTC_CNTL_TEST_MUX_REG, RTC_CNTL_ENT_RTC); + SET_PERI_REG_BITS(RTC_CNTL_TEST_MUX_REG, RTC_CNTL_DTEST_RTC, 0, RTC_CNTL_DTEST_RTC_S); } diff --git a/components/esp32/deep_sleep.c b/components/esp32/deep_sleep.c index 3eef7ca29d..4d672402e1 100644 --- a/components/esp32/deep_sleep.c +++ b/components/esp32/deep_sleep.c @@ -22,6 +22,7 @@ #include "rom/uart.h" #include "soc/cpu.h" #include "soc/rtc_cntl_reg.h" +#include "soc/sens_reg.h" #include "soc/dport_reg.h" #include "driver/rtc_io.h" #include "freertos/FreeRTOS.h" @@ -111,6 +112,13 @@ void IRAM_ATTR esp_deep_sleep_start() // Decide which power domains can be powered down uint32_t pd_flags = get_power_down_flags(); + // Shut down parts of RTC which may have been left enabled by the wireless drivers + CLEAR_PERI_REG_MASK(RTC_CNTL_ANA_CONF_REG, + RTC_CNTL_CKGEN_I2C_PU | RTC_CNTL_PLL_I2C_PU | + RTC_CNTL_RFRX_PBUS_PU | RTC_CNTL_TXRF_I2C_PU); + + SET_PERI_REG_BITS(SENS_SAR_MEAS_WAIT2_REG, SENS_FORCE_XPD_SAR_M, 0, SENS_FORCE_XPD_SAR_S); + // Configure pins for external wakeup if (s_config.wakeup_triggers & EXT_EVENT0_TRIG_EN) { ext0_wakeup_prepare(); diff --git a/components/esp32/include/esp_deep_sleep.h b/components/esp32/include/esp_deep_sleep.h index a6251e2dec..aba74b30da 100644 --- a/components/esp32/include/esp_deep_sleep.h +++ b/components/esp32/include/esp_deep_sleep.h @@ -164,6 +164,14 @@ void esp_deep_sleep_start() __attribute__((noreturn)); * Call to this function is equivalent to a call to esp_deep_sleep_enable_timer_wakeup * followed by a call to esp_deep_sleep_start. * + * esp_deep_sleep does not shut down WiFi, BT, and higher level protocol + * connections gracefully. + * Make sure relevant WiFi and BT stack functions are called to close any + * connections and deinitialize the peripherals. These include: + * - esp_bluedroid_disable + * - esp_bt_controller_disable + * - esp_wifi_stop + * * This function does not return. * * @param time_in_us deep-sleep time, unit: microsecond diff --git a/examples/protocols/sntp/main/sntp_main.c b/examples/protocols/sntp/main/sntp_main.c index f128323dcb..438505d7b6 100644 --- a/examples/protocols/sntp/main/sntp_main.c +++ b/examples/protocols/sntp/main/sntp_main.c @@ -110,6 +110,8 @@ static void obtain_time(void) time(&now); localtime_r(&now, &timeinfo); } + + ESP_ERROR_CHECK( esp_wifi_stop() ); } static void initialize_sntp(void)