Skip to content

Commit

Permalink
Merge branch 'bugfix/fix_some_wifi_bugs_240111_v5.0' into 'release/v5.0'
Browse files Browse the repository at this point in the history
fix(wifi): fix some wifi bugs (Backport v5.0)

See merge request espressif/esp-idf!28410
  • Loading branch information
jack0c committed Jan 11, 2024
2 parents 2b16bd7 + be1be3c commit 6e4eb1a
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 30 deletions.
13 changes: 11 additions & 2 deletions components/esp_psram/Kconfig.spiram.common
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,20 @@ config SPIRAM_BOOT_INIT
config SPIRAM_IGNORE_NOTFOUND
bool "Ignore PSRAM when not found"
default "n"
depends on SPIRAM_BOOT_INIT && !SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY
depends on SPIRAM_BOOT_INIT && !SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY && !SPIRAM_ALLOW_NOINIT_SEG_EXTERNAL_MEMORY
help
Normally, if psram initialization is enabled during compile time but not found at runtime, it
is seen as an error making the CPU panic. If this is enabled, booting will complete
but no PSRAM will be available.
but no PSRAM will be available. If PSRAM failed to initialize, the following configs may be affected
and may need to be corrected manually. SPIRAM_TRY_ALLOCATE_WIFI_LWIP will affect some LWIP and WiFi buffer
default values and range values. Enable SPIRAM_TRY_ALLOCATE_WIFI_LWIP, ESP_WIFI_AMSDU_TX_ENABLED,
ESP_WIFI_CACHE_TX_BUFFER_NUM and use static WiFi Tx buffer may cause potential memory exhaustion issues.
Suggest disable SPIRAM_TRY_ALLOCATE_WIFI_LWIP.
Suggest disable ESP_WIFI_AMSDU_TX_ENABLED.
Suggest disable ESP_WIFI_CACHE_TX_BUFFER_NUM, need clear CONFIG_FEATURE_CACHE_TX_BUF_BIT of
config->feature_caps.
Suggest change ESP_WIFI_TX_BUFFER from static to dynamic. Also suggest to adjust some buffer numbers to the
values used without PSRAM case. Such as, ESP_WIFI_STATIC_TX_BUFFER_NUM, ESP_WIFI_DYNAMIC_TX_BUFFER_NUM.

choice SPIRAM_USE
prompt "SPI RAM access method"
Expand Down
4 changes: 4 additions & 0 deletions components/esp_wifi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,8 @@ if(CONFIG_ESP32_WIFI_ENABLED)
endforeach()
endif()

if(CONFIG_SPIRAM)
idf_component_optional_requires(PRIVATE esp_psram)
endif()

endif()
37 changes: 33 additions & 4 deletions components/esp_wifi/include/esp_wifi.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -176,7 +176,6 @@ typedef struct {
#endif

extern const wpa_crypto_funcs_t g_wifi_default_wpa_crypto_funcs;
extern uint64_t g_wifi_feature_caps;

#define WIFI_INIT_CONFIG_MAGIC 0x1F2F3F4F

Expand Down Expand Up @@ -210,11 +209,41 @@ extern uint64_t g_wifi_feature_caps;
#define WIFI_STA_DISCONNECTED_PM_ENABLED false
#endif

#define CONFIG_FEATURE_WPA3_SAE_BIT (1<<0)
#if CONFIG_ESP_WIFI_ENABLE_WPA3_SAE
#define WIFI_ENABLE_WPA3_SAE (1<<0)
#else
#define WIFI_ENABLE_WPA3_SAE 0
#endif

#if CONFIG_SPIRAM
#define WIFI_ENABLE_SPIRAM (1<<1)
#else
#define WIFI_ENABLE_SPIRAM 0
#endif

#if CONFIG_ESP_WIFI_FTM_INITIATOR_SUPPORT
#define WIFI_FTM_INITIATOR (1<<2)
#else
#define WIFI_FTM_INITIATOR 0
#endif

#if CONFIG_ESP_WIFI_FTM_RESPONDER_SUPPORT
#define WIFI_FTM_RESPONDER (1<<3)
#else
#define WIFI_FTM_RESPONDER 0
#endif

#define CONFIG_FEATURE_WPA3_SAE_BIT (1<<0)
#define CONFIG_FEATURE_CACHE_TX_BUF_BIT (1<<1)
#define CONFIG_FEATURE_FTM_INITIATOR_BIT (1<<2)
#define CONFIG_FEATURE_FTM_RESPONDER_BIT (1<<3)

/* Set additional WiFi features and capabilities */
#define WIFI_FEATURE_CAPS (WIFI_ENABLE_WPA3_SAE | \
WIFI_ENABLE_SPIRAM | \
WIFI_FTM_INITIATOR | \
WIFI_FTM_RESPONDER)

#define WIFI_INIT_CONFIG_DEFAULT() { \
.osi_funcs = &g_wifi_osi_funcs, \
.wpa_crypto_funcs = g_wifi_default_wpa_crypto_funcs, \
Expand All @@ -236,7 +265,7 @@ extern uint64_t g_wifi_feature_caps;
.wifi_task_core_id = WIFI_TASK_CORE_ID,\
.beacon_max_len = WIFI_SOFTAP_BEACON_MAX_LEN, \
.mgmt_sbuf_num = WIFI_MGMT_SBUF_NUM, \
.feature_caps = g_wifi_feature_caps, \
.feature_caps = WIFI_FEATURE_CAPS, \
.sta_disconnected_pm = WIFI_STA_DISCONNECTED_PM_ENABLED, \
.espnow_max_encrypt_num = CONFIG_ESP_WIFI_ESPNOW_MAX_ENCRYPT_NUM, \
.magic = WIFI_INIT_CONFIG_MAGIC\
Expand Down
1 change: 1 addition & 0 deletions components/esp_wifi/include/esp_wifi_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ typedef struct {
bool channel_filter_en; /**< enable to turn on channel filter to smooth adjacent sub-carrier. Disable it to keep independence of adjacent sub-carrier. Default enabled */
bool manu_scale; /**< manually scale the CSI data by left shifting or automatically scale the CSI data. If set true, please set the shift bits. false: automatically. true: manually. Default false */
uint8_t shift; /**< manually left shift bits of the scale of the CSI data. The range of the left shift bits is 0~15 */
bool dump_ack_en; /**< enable to dump 802.11 ACK frame, default disabled */
} wifi_csi_config_t;

/**
Expand Down
61 changes: 38 additions & 23 deletions components/esp_wifi/src/wifi_init.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -18,6 +18,9 @@
#include "esp_coexist_internal.h"
#include "esp_phy_init.h"
#include "phy.h"
#if __has_include("esp_psram.h")
#include "esp_psram.h"
#endif

static bool s_wifi_inited = false;

Expand All @@ -41,23 +44,6 @@ static esp_pm_lock_handle_t s_wifi_modem_sleep_lock;
wifi_mac_time_update_cb_t s_wifi_mac_time_update_cb = NULL;
#endif

/* Set additional WiFi features and capabilities */
uint64_t g_wifi_feature_caps =
#if CONFIG_ESP32_WIFI_ENABLE_WPA3_SAE
CONFIG_FEATURE_WPA3_SAE_BIT |
#endif
#if CONFIG_SPIRAM
CONFIG_FEATURE_CACHE_TX_BUF_BIT |
#endif
#if CONFIG_ESP_WIFI_FTM_INITIATOR_SUPPORT
CONFIG_FEATURE_FTM_INITIATOR_BIT |
#endif
#if CONFIG_ESP_WIFI_FTM_RESPONDER_SUPPORT
CONFIG_FEATURE_FTM_RESPONDER_BIT |
#endif
0;


static const char* TAG = "wifi_init";

static void __attribute__((constructor)) s_set_default_wifi_log_level(void)
Expand Down Expand Up @@ -197,17 +183,46 @@ static void esp_wifi_config_info(void)
#endif
}

#if CONFIG_SPIRAM
static esp_err_t esp_wifi_psram_check(const wifi_init_config_t *config)
{
#if CONFIG_SPIRAM_IGNORE_NOTFOUND
if (!esp_psram_is_initialized()) {
if (config->feature_caps & CONFIG_FEATURE_CACHE_TX_BUF_BIT) {
ESP_LOGW(TAG, "WiFi cache TX buffers should be disabled when initialize SPIRAM failed");
}
if (config->tx_buf_type == 0) {
ESP_LOGW(TAG, "TX buffers type should be changed from static to dynamic when initialize SPIRAM failed");
}
#ifdef CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP
ESP_LOGW(TAG, "WiFi/LWIP prefer SPIRAM should be disabled when initialize SPIRAM failed");
#endif
if (config->amsdu_tx_enable) {
ESP_LOGW(TAG, "WiFi AMSDU TX should be disabled when initialize SPIRAM failed");
}
}
#endif
if ((config->feature_caps & CONFIG_FEATURE_CACHE_TX_BUF_BIT) && (WIFI_CACHE_TX_BUFFER_NUM == 0)) {
ESP_LOGE(TAG, "Number of WiFi cache TX buffers should not equal 0 when enable SPIRAM");
return ESP_ERR_NOT_SUPPORTED;
}
return ESP_OK;
}
#endif

esp_err_t esp_wifi_init(const wifi_init_config_t *config)
{
if (s_wifi_inited) {
return ESP_OK;
}

if ((config->feature_caps & CONFIG_FEATURE_CACHE_TX_BUF_BIT) && (WIFI_CACHE_TX_BUFFER_NUM == 0))
{
ESP_LOGE(TAG, "Number of WiFi cache TX buffers should not equal 0 when enable SPIRAM");
return ESP_ERR_NOT_SUPPORTED;
esp_err_t result = ESP_OK;
#ifdef CONFIG_SPIRAM
result = esp_wifi_psram_check(config);
if (result != ESP_OK) {
return result;
}
#endif

#if CONFIG_ESP_WIFI_SLP_IRAM_OPT
esp_pm_register_light_sleep_default_params_config_callback(esp_wifi_internal_update_light_sleep_default_params);
Expand Down Expand Up @@ -261,7 +276,7 @@ esp_err_t esp_wifi_init(const wifi_init_config_t *config)
#endif
esp_wifi_set_log_level();
esp_wifi_power_domain_on();
esp_err_t result = esp_wifi_init_internal(config);
result = esp_wifi_init_internal(config);
if (result == ESP_OK) {
#if CONFIG_MAC_BB_PD
esp_mac_bb_pd_mem_init();
Expand Down

0 comments on commit 6e4eb1a

Please sign in to comment.