From 568dd3d823264bb178f02cf1c9f2a2230305c97e Mon Sep 17 00:00:00 2001 From: wuzhenghui Date: Mon, 13 Mar 2023 20:49:36 +0800 Subject: [PATCH 1/2] Revert "optimize deep sleep current in wifi softap mode" This reverts commit 344ec80fadae35cadf46b997b7758bf5f1873946. --- components/esp_hw_support/port/esp32/rtc_sleep.c | 1 - components/esp_hw_support/port/esp32c3/rtc_sleep.c | 1 - components/esp_hw_support/port/esp32s2/rtc_sleep.c | 1 - components/esp_hw_support/port/esp32s3/rtc_sleep.c | 1 - 4 files changed, 4 deletions(-) diff --git a/components/esp_hw_support/port/esp32/rtc_sleep.c b/components/esp_hw_support/port/esp32/rtc_sleep.c index 98bfa9644a..a458caeb6a 100644 --- a/components/esp_hw_support/port/esp32/rtc_sleep.c +++ b/components/esp_hw_support/port/esp32/rtc_sleep.c @@ -206,7 +206,6 @@ void rtc_sleep_init(rtc_sleep_config_t cfg) 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); - CLEAR_PERI_REG_MASK(RTC_CNTL_OPTIONS0_REG, RTC_CNTL_BB_I2C_FORCE_PU); } else { CLEAR_PERI_REG_MASK(RTC_CNTL_DIG_PWC_REG, RTC_CNTL_DG_WRAP_PD_EN); } diff --git a/components/esp_hw_support/port/esp32c3/rtc_sleep.c b/components/esp_hw_support/port/esp32c3/rtc_sleep.c index 179f6e93dd..27b9fe435c 100644 --- a/components/esp_hw_support/port/esp32c3/rtc_sleep.c +++ b/components/esp_hw_support/port/esp32c3/rtc_sleep.c @@ -153,7 +153,6 @@ void rtc_sleep_init(rtc_sleep_config_t cfg) 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); - CLEAR_PERI_REG_MASK(RTC_CNTL_OPTIONS0_REG, RTC_CNTL_BB_I2C_FORCE_PU); } else { SET_PERI_REG_MASK(RTC_CNTL_BIAS_CONF_REG, RTC_CNTL_DG_VDD_DRV_B_SLP_EN); REG_SET_FIELD(RTC_CNTL_BIAS_CONF_REG, RTC_CNTL_DG_VDD_DRV_B_SLP, RTC_CNTL_DG_VDD_DRV_B_SLP_DEFAULT); diff --git a/components/esp_hw_support/port/esp32s2/rtc_sleep.c b/components/esp_hw_support/port/esp32s2/rtc_sleep.c index c138239934..1e5e1f61f5 100644 --- a/components/esp_hw_support/port/esp32s2/rtc_sleep.c +++ b/components/esp_hw_support/port/esp32s2/rtc_sleep.c @@ -154,7 +154,6 @@ void rtc_sleep_init(rtc_sleep_config_t cfg) 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); - CLEAR_PERI_REG_MASK(RTC_CNTL_OPTIONS0_REG, RTC_CNTL_BB_I2C_FORCE_PU); } else { SET_PERI_REG_MASK(RTC_CNTL_REG, RTC_CNTL_REGULATOR_FORCE_PU); CLEAR_PERI_REG_MASK(RTC_CNTL_DIG_PWC_REG, RTC_CNTL_DG_WRAP_PD_EN); diff --git a/components/esp_hw_support/port/esp32s3/rtc_sleep.c b/components/esp_hw_support/port/esp32s3/rtc_sleep.c index 14d3cf3876..1e0d70fe29 100644 --- a/components/esp_hw_support/port/esp32s3/rtc_sleep.c +++ b/components/esp_hw_support/port/esp32s3/rtc_sleep.c @@ -209,7 +209,6 @@ void rtc_sleep_init(rtc_sleep_config_t cfg) 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); - CLEAR_PERI_REG_MASK(RTC_CNTL_OPTIONS0_REG, RTC_CNTL_BB_I2C_FORCE_PU); } else { REG_SET_FIELD(RTC_CNTL_REGULATOR_DRV_CTRL_REG, RTC_CNTL_DG_VDD_DRV_B_SLP, RTC_CNTL_DG_VDD_DRV_B_SLP_DEFAULT); CLEAR_PERI_REG_MASK(RTC_CNTL_DIG_PWC_REG, RTC_CNTL_DG_WRAP_PD_EN); From 64d5421d8babe1ed4f5f34f8f3b79107d8074f82 Mon Sep 17 00:00:00 2001 From: wuzhenghui Date: Mon, 13 Mar 2023 20:45:48 +0800 Subject: [PATCH 2/2] deep sleep: close rf to optimize sleep current --- components/esp_hw_support/sleep_modes.c | 8 +++++++- components/esp_phy/include/esp_phy_init.h | 6 ++++++ components/esp_phy/src/phy_init.c | 5 +++++ docs/en/api-reference/system/sleep_modes.rst | 2 +- docs/zh_CN/api-reference/system/sleep_modes.rst | 2 +- 5 files changed, 20 insertions(+), 3 deletions(-) diff --git a/components/esp_hw_support/sleep_modes.c b/components/esp_hw_support/sleep_modes.c index e8357997b7..c68f3aea86 100644 --- a/components/esp_hw_support/sleep_modes.c +++ b/components/esp_hw_support/sleep_modes.c @@ -447,7 +447,13 @@ static uint32_t IRAM_ATTR esp_sleep_start(uint32_t pd_flags) } #endif - if (!deep_sleep) { + if (deep_sleep) { + extern bool esp_phy_is_initialized(void); + if (esp_phy_is_initialized()){ + extern void phy_close_rf(void); + phy_close_rf(); + } + } else { misc_modules_sleep_prepare(); } diff --git a/components/esp_phy/include/esp_phy_init.h b/components/esp_phy/include/esp_phy_init.h index bcf3e289d3..1422b43245 100644 --- a/components/esp_phy/include/esp_phy_init.h +++ b/components/esp_phy/include/esp_phy_init.h @@ -150,6 +150,12 @@ esp_err_t esp_phy_store_cal_data_to_nvs(const esp_phy_calibration_data_t* cal_da */ esp_err_t esp_phy_erase_cal_data_in_nvs(void); +/** + * @brief Get phy initialize status + * @return return true if phy is already initialized. + */ +bool esp_phy_is_initialized(void); + /** * @brief Enable PHY and RF module * diff --git a/components/esp_phy/src/phy_init.c b/components/esp_phy/src/phy_init.c index 664e89b6a6..08e67003d2 100644 --- a/components/esp_phy/src/phy_init.c +++ b/components/esp_phy/src/phy_init.c @@ -224,6 +224,11 @@ static inline void phy_digital_regs_load(void) } } +bool esp_phy_is_initialized(void) +{ + return s_is_phy_calibrated; +} + void esp_phy_enable(void) { _lock_acquire(&s_phy_access_lock); diff --git a/docs/en/api-reference/system/sleep_modes.rst b/docs/en/api-reference/system/sleep_modes.rst index 792038c1ee..8374cc442f 100644 --- a/docs/en/api-reference/system/sleep_modes.rst +++ b/docs/en/api-reference/system/sleep_modes.rst @@ -31,7 +31,7 @@ Once wakeup sources are configured, the application can enter sleep mode using : Wi-Fi/Bluetooth and Sleep Modes --------------------------------- - In Deep-sleep and Light-sleep modes, the wireless peripherals are powered down. Before entering Deep-sleep or Light-sleep modes, the application must disable Wi-Fi and Bluetooth using the appropriate calls (i.e., :cpp:func:`esp_bluedroid_disable`, :cpp:func:`esp_bt_controller_disable`, :cpp:func:`esp_wifi_stop`). Wi-Fi and Bluetooth connections will not be maintained in Deep-sleep or Light-sleep mode, even if these functions are not called. + In Deep-sleep and Light-sleep modes, the wireless peripherals are powered down. Before entering Light-sleep modes, the application must disable Wi-Fi and Bluetooth using the appropriate calls (i.e., :cpp:func:`esp_bluedroid_disable`, :cpp:func:`esp_bt_controller_disable`, :cpp:func:`esp_wifi_stop`). In both Deep-sleep and Light-sleep modes, Wi-Fi and Bluetooth connection cannot be maintained. .. only:: not SOC_BT_SUPPORTED diff --git a/docs/zh_CN/api-reference/system/sleep_modes.rst b/docs/zh_CN/api-reference/system/sleep_modes.rst index 15f65ff100..e1245c2a6f 100644 --- a/docs/zh_CN/api-reference/system/sleep_modes.rst +++ b/docs/zh_CN/api-reference/system/sleep_modes.rst @@ -38,7 +38,7 @@ Light-sleep 和 Deep-sleep 模式有多种唤醒源。这些唤醒源也可以 睡眠模式下的 Wi-Fi 功能 -------------------------- - 在 Light-sleep 和 Deep-sleep 模式下,无线外设会被断电。因此,在进入这两种睡眠模式前,应用程序必须调用恰当的函数 (:cpp:func:`esp_wifi_stop`) 来禁用 Wi-Fi。在 Light-sleep 或 Deep-sleep 模式下,即使不调用此函数也无法连接 Wi-Fi。 + 在 Light-sleep 和 Deep-sleep 模式下,无线外设会被断电。因此,在进入 Light-sleep 模式前,应用程序必须调用恰当的函数 (:cpp:func:`esp_wifi_stop`) 来禁用 Wi-Fi。在 Light-sleep 和 Deep-sleep 模式下均无法保持 Wi-Fi 的连接。 如需保持 Wi-Fi 连接,请启用 Wi-Fi Modem-sleep 模式和自动 Light-sleep 模式(请参阅 :doc:`电源管理 API `)。在这两种模式下,Wi-Fi 驱动程序发出请求时,系统将自动从睡眠中被唤醒,从而保持与 AP 的连接。