From de5156bb2082bf576a05728e742742709ac75973 Mon Sep 17 00:00:00 2001 From: zhangyanjiao Date: Fri, 2 Sep 2022 19:22:40 +0800 Subject: [PATCH 1/6] esp_wifi: report rssi info in wifi event --- components/esp_wifi/include/esp_wifi_types.h | 1 + 1 file changed, 1 insertion(+) diff --git a/components/esp_wifi/include/esp_wifi_types.h b/components/esp_wifi/include/esp_wifi_types.h index 85614b0b91..84fc83398c 100644 --- a/components/esp_wifi/include/esp_wifi_types.h +++ b/components/esp_wifi/include/esp_wifi_types.h @@ -641,6 +641,7 @@ typedef struct { uint8_t ssid_len; /**< SSID length of disconnected AP */ uint8_t bssid[6]; /**< BSSID of disconnected AP */ uint8_t reason; /**< reason of disconnection */ + int8_t rssi; /**< rssi of disconnection */ } wifi_event_sta_disconnected_t; /** Argument structure for WIFI_EVENT_STA_AUTHMODE_CHANGE event */ From 2d2177b4ad4d487118ed83e16b3c291300576ccf Mon Sep 17 00:00:00 2001 From: liuning Date: Fri, 22 Jul 2022 18:11:10 +0800 Subject: [PATCH 2/6] blufi: update version to 1.3 record connecting status, got ip status, maximum retry, connection end info (reason code, rssi) and provide greater information to phone --- .../bt/common/api/include/api/esp_blufi_api.h | 10 +++ .../common/btc/profile/esp/blufi/blufi_prf.c | 30 +++++++ .../btc/profile/esp/blufi/include/blufi_int.h | 5 +- .../bluetooth/blufi/main/Kconfig.projbuild | 10 +++ .../bluetooth/blufi/main/blufi_example_main.c | 85 ++++++++++++++++--- 5 files changed, 129 insertions(+), 11 deletions(-) create mode 100644 examples/bluetooth/blufi/main/Kconfig.projbuild diff --git a/components/bt/common/api/include/api/esp_blufi_api.h b/components/bt/common/api/include/api/esp_blufi_api.h index 63109b20f1..ce7fe3a0d3 100644 --- a/components/bt/common/api/include/api/esp_blufi_api.h +++ b/components/bt/common/api/include/api/esp_blufi_api.h @@ -57,6 +57,8 @@ typedef enum { typedef enum { ESP_BLUFI_STA_CONN_SUCCESS = 0x00, ESP_BLUFI_STA_CONN_FAIL = 0x01, + ESP_BLUFI_STA_CONNECTING = 0x02, + ESP_BLUFI_STA_NO_IP = 0x03, } esp_blufi_sta_conn_state_t; /// BLUFI init status @@ -82,6 +84,8 @@ typedef enum { ESP_BLUFI_READ_PARAM_ERROR, ESP_BLUFI_MAKE_PUBLIC_ERROR, ESP_BLUFI_DATA_FORMAT_ERROR, + ESP_BLUFI_CALC_MD5_ERROR, + ESP_BLUFI_WIFI_SCAN_FAIL, } esp_blufi_error_state_t; /** @@ -105,6 +109,12 @@ typedef struct { bool softap_max_conn_num_set; /*!< is max connection number of softap interface set */ uint8_t softap_channel; /*!< channel of softap interface */ bool softap_channel_set; /*!< is channel of softap interface set */ + uint8_t sta_max_conn_retry; /*!< max retry of sta establish connection */ + bool sta_max_conn_retry_set; /*!< is max retry of sta establish connection set */ + uint8_t sta_conn_end_reason; /*!< reason of sta connection end */ + bool sta_conn_end_reason_set; /*!< is reason of sta connection end set */ + int8_t sta_conn_rssi; /*!< rssi of sta connection */ + bool sta_conn_rssi_set; /*!< is rssi of sta connection set */ } esp_blufi_extra_info_t; /** @brief Description of an WiFi AP */ diff --git a/components/bt/common/btc/profile/esp/blufi/blufi_prf.c b/components/bt/common/btc/profile/esp/blufi/blufi_prf.c index d2c7f7ebff..f93faf439b 100644 --- a/components/bt/common/btc/profile/esp/blufi/blufi_prf.c +++ b/components/bt/common/btc/profile/esp/blufi/blufi_prf.c @@ -321,6 +321,21 @@ static void btc_blufi_wifi_conn_report(uint8_t opmode, uint8_t sta_conn_state, u *p++ = 1; *p++ = info->softap_channel; } + if (info->sta_max_conn_retry_set) { + *p++ = BLUFI_TYPE_DATA_SUBTYPE_STA_MAX_CONN_RETRY; + *p++ = 1; + *p++ = info->sta_max_conn_retry; + } + if (info->sta_conn_end_reason_set) { + *p++ = BLUFI_TYPE_DATA_SUBTYPE_STA_CONN_END_REASON; + *p++ = 1; + *p++ = info->sta_conn_end_reason; + } + if (info->sta_conn_rssi_set) { + *p++ = BLUFI_TYPE_DATA_SUBTYPE_STA_CONN_RSSI; + *p++ = 1; + *p++ = info->sta_conn_rssi; + } } if (p - data > data_len) { BTC_TRACE_ERROR("%s len error %d %d\n", __func__, (int)(p - data), data_len); @@ -714,6 +729,21 @@ void btc_blufi_call_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src) dst->wifi_conn_report.extra_info->softap_channel = src_info->softap_channel; dst->wifi_conn_report.extra_info_len += (1 + 2); } + if (src_info->sta_max_conn_retry_set) { + dst->wifi_conn_report.extra_info->sta_max_conn_retry_set = src_info->sta_max_conn_retry_set; + dst->wifi_conn_report.extra_info->sta_max_conn_retry = src_info->sta_max_conn_retry; + dst->wifi_conn_report.extra_info_len += (1 + 2); + } + if (src_info->sta_conn_end_reason_set) { + dst->wifi_conn_report.extra_info->sta_conn_end_reason_set = src_info->sta_conn_end_reason_set; + dst->wifi_conn_report.extra_info->sta_conn_end_reason = src_info->sta_conn_end_reason; + dst->wifi_conn_report.extra_info_len += (1 + 2); + } + if (src_info->sta_conn_rssi_set) { + dst->wifi_conn_report.extra_info->sta_conn_rssi_set = src_info->sta_conn_rssi_set; + dst->wifi_conn_report.extra_info->sta_conn_rssi = src_info->sta_conn_rssi; + dst->wifi_conn_report.extra_info_len += (1 + 2); + } break; } case BTC_BLUFI_ACT_SEND_WIFI_LIST:{ diff --git a/components/bt/common/btc/profile/esp/blufi/include/blufi_int.h b/components/bt/common/btc/profile/esp/blufi/include/blufi_int.h index 996621e048..be2c72c78d 100644 --- a/components/bt/common/btc/profile/esp/blufi/include/blufi_int.h +++ b/components/bt/common/btc/profile/esp/blufi/include/blufi_int.h @@ -20,7 +20,7 @@ #if (BLUFI_INCLUDED == TRUE) #define BTC_BLUFI_GREAT_VER 0x01 //Version + Subversion -#define BTC_BLUFI_SUB_VER 0x02 //Version + Subversion +#define BTC_BLUFI_SUB_VER 0x03 //Version + Subversion #define BTC_BLUFI_VERSION ((BTC_BLUFI_GREAT_VER<<8)|BTC_BLUFI_SUB_VER) //Version + Subversion typedef UINT8 tGATT_IF; @@ -129,6 +129,9 @@ extern tBLUFI_ENV *blufi_env_ptr; #define BLUFI_TYPE_DATA_SUBTYPE_WIFI_LIST 0x11 #define BLUFI_TYPE_DATA_SUBTYPE_ERROR_INFO 0x12 #define BLUFI_TYPE_DATA_SUBTYPE_CUSTOM_DATA 0x13 +#define BLUFI_TYPE_DATA_SUBTYPE_STA_MAX_CONN_RETRY 0x14 +#define BLUFI_TYPE_DATA_SUBTYPE_STA_CONN_END_REASON 0x15 +#define BLUFI_TYPE_DATA_SUBTYPE_STA_CONN_RSSI 0x16 #define BLUFI_TYPE_IS_CTRL(type) (BLUFI_GET_TYPE((type)) == BLUFI_TYPE_CTRL) #define BLUFI_TYPE_IS_DATA(type) (BLUFI_GET_TYPE((type)) == BLUFI_TYPE_DATA) diff --git a/examples/bluetooth/blufi/main/Kconfig.projbuild b/examples/bluetooth/blufi/main/Kconfig.projbuild new file mode 100644 index 0000000000..3ede60cb2e --- /dev/null +++ b/examples/bluetooth/blufi/main/Kconfig.projbuild @@ -0,0 +1,10 @@ +menu "Example Configuration" + + config EXAMPLE_WIFI_CONNECTION_MAXIMUM_RETRY + int "WiFi connection maximum retry" + range 0 255 + default 2 + help + WiFi connection maximum retry, from 0 to 255. + +endmenu diff --git a/examples/bluetooth/blufi/main/blufi_example_main.c b/examples/bluetooth/blufi/main/blufi_example_main.c index 06921e44e7..313e1f7005 100644 --- a/examples/bluetooth/blufi/main/blufi_example_main.c +++ b/examples/bluetooth/blufi/main/blufi_example_main.c @@ -33,6 +33,10 @@ #include "esp_blufi.h" +#define EXAMPLE_WIFI_CONNECTION_MAXIMUM_RETRY CONFIG_EXAMPLE_WIFI_CONNECTION_MAXIMUM_RETRY +#define EXAMPLE_INVALID_REASON 255 +#define EXAMPLE_INVALID_RSSI -128 + static void example_event_callback(esp_blufi_cb_event_t event, esp_blufi_cb_param_t *param); #define WIFI_LIST_NUM 10 @@ -48,13 +52,53 @@ static EventGroupHandle_t wifi_event_group; to the AP with an IP? */ const int CONNECTED_BIT = BIT0; +static uint8_t example_wifi_retry = 0; + /* store the station info for send back to phone */ static bool gl_sta_connected = false; +static bool gl_sta_got_ip = false; static bool ble_is_connected = false; static uint8_t gl_sta_bssid[6]; static uint8_t gl_sta_ssid[32]; static int gl_sta_ssid_len; static wifi_sta_list_t gl_sta_list; +static bool gl_sta_is_connecting = false; +static esp_blufi_extra_info_t gl_sta_conn_info; + +static void example_record_wifi_conn_info(int rssi, uint8_t reason) +{ + memset(&gl_sta_conn_info, 0, sizeof(esp_blufi_extra_info_t)); + if (gl_sta_is_connecting) { + gl_sta_conn_info.sta_max_conn_retry_set = true; + gl_sta_conn_info.sta_max_conn_retry = EXAMPLE_WIFI_CONNECTION_MAXIMUM_RETRY; + } else { + gl_sta_conn_info.sta_conn_rssi_set = true; + gl_sta_conn_info.sta_conn_rssi = rssi; + gl_sta_conn_info.sta_conn_end_reason_set = true; + gl_sta_conn_info.sta_conn_end_reason = reason; + } +} + +static void example_wifi_connect(void) +{ + example_wifi_retry = 0; + gl_sta_is_connecting = (esp_wifi_connect() == ESP_OK); + example_record_wifi_conn_info(EXAMPLE_INVALID_RSSI, EXAMPLE_INVALID_REASON); +} + +static bool example_wifi_reconnect(void) +{ + bool ret; + if (gl_sta_is_connecting && example_wifi_retry++ < EXAMPLE_WIFI_CONNECTION_MAXIMUM_RETRY) { + BLUFI_INFO("BLUFI WiFi starts reconnection\n"); + gl_sta_is_connecting = (esp_wifi_connect() == ESP_OK); + example_record_wifi_conn_info(EXAMPLE_INVALID_RSSI, EXAMPLE_INVALID_REASON); + ret = true; + } else { + ret = false; + } + return ret; +} static int softap_get_current_connection_number(void) { @@ -85,6 +129,7 @@ static void ip_event_handler(void* arg, esp_event_base_t event_base, info.sta_bssid_set = true; info.sta_ssid = gl_sta_ssid; info.sta_ssid_len = gl_sta_ssid_len; + gl_sta_got_ip = true; if (ble_is_connected == true) { esp_blufi_send_wifi_conn_report(mode, ESP_BLUFI_STA_CONN_SUCCESS, softap_get_current_connection_number(), &info); } else { @@ -102,27 +147,35 @@ static void wifi_event_handler(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data) { wifi_event_sta_connected_t *event; + wifi_event_sta_disconnected_t *disconnected_event; wifi_mode_t mode; switch (event_id) { case WIFI_EVENT_STA_START: - esp_wifi_connect(); + example_wifi_connect(); break; case WIFI_EVENT_STA_CONNECTED: gl_sta_connected = true; + gl_sta_is_connecting = false; event = (wifi_event_sta_connected_t*) event_data; memcpy(gl_sta_bssid, event->bssid, 6); memcpy(gl_sta_ssid, event->ssid, event->ssid_len); gl_sta_ssid_len = event->ssid_len; break; case WIFI_EVENT_STA_DISCONNECTED: + /* Only handle reconnection during connecting */ + if (gl_sta_connected == false && example_wifi_reconnect() == false) { + gl_sta_is_connecting = false; + disconnected_event = (wifi_event_sta_disconnected_t*) event_data; + example_record_wifi_conn_info(disconnected_event->rssi, disconnected_event->reason); + } /* This is a workaround as ESP32 WiFi libs don't currently auto-reassociate. */ gl_sta_connected = false; + gl_sta_got_ip = false; memset(gl_sta_ssid, 0, 32); memset(gl_sta_bssid, 0, 6); gl_sta_ssid_len = 0; - esp_wifi_connect(); xEventGroupClearBits(wifi_event_group, CONNECTED_BIT); break; case WIFI_EVENT_AP_START: @@ -131,9 +184,17 @@ static void wifi_event_handler(void* arg, esp_event_base_t event_base, /* TODO: get config or information of softap, then set to report extra_info */ if (ble_is_connected == true) { if (gl_sta_connected) { - esp_blufi_send_wifi_conn_report(mode, ESP_BLUFI_STA_CONN_SUCCESS, softap_get_current_connection_number(), NULL); + esp_blufi_extra_info_t info; + memset(&info, 0, sizeof(esp_blufi_extra_info_t)); + memcpy(info.sta_bssid, gl_sta_bssid, 6); + info.sta_bssid_set = true; + info.sta_ssid = gl_sta_ssid; + info.sta_ssid_len = gl_sta_ssid_len; + esp_blufi_send_wifi_conn_report(mode, gl_sta_got_ip ? ESP_BLUFI_STA_CONN_SUCCESS : ESP_BLUFI_STA_NO_IP, softap_get_current_connection_number(), &info); + } else if (gl_sta_is_connecting) { + esp_blufi_send_wifi_conn_report(mode, ESP_BLUFI_STA_CONNECTING, softap_get_current_connection_number(), &gl_sta_conn_info); } else { - esp_blufi_send_wifi_conn_report(mode, ESP_BLUFI_STA_CONN_FAIL, softap_get_current_connection_number(), NULL); + esp_blufi_send_wifi_conn_report(mode, ESP_BLUFI_STA_CONN_FAIL, softap_get_current_connection_number(), &gl_sta_conn_info); } } else { BLUFI_INFO("BLUFI BLE is not connected yet\n"); @@ -209,6 +270,7 @@ static void initialise_wifi(void) wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); ESP_ERROR_CHECK( esp_wifi_init(&cfg) ); ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA) ); + example_record_wifi_conn_info(EXAMPLE_INVALID_RSSI, EXAMPLE_INVALID_REASON); ESP_ERROR_CHECK( esp_wifi_start() ); } @@ -255,7 +317,7 @@ static void example_event_callback(esp_blufi_cb_event_t event, esp_blufi_cb_para so disconnect wifi before connection. */ esp_wifi_disconnect(); - esp_wifi_connect(); + example_wifi_connect(); break; case ESP_BLUFI_EVENT_REQ_DISCONNECT_FROM_AP: BLUFI_INFO("BLUFI requset wifi disconnect from AP\n"); @@ -271,17 +333,17 @@ static void example_event_callback(esp_blufi_cb_event_t event, esp_blufi_cb_para esp_wifi_get_mode(&mode); - - if (gl_sta_connected) { memset(&info, 0, sizeof(esp_blufi_extra_info_t)); memcpy(info.sta_bssid, gl_sta_bssid, 6); info.sta_bssid_set = true; info.sta_ssid = gl_sta_ssid; info.sta_ssid_len = gl_sta_ssid_len; - esp_blufi_send_wifi_conn_report(mode, ESP_BLUFI_STA_CONN_SUCCESS, softap_get_current_connection_number(), &info); + esp_blufi_send_wifi_conn_report(mode, gl_sta_got_ip ? ESP_BLUFI_STA_CONN_SUCCESS : ESP_BLUFI_STA_NO_IP, softap_get_current_connection_number(), &info); + } else if (gl_sta_is_connecting) { + esp_blufi_send_wifi_conn_report(mode, ESP_BLUFI_STA_CONNECTING, softap_get_current_connection_number(), &gl_sta_conn_info); } else { - esp_blufi_send_wifi_conn_report(mode, ESP_BLUFI_STA_CONN_FAIL, softap_get_current_connection_number(), NULL); + esp_blufi_send_wifi_conn_report(mode, ESP_BLUFI_STA_CONN_FAIL, softap_get_current_connection_number(), &gl_sta_conn_info); } BLUFI_INFO("BLUFI get wifi status from AP\n"); @@ -356,7 +418,10 @@ static void example_event_callback(esp_blufi_cb_event_t event, esp_blufi_cb_para .channel = 0, .show_hidden = false }; - esp_wifi_scan_start(&scanConf, true); + esp_err_t ret = esp_wifi_scan_start(&scanConf, true); + if (ret != ESP_OK) { + esp_blufi_send_error_info(ESP_BLUFI_WIFI_SCAN_FAIL); + } break; } case ESP_BLUFI_EVENT_RECV_CUSTOM_DATA: From 6a66453e9463d69dc23e520548b21fcd628ca942 Mon Sep 17 00:00:00 2001 From: liuning Date: Mon, 19 Sep 2022 16:44:31 +0800 Subject: [PATCH 3/6] docs: update BluFi documentation --- docs/en/api-guides/blufi.rst | 19 +++++++++++++++++-- docs/zh_CN/api-guides/blufi.rst | 19 +++++++++++++++++-- examples/bluetooth/blufi/README.md | 6 +++--- 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/docs/en/api-guides/blufi.rst b/docs/en/api-guides/blufi.rst index 9d7bfb120b..cb5fcfd3a5 100644 --- a/docs/en/api-guides/blufi.rst +++ b/docs/en/api-guides/blufi.rst @@ -321,11 +321,11 @@ The format of ACK Frame(8 bit): * 0x02: SoftAP * 0x03: SoftAP & STA - data[1]:the connection state of the STA device, 0x0 indicates a connection state, and others represent a disconnected state; + data[1]: connection state of the STA device. 0x0 indicates a connection state with IP address, 0x1 represent a disconnected state, 0x2 indicates a connecting state, and 0x3 indicates a connection state but no IP address. data[2]:the connection state of the SoftAP, that is, how many STA devices have been connected. - data[3] and the subsequent is in accordance with the format of SSID/BSSID information. + data[3] and the subsequent is in accordance with the format of SSID/BSSID information. If device is in connecting state, maximum Wi-Fi reconnecting time would be included here. If device is in disconnected state, Wi-Fi connection end reason and RSSI would be included here. * - 0x10 (b’010000) - Version - @@ -347,10 +347,25 @@ The format of ACK Frame(8 bit): * 0x06: dh param error * 0x07: read param error * 0x08: make public error + * 0x09: data format error + * 0x0a: calculate MD5 error + * 0x0b: Wi-Fi scan error * - 0x13 (b’010011) - Custom Data - To send or receive custom data. - The data frame supports to be sent into fragments if the data length is too long. + * - 0x14 (b’010100) + - Set the maximum Wi-Fi reconnecting time. + - + - data[0] represents the maximum Wi-Fi reconnecting time. + * - 0x15 (b’010101) + - Set the Wi-Fi connection end reason. + - + - data[0] represents the Wi-Fi connection end reason, whose type shall be same with struct `wifi_err_reason_t`. + * - 0x16 (b’010110) + - Set the RSSI at Wi-Fi connection end. + - + - data[0] represents the RSSI at Wi-Fi connection end. If there is no meaningful RSSI in the connection end, this value shall be the meaningless one, which is `-128`. .. note:: diff --git a/docs/zh_CN/api-guides/blufi.rst b/docs/zh_CN/api-guides/blufi.rst index 51a191bf1b..aa232c8811 100644 --- a/docs/zh_CN/api-guides/blufi.rst +++ b/docs/zh_CN/api-guides/blufi.rst @@ -321,11 +321,11 @@ ACK 帧格式(8 bit): * 0x02: SoftAP * 0x03: SoftAP & STA - data[1]:STA 设备的连接状态,0x0 表示处于连接状态,其他表示处于非连接状态; + data[1]:STA 设备的连接状态。0x0 表示处于连接状态且获得 IP 地址,0x1 表示处于非连接状态, 0x2 表示处于正在连接状态,0x3 表示处于连接状态但未获得 IP 地址。 data[2]:SoftAP 的连接状态,即表示有多少 STA 设备已经连接。 - data[3]及后面的数据是按照 SSID/BSSID 格式提供的信息。 + data[3]及后面的数据是按照 SSID/BSSID 格式提供的信息。 如果 Wi-Fi 处于正在连接状态,这里将会包含最大重连次数;如果 Wi-Fi 处于非连接状态,这里将会包含 Wi-Fi 断开连接原因和 RSSI 信息。 * - 0x10 (b’010000) - 版本 - @@ -347,10 +347,25 @@ ACK 帧格式(8 bit): * 0x06: dh param error * 0x07: read param error * 0x08: make public error + * 0x09: data format error + * 0x0a: calculate MD5 error + * 0x0b: Wi-Fi scan error * - 0x13 (b’010011) - 自定义数据 - 用户发送或者接收自定义数据。 - 数据较长时可分片发送。 + * - 0x14 (b’010100) + - 设置最大 Wi-Fi 重连次数。 + - + - data[0] 表示 Wi-Fi 最大重连次数。 + * - 0x15 (b’010101) + - 设置 Wi-Fi 连接失败原因。 + - + - data[0] 表示 Wi-Fi 连接失败原因,它的类型应该和 `wifi_err_reason_t` 一致。 + * - 0x16 (b’010110) + - 设置 Wi-Fi 连接失败的 RSSI 。 + - + - data[0] 表示在 Wi-Fi 连接失败时的 RSSI。 如果在连接结束时没有有意义的 RSSI , 这个值应该为一个无意义值 `-128`。 .. note:: diff --git a/examples/bluetooth/blufi/README.md b/examples/bluetooth/blufi/README.md index f2c04d93d3..f07eabc6f0 100644 --- a/examples/bluetooth/blufi/README.md +++ b/examples/bluetooth/blufi/README.md @@ -1,5 +1,5 @@ -| Supported Targets | ESP32 | ESP32-C3 | -| ----------------- | ----- | -------- | +| Supported Targets | ESP32 | ESP32-C3 | ESP32-S3 | +| ----------------- | ----- | -------- | -------- | # ESP-IDF Blufi Example @@ -27,7 +27,7 @@ Blufi is completely open source, here is the download link: ### Hardware Required -* A development board with ESP32/ESP32-C3 SoC (e.g., ESP32-DevKitC, ESP-WROVER-KIT, etc.) +* A development board with ESP32/ESP32-C3/ESP32-S3 SoC (e.g., ESP32-DevKitC, ESP-WROVER-KIT, etc.) * A USB cable for Power supply and programming See [Development Boards](https://www.espressif.com/en/products/devkits) for more information about it. From c9996c010dfa4924d18f7f84110ba20442969c5e Mon Sep 17 00:00:00 2001 From: liuning Date: Sun, 9 Oct 2022 16:55:15 +0800 Subject: [PATCH 4/6] esp_wifi: fix some connectionless related issue --- components/esp_wifi/include/esp_wifi.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/esp_wifi/include/esp_wifi.h b/components/esp_wifi/include/esp_wifi.h index 08be53cf6a..6bbca27069 100644 --- a/components/esp_wifi/include/esp_wifi.h +++ b/components/esp_wifi/include/esp_wifi.h @@ -1219,7 +1219,7 @@ esp_err_t esp_wifi_config_11b_rate(wifi_interface_t ifx, bool disable); * @attention 3. This configuration would influence nothing until some module configure wake_window * @attention 4. A sensible interval which is not too small is recommended (e.g. 100ms) * - * @param interval how much micriosecond would the chip wake up, from 1 to 65535. + * @param interval how much milliseconds would the chip wake up, from 1 to 65535. */ esp_err_t esp_wifi_set_connectionless_wake_interval(uint16_t interval); From b6800c3e01dd7b09e780f2373545e7702f9e5600 Mon Sep 17 00:00:00 2001 From: liuning Date: Thu, 24 Nov 2022 20:18:27 +0800 Subject: [PATCH 5/6] phy: only set phy_init_flag at power domain off, when all modems deinit --- components/bt/controller/esp32/bt.c | 4 ++-- components/bt/controller/esp32c3/bt.c | 9 ++------- components/bt/controller/esp32s3/bt.c | 4 ++-- components/esp_phy/include/esp_phy_init.h | 5 +++-- components/esp_phy/src/phy_init.c | 18 ++++++++++++------ components/esp_wifi/src/wifi_init.c | 7 ++----- 6 files changed, 23 insertions(+), 24 deletions(-) diff --git a/components/bt/controller/esp32/bt.c b/components/bt/controller/esp32/bt.c index 0e68c9579f..335f968134 100644 --- a/components/bt/controller/esp32/bt.c +++ b/components/bt/controller/esp32/bt.c @@ -1478,7 +1478,7 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg) goto error; } - esp_phy_pd_mem_init(); + esp_phy_modem_init(); esp_bt_power_domain_on(); @@ -1640,7 +1640,7 @@ esp_err_t esp_bt_controller_deinit(void) esp_bt_power_domain_off(); - esp_phy_pd_mem_deinit(); + esp_phy_modem_deinit(); return ESP_OK; } diff --git a/components/bt/controller/esp32c3/bt.c b/components/bt/controller/esp32c3/bt.c index 564c90d493..9bb4068014 100644 --- a/components/bt/controller/esp32c3/bt.c +++ b/components/bt/controller/esp32c3/bt.c @@ -1096,7 +1096,7 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg) #if CONFIG_MAC_BB_PD esp_mac_bb_pd_mem_init(); #endif - esp_phy_pd_mem_init(); + esp_phy_modem_init(); esp_bt_power_domain_on(); btdm_controller_mem_init(); @@ -1413,16 +1413,11 @@ esp_err_t esp_bt_controller_deinit(void) esp_unregister_mac_bb_pu_callback(btdm_mac_bb_power_up_cb); #endif - /* Fix the issue caused by the power off the bt power domain. - * This issue is only on ESP32C3. - */ - phy_init_flag(); - esp_bt_power_domain_off(); #if CONFIG_MAC_BB_PD esp_mac_bb_pd_mem_deinit(); #endif - esp_phy_pd_mem_deinit(); + esp_phy_modem_deinit(); free(osi_funcs_p); osi_funcs_p = NULL; diff --git a/components/bt/controller/esp32s3/bt.c b/components/bt/controller/esp32s3/bt.c index 8295b98aef..3bfbff3d89 100644 --- a/components/bt/controller/esp32s3/bt.c +++ b/components/bt/controller/esp32s3/bt.c @@ -1142,7 +1142,7 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg) #if CONFIG_MAC_BB_PD esp_mac_bb_pd_mem_init(); #endif - esp_phy_pd_mem_init(); + esp_phy_modem_init(); esp_bt_power_domain_on(); btdm_controller_mem_init(); @@ -1464,7 +1464,7 @@ esp_err_t esp_bt_controller_deinit(void) #if CONFIG_MAC_BB_PD esp_mac_bb_pd_mem_deinit(); #endif - esp_phy_pd_mem_deinit(); + esp_phy_modem_deinit(); free(osi_funcs_p); osi_funcs_p = NULL; diff --git a/components/esp_phy/include/esp_phy_init.h b/components/esp_phy/include/esp_phy_init.h index efefd114d4..bcf3e289d3 100644 --- a/components/esp_phy/include/esp_phy_init.h +++ b/components/esp_phy/include/esp_phy_init.h @@ -178,12 +178,13 @@ void esp_phy_load_cal_and_init(void); /** * @brief Initialize backup memory for Phy power up/down */ -void esp_phy_pd_mem_init(void); +void esp_phy_modem_init(void); /** * @brief Deinitialize backup memory for Phy power up/down + * Set phy_init_flag if all modems deinit on ESP32C3 */ -void esp_phy_pd_mem_deinit(void); +void esp_phy_modem_deinit(void); #if CONFIG_MAC_BB_PD /** diff --git a/components/esp_phy/src/phy_init.c b/components/esp_phy/src/phy_init.c index 2319e391ee..2687f706de 100644 --- a/components/esp_phy/src/phy_init.c +++ b/components/esp_phy/src/phy_init.c @@ -71,7 +71,7 @@ static DRAM_ATTR portMUX_TYPE s_phy_int_mux = portMUX_INITIALIZER_UNLOCKED; /* Memory to store PHY digital registers */ static uint32_t* s_phy_digital_regs_mem = NULL; -static uint8_t s_phy_backup_mem_ref = 0; +static uint8_t s_phy_modem_init_ref = 0; #if CONFIG_MAC_BB_PD uint32_t* s_mac_bb_pd_mem = NULL; @@ -297,11 +297,11 @@ void esp_wifi_bt_power_domain_off(void) _lock_release(&s_wifi_bt_pd_controller.lock); } -void esp_phy_pd_mem_init(void) +void esp_phy_modem_init(void) { _lock_acquire(&s_phy_access_lock); - s_phy_backup_mem_ref++; + s_phy_modem_init_ref++; if (s_phy_digital_regs_mem == NULL) { s_phy_digital_regs_mem = (uint32_t *)heap_caps_malloc(SOC_PHY_DIG_REGS_MEM_SIZE, MALLOC_CAP_DMA|MALLOC_CAP_INTERNAL); } @@ -310,15 +310,21 @@ void esp_phy_pd_mem_init(void) } -void esp_phy_pd_mem_deinit(void) +void esp_phy_modem_deinit(void) { _lock_acquire(&s_phy_access_lock); - s_phy_backup_mem_ref--; - if (s_phy_backup_mem_ref == 0) { + s_phy_modem_init_ref--; + if (s_phy_modem_init_ref == 0) { s_is_phy_reg_stored = false; free(s_phy_digital_regs_mem); s_phy_digital_regs_mem = NULL; + /* Fix the issue caused by the power domain off. + * This issue is only on ESP32C3. + */ +#if CONFIG_IDF_TARGET_ESP32C3 + phy_init_flag(); +#endif } _lock_release(&s_phy_access_lock); diff --git a/components/esp_wifi/src/wifi_init.c b/components/esp_wifi/src/wifi_init.c index 6d4a034f86..bc831e46a6 100644 --- a/components/esp_wifi/src/wifi_init.c +++ b/components/esp_wifi/src/wifi_init.c @@ -131,15 +131,12 @@ esp_err_t esp_wifi_deinit(void) #if CONFIG_MAC_BB_PD esp_unregister_mac_bb_pd_callback(pm_mac_sleep); esp_unregister_mac_bb_pu_callback(pm_mac_wakeup); -#endif -#if CONFIG_IDF_TARGET_ESP32C3 - phy_init_flag(); #endif esp_wifi_power_domain_off(); #if CONFIG_MAC_BB_PD esp_mac_bb_pd_mem_deinit(); #endif - esp_phy_pd_mem_deinit(); + esp_phy_modem_deinit(); return err; } @@ -259,7 +256,7 @@ esp_err_t esp_wifi_init(const wifi_init_config_t *config) esp_mac_bb_pd_mem_init(); esp_wifi_internal_set_mac_sleep(true); #endif - esp_phy_pd_mem_init(); + esp_phy_modem_init(); #if CONFIG_IDF_TARGET_ESP32 s_wifi_mac_time_update_cb = esp_wifi_internal_update_mac_time; #endif From 78cef1b7d2acbe465a50e370b40bfa98c90923ac Mon Sep 17 00:00:00 2001 From: liuning Date: Fri, 2 Dec 2022 20:02:07 +0800 Subject: [PATCH 6/6] esp_wifi: update lib for backport --- components/esp_wifi/lib | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/esp_wifi/lib b/components/esp_wifi/lib index 378947adbf..fd709e9206 160000 --- a/components/esp_wifi/lib +++ b/components/esp_wifi/lib @@ -1 +1 @@ -Subproject commit 378947adbfcfa4c1bcf96b3465ffec23ab7d9e32 +Subproject commit fd709e9206fe0102d904db396e3127a54dfbaaf4