Merge branch 'bugfix/fix_some_wifi_bugs_260312_v5.4' into 'release/v5.4'

Bugfix/fix some wifi bugs 260312 v5.4

See merge request espressif/esp-idf!46542
This commit is contained in:
Jiang Jiang Jian
2026-03-13 19:19:27 +08:00
11 changed files with 64 additions and 6 deletions
+1 -1
View File
@@ -39,7 +39,7 @@ static _lock_t s_modem_prepare_lock;
#endif // SOC_PM_RETENTION_HAS_CLOCK_BUG && CONFIG_MAC_BB_PD #endif // SOC_PM_RETENTION_HAS_CLOCK_BUG && CONFIG_MAC_BB_PD
#if CONFIG_MAC_BB_PD #if CONFIG_MAC_BB_PD
#define MAC_BB_POWER_DOWN_CB_NO (3) #define MAC_BB_POWER_DOWN_CB_NO (4)
#define MAC_BB_POWER_UP_CB_NO (3) #define MAC_BB_POWER_UP_CB_NO (3)
static DRAM_ATTR mac_bb_power_down_cb_t s_mac_bb_power_down_cb[MAC_BB_POWER_DOWN_CB_NO]; static DRAM_ATTR mac_bb_power_down_cb_t s_mac_bb_power_down_cb[MAC_BB_POWER_DOWN_CB_NO];
+12 -1
View File
@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2015-2026 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -14,6 +14,7 @@ extern "C" {
#endif #endif
#define ESP_CAL_DATA_CHECK_FAIL 1 #define ESP_CAL_DATA_CHECK_FAIL 1
#define ESP_MODEM_RF_FLAG_UPDATE_CB_REQUIRED (SOC_PM_MODEM_RF_FLAG_UPDATE_WORKAROUND || CONFIG_ESP_WIFI_MODEM_RF_FLAG_UPDATE_DEBUG)
typedef struct { typedef struct {
uint8_t cmd_type; /* the command type of the current phy i2c master command memory config */ uint8_t cmd_type; /* the command type of the current phy i2c master command memory config */
@@ -243,6 +244,16 @@ uint32_t phy_ana_i2c_master_burst_rf_onoff(bool on);
void phy_wakeup_from_modem_state_extra_init(void); void phy_wakeup_from_modem_state_extra_init(void);
#endif #endif
#if SOC_PM_SUPPORT_PMU_MODEM_STATE && CONFIG_ESP_WIFI_ENHANCED_LIGHT_SLEEP && ESP_MODEM_RF_FLAG_UPDATE_CB_REQUIRED
/**
* @brief Update modem RF flag
*
* This function is called as a callback during MAC/BB power down operations.
* It checks if modem RF is already enabled and clears the RF power state accordingly.
*/
void esp_phy_modem_rf_flag_update(void);
#endif
#if SOC_PM_MODEM_RETENTION_BY_REGDMA && CONFIG_MAC_BB_PD #if SOC_PM_MODEM_RETENTION_BY_REGDMA && CONFIG_MAC_BB_PD
/** /**
* @brief PHY module sleep data (includes AGC, TX, NRX, BB, FE, etc..) initialize. * @brief PHY module sleep data (includes AGC, TX, NRX, BB, FE, etc..) initialize.
+18 -3
View File
@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2015-2026 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -60,6 +60,11 @@
extern wifi_mac_time_update_cb_t s_wifi_mac_time_update_cb; extern wifi_mac_time_update_cb_t s_wifi_mac_time_update_cb;
#endif #endif
#if SOC_PM_SUPPORT_PMU_MODEM_STATE && CONFIG_ESP_WIFI_ENHANCED_LIGHT_SLEEP
extern void pm_mac_modem_clear_rf_power_state(void);
extern bool pm_mac_modem_rf_already_enabled(void);
#endif
static const char* TAG = "phy_init"; static const char* TAG = "phy_init";
static _lock_t s_phy_access_lock; static _lock_t s_phy_access_lock;
@@ -296,6 +301,18 @@ static inline void phy_digital_regs_load(void)
} }
#endif // SOC_PM_MODEM_RETENTION_BY_BACKUPDMA #endif // SOC_PM_MODEM_RETENTION_BY_BACKUPDMA
#if SOC_PM_SUPPORT_PMU_MODEM_STATE && CONFIG_ESP_WIFI_ENHANCED_LIGHT_SLEEP && ESP_MODEM_RF_FLAG_UPDATE_CB_REQUIRED
void IRAM_ATTR esp_phy_modem_rf_flag_update(void)
{
if (pm_mac_modem_rf_already_enabled()) {
#if CONFIG_ESP_WIFI_MODEM_RF_FLAG_UPDATE_DEBUG
assert(0);
#endif
pm_mac_modem_clear_rf_power_state();
}
}
#endif
void esp_phy_enable(esp_phy_modem_t modem) void esp_phy_enable(esp_phy_modem_t modem)
{ {
_lock_acquire(&s_phy_access_lock); _lock_acquire(&s_phy_access_lock);
@@ -314,7 +331,6 @@ void esp_phy_enable(esp_phy_modem_t modem)
s_is_phy_calibrated = true; s_is_phy_calibrated = true;
} else { } else {
#if SOC_PM_SUPPORT_PMU_MODEM_STATE && CONFIG_ESP_WIFI_ENHANCED_LIGHT_SLEEP #if SOC_PM_SUPPORT_PMU_MODEM_STATE && CONFIG_ESP_WIFI_ENHANCED_LIGHT_SLEEP
extern bool pm_mac_modem_rf_already_enabled(void);
if (!pm_mac_modem_rf_already_enabled()) { if (!pm_mac_modem_rf_already_enabled()) {
if (sleep_modem_wifi_modem_state_enabled() && sleep_modem_wifi_modem_link_done()) { if (sleep_modem_wifi_modem_state_enabled() && sleep_modem_wifi_modem_link_done()) {
sleep_modem_wifi_do_phy_retention(true); sleep_modem_wifi_do_phy_retention(true);
@@ -382,7 +398,6 @@ void esp_phy_disable(esp_phy_modem_t modem)
phy_digital_regs_store(); phy_digital_regs_store();
#endif #endif
#if SOC_PM_SUPPORT_PMU_MODEM_STATE && CONFIG_ESP_WIFI_ENHANCED_LIGHT_SLEEP #if SOC_PM_SUPPORT_PMU_MODEM_STATE && CONFIG_ESP_WIFI_ENHANCED_LIGHT_SLEEP
extern void pm_mac_modem_clear_rf_power_state(void);
pm_mac_modem_clear_rf_power_state(); pm_mac_modem_clear_rf_power_state();
if (sleep_modem_wifi_modem_state_enabled()) { if (sleep_modem_wifi_modem_state_enabled()) {
sleep_modem_wifi_do_phy_retention(false); sleep_modem_wifi_do_phy_retention(false);
@@ -57,6 +57,7 @@ void IRAM_ATTR esp_system_reset_modules_on_exit(void)
SET_PERI_REG_MASK(PCR_PWM_CONF_REG, PCR_PWM_RST_EN); SET_PERI_REG_MASK(PCR_PWM_CONF_REG, PCR_PWM_RST_EN);
//ETM may directly control the GPIO or other peripherals even after CPU reset. Reset to stop these control. //ETM may directly control the GPIO or other peripherals even after CPU reset. Reset to stop these control.
SET_PERI_REG_MASK(PCR_ETM_CONF_REG, PCR_ETM_RST_EN); SET_PERI_REG_MASK(PCR_ETM_CONF_REG, PCR_ETM_RST_EN);
SET_PERI_REG_MASK(PCR_REGDMA_CONF_REG, PCR_REGDMA_RST_EN);
// Clear Peripheral clk rst // Clear Peripheral clk rst
CLEAR_PERI_REG_MASK(PCR_MSPI_CONF_REG, PCR_MSPI_RST_EN); CLEAR_PERI_REG_MASK(PCR_MSPI_CONF_REG, PCR_MSPI_RST_EN);
@@ -67,6 +68,7 @@ void IRAM_ATTR esp_system_reset_modules_on_exit(void)
CLEAR_PERI_REG_MASK(PCR_MODEM_CONF_REG, PCR_MODEM_RST_EN); CLEAR_PERI_REG_MASK(PCR_MODEM_CONF_REG, PCR_MODEM_RST_EN);
CLEAR_PERI_REG_MASK(PCR_PWM_CONF_REG, PCR_PWM_RST_EN); CLEAR_PERI_REG_MASK(PCR_PWM_CONF_REG, PCR_PWM_RST_EN);
CLEAR_PERI_REG_MASK(PCR_ETM_CONF_REG, PCR_ETM_RST_EN); CLEAR_PERI_REG_MASK(PCR_ETM_CONF_REG, PCR_ETM_RST_EN);
CLEAR_PERI_REG_MASK(PCR_REGDMA_CONF_REG, PCR_REGDMA_RST_EN);
// Reset crypto peripherals. This ensures a clean state for the crypto peripherals after a CPU restart // Reset crypto peripherals. This ensures a clean state for the crypto peripherals after a CPU restart
// and hence avoiding any possibility with crypto failure in ROM security workflows. // and hence avoiding any possibility with crypto failure in ROM security workflows.
@@ -53,6 +53,7 @@ void IRAM_ATTR esp_system_reset_modules_on_exit(void)
SET_PERI_REG_MASK(PCR_PWM_CONF_REG, PCR_PWM_RST_EN); SET_PERI_REG_MASK(PCR_PWM_CONF_REG, PCR_PWM_RST_EN);
//ETM may directly control the GPIO or other peripherals even after CPU reset. Reset to stop these control. //ETM may directly control the GPIO or other peripherals even after CPU reset. Reset to stop these control.
SET_PERI_REG_MASK(PCR_ETM_CONF_REG, PCR_ETM_RST_EN); SET_PERI_REG_MASK(PCR_ETM_CONF_REG, PCR_ETM_RST_EN);
SET_PERI_REG_MASK(PCR_REGDMA_CONF_REG, PCR_REGDMA_RST_EN);
// Clear Peripheral clk rst // Clear Peripheral clk rst
CLEAR_PERI_REG_MASK(PCR_MSPI_CONF_REG, PCR_MSPI_RST_EN); CLEAR_PERI_REG_MASK(PCR_MSPI_CONF_REG, PCR_MSPI_RST_EN);
@@ -79,6 +80,7 @@ void IRAM_ATTR esp_system_reset_modules_on_exit(void)
CLEAR_PERI_REG_MASK(PCR_HMAC_CONF_REG, PCR_HMAC_RST_EN); CLEAR_PERI_REG_MASK(PCR_HMAC_CONF_REG, PCR_HMAC_RST_EN);
CLEAR_PERI_REG_MASK(PCR_RSA_CONF_REG, PCR_RSA_RST_EN); CLEAR_PERI_REG_MASK(PCR_RSA_CONF_REG, PCR_RSA_RST_EN);
CLEAR_PERI_REG_MASK(PCR_SHA_CONF_REG, PCR_SHA_RST_EN); CLEAR_PERI_REG_MASK(PCR_SHA_CONF_REG, PCR_SHA_RST_EN);
CLEAR_PERI_REG_MASK(PCR_REGDMA_CONF_REG, PCR_REGDMA_RST_EN);
// UART's sclk is controlled in the PCR register and does not reset with the UART module. The ROM missed enabling // UART's sclk is controlled in the PCR register and does not reset with the UART module. The ROM missed enabling
// it when initializing the ROM UART. If it is not turned on, it will trigger LP_WDT in the ROM. // it when initializing the ROM UART. If it is not turned on, it will trigger LP_WDT in the ROM.
@@ -58,6 +58,7 @@ void IRAM_ATTR esp_system_reset_modules_on_exit(void)
SET_PERI_REG_MASK(PCR_SDIO_SLAVE_CONF_REG, PCR_SDIO_SLAVE_RST_EN); SET_PERI_REG_MASK(PCR_SDIO_SLAVE_CONF_REG, PCR_SDIO_SLAVE_RST_EN);
//ETM may directly control the GPIO or other peripherals even after CPU reset. Reset to stop these control. //ETM may directly control the GPIO or other peripherals even after CPU reset. Reset to stop these control.
SET_PERI_REG_MASK(PCR_ETM_CONF_REG, PCR_ETM_RST_EN); SET_PERI_REG_MASK(PCR_ETM_CONF_REG, PCR_ETM_RST_EN);
SET_PERI_REG_MASK(PCR_REGDMA_CONF_REG, PCR_REGDMA_RST_EN);
// Clear Peripheral clk rst // Clear Peripheral clk rst
CLEAR_PERI_REG_MASK(PCR_MSPI_CONF_REG, PCR_MSPI_RST_EN); CLEAR_PERI_REG_MASK(PCR_MSPI_CONF_REG, PCR_MSPI_RST_EN);
@@ -68,6 +69,7 @@ void IRAM_ATTR esp_system_reset_modules_on_exit(void)
CLEAR_PERI_REG_MASK(PCR_MODEM_CONF_REG, PCR_MODEM_RST_EN); CLEAR_PERI_REG_MASK(PCR_MODEM_CONF_REG, PCR_MODEM_RST_EN);
CLEAR_PERI_REG_MASK(PCR_SDIO_SLAVE_CONF_REG, PCR_SDIO_SLAVE_RST_EN); CLEAR_PERI_REG_MASK(PCR_SDIO_SLAVE_CONF_REG, PCR_SDIO_SLAVE_RST_EN);
CLEAR_PERI_REG_MASK(PCR_ETM_CONF_REG, PCR_ETM_RST_EN); CLEAR_PERI_REG_MASK(PCR_ETM_CONF_REG, PCR_ETM_RST_EN);
CLEAR_PERI_REG_MASK(PCR_REGDMA_CONF_REG, PCR_REGDMA_RST_EN);
// Reset crypto peripherals. This ensures a clean state for the crypto peripherals after a CPU restart // Reset crypto peripherals. This ensures a clean state for the crypto peripherals after a CPU restart
// and hence avoiding any possibility with crypto failure in ROM security workflows. // and hence avoiding any possibility with crypto failure in ROM security workflows.
@@ -50,6 +50,7 @@ void IRAM_ATTR esp_system_reset_modules_on_exit(void)
SET_PERI_REG_MASK(PCR_PWM_CONF_REG, PCR_PWM_RST_EN); SET_PERI_REG_MASK(PCR_PWM_CONF_REG, PCR_PWM_RST_EN);
//ETM may directly control the GPIO or other peripherals even after CPU reset. Reset to stop these control. //ETM may directly control the GPIO or other peripherals even after CPU reset. Reset to stop these control.
SET_PERI_REG_MASK(PCR_ETM_CONF_REG, PCR_ETM_RST_EN); SET_PERI_REG_MASK(PCR_ETM_CONF_REG, PCR_ETM_RST_EN);
SET_PERI_REG_MASK(PCR_REGDMA_CONF_REG, PCR_REGDMA_RST_EN);
// Clear Peripheral clk rst // Clear Peripheral clk rst
CLEAR_PERI_REG_MASK(PCR_MSPI_CONF_REG, PCR_MSPI_RST_EN); CLEAR_PERI_REG_MASK(PCR_MSPI_CONF_REG, PCR_MSPI_RST_EN);
@@ -60,6 +61,7 @@ void IRAM_ATTR esp_system_reset_modules_on_exit(void)
CLEAR_PERI_REG_MASK(PCR_MODEM_CONF_REG, PCR_MODEM_RST_EN); CLEAR_PERI_REG_MASK(PCR_MODEM_CONF_REG, PCR_MODEM_RST_EN);
CLEAR_PERI_REG_MASK(PCR_PWM_CONF_REG, PCR_PWM_RST_EN); CLEAR_PERI_REG_MASK(PCR_PWM_CONF_REG, PCR_PWM_RST_EN);
CLEAR_PERI_REG_MASK(PCR_ETM_CONF_REG, PCR_ETM_RST_EN); CLEAR_PERI_REG_MASK(PCR_ETM_CONF_REG, PCR_ETM_RST_EN);
CLEAR_PERI_REG_MASK(PCR_REGDMA_CONF_REG, PCR_REGDMA_RST_EN);
// Reset crypto peripherals. This ensures a clean state for the crypto peripherals after a CPU restart // Reset crypto peripherals. This ensures a clean state for the crypto peripherals after a CPU restart
// and hence avoiding any possibility with crypto failure in ROM security workflows. // and hence avoiding any possibility with crypto failure in ROM security workflows.
+9
View File
@@ -768,6 +768,15 @@ menu "Wi-Fi"
Select this configuration to free dynamic buffers during WiFi enterprise connection. Select this configuration to free dynamic buffers during WiFi enterprise connection.
This will enable chip to reduce heap consumption during WiFi enterprise connection. This will enable chip to reduce heap consumption during WiFi enterprise connection.
config ESP_WIFI_MODEM_RF_FLAG_UPDATE_DEBUG
bool "Enable debug assertions for modem RF flag update"
depends on ESP_WIFI_ENHANCED_LIGHT_SLEEP
default n
help
Enable debug assertions to verify modem RF flag update operations.
This option enables assert checks to verify that modem RF power state
is correctly cleared before pmu sleep.
endif # wifi enabled endif # wifi enabled
endmenu # Wi-Fi endmenu # Wi-Fi
+10 -1
View File
@@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2015-2026 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -236,7 +236,10 @@ static esp_err_t wifi_deinit_internal(void)
#if CONFIG_ESP_WIFI_ENHANCED_LIGHT_SLEEP #if CONFIG_ESP_WIFI_ENHANCED_LIGHT_SLEEP
esp_wifi_internal_modem_state_configure(false); esp_wifi_internal_modem_state_configure(false);
esp_pm_unregister_skip_light_sleep_callback(sleep_modem_wifi_modem_state_skip_light_sleep); esp_pm_unregister_skip_light_sleep_callback(sleep_modem_wifi_modem_state_skip_light_sleep);
#if ESP_MODEM_RF_FLAG_UPDATE_CB_REQUIRED
esp_unregister_mac_bb_pd_callback(esp_phy_modem_rf_flag_update);
#endif #endif
#endif /* CONFIG_ESP_WIFI_ENHANCED_LIGHT_SLEEP */
#ifdef CONFIG_ESP_PHY_ENABLED #ifdef CONFIG_ESP_PHY_ENABLED
esp_phy_modem_deinit(); esp_phy_modem_deinit();
#endif #endif
@@ -432,6 +435,12 @@ esp_err_t esp_wifi_init(const wifi_init_config_t *config)
if (sleep_modem_wifi_modem_state_enabled()) { if (sleep_modem_wifi_modem_state_enabled()) {
esp_pm_register_skip_light_sleep_callback(sleep_modem_wifi_modem_state_skip_light_sleep); esp_pm_register_skip_light_sleep_callback(sleep_modem_wifi_modem_state_skip_light_sleep);
esp_wifi_internal_modem_state_configure(true); /* require WiFi to enable automatically receives the beacon */ esp_wifi_internal_modem_state_configure(true); /* require WiFi to enable automatically receives the beacon */
#if ESP_MODEM_RF_FLAG_UPDATE_CB_REQUIRED
if (esp_register_mac_bb_pd_callback(esp_phy_modem_rf_flag_update) != ESP_OK) {
ESP_LOGE(TAG, "Failed to register modem RF flag update callback");
goto _deinit;
}
#endif
} }
#endif #endif
#if CONFIG_IDF_TARGET_ESP32 #if CONFIG_IDF_TARGET_ESP32
@@ -1447,6 +1447,10 @@ config SOC_EXT_MEM_CACHE_TAG_IN_CPU_DOMAIN
bool bool
default y default y
config SOC_PM_MODEM_RF_FLAG_UPDATE_WORKAROUND
bool
default y
config SOC_PM_PAU_LINK_NUM config SOC_PM_PAU_LINK_NUM
int int
default 4 default 4
@@ -565,6 +565,8 @@
#define SOC_PM_RETENTION_HAS_CLOCK_BUG (1) #define SOC_PM_RETENTION_HAS_CLOCK_BUG (1)
#define SOC_EXT_MEM_CACHE_TAG_IN_CPU_DOMAIN (1) #define SOC_EXT_MEM_CACHE_TAG_IN_CPU_DOMAIN (1)
#define SOC_PM_MODEM_RF_FLAG_UPDATE_WORKAROUND (1)
#define SOC_PM_PAU_LINK_NUM (4) #define SOC_PM_PAU_LINK_NUM (4)
#define SOC_PM_PAU_REGDMA_LINK_MULTI_ADDR (1) #define SOC_PM_PAU_REGDMA_LINK_MULTI_ADDR (1)
#define SOC_PM_PAU_REGDMA_LINK_WIFIMAC (1) #define SOC_PM_PAU_REGDMA_LINK_WIFIMAC (1)