How to use the esp_wifi_set_dynamic_cs API in v5.2.2

poneponecar
Posts: 4
Joined: Sun Apr 03, 2022 11:56 am

How to use the esp_wifi_set_dynamic_cs API in v5.2.2

Postby poneponecar » Tue Jul 23, 2024 2:40 pm

Hi,
My product using ESP32 couldn't pass the Carrier Sense test in the WiFi test in Japan.
I saw a new API esp_wifi_set_dynamic_cs() is added in v5.2.2.
So I upgraded the SDK version and add this API in my WiFi init code:

ESP_ERROR_CHECK(esp_netif_init());
ESP_ERROR_CHECK(esp_event_loop_create_default());

uint8_t tmp[6] = {0};
esp_read_mac(tmp, ESP_MAC_WIFI_STA);
sprintf(_wifi_mac,"%02X%02X%02X%02X%02X%02X", tmp[0],tmp[1],tmp[2],tmp[3],tmp[4],tmp[5]);
//HM_PRINTF_LOG(HM_LOG_WIFI, "wifi mac: %s", _wifi_mac_sta);

esp_netif_t *sta_netif = esp_netif_create_default_wifi_sta();
assert(sta_netif);

wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
esp_wifi_set_storage(WIFI_STORAGE_RAM);
esp_event_handler_instance_t instance_any_id;
esp_event_handler_instance_t instance_got_ip;
ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &wifi_event_handler, sta_netif, &instance_any_id));
ESP_ERROR_CHECK(esp_event_handler_instance_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &wifi_event_handler, sta_netif, &instance_got_ip));

ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
ESP_ERROR_CHECK(esp_wifi_set_dynamic_cs(true));
ESP_ERROR_CHECK(esp_wifi_start());

But it would leads to the assert failed:
ESP_ERROR_CHECK failed: esp_err_t 0x3002 (ESP_ERR_WIFI_NOT_STARTED) at 0x400dd653
0x400dd653: wifi_init_station at D:/ESP32/commbox_fw/application/source/wifi/wifi.c:290 (discriminator 1)

file: "D:/ESP32/commbox_fw/application/source/wifi/wifi.c" line 290
func: wifi_init_station
expression: esp_wifi_set_dynamic_cs(true)

abort() was called at PC 0x4008a993 on core 0
0x4008a993: _esp_error_check_failed at D:/ESP32/toolchain_5_2_2/Espressif/frameworks/esp-idf-v5.2.2/components/esp_system/esp_err.c:50



Backtrace: 0x400819ee:0x3ffc5680 0x4008a99d:0x3ffc56a0 0x40093009:0x3ffc56c0 0x4008a993:0x3ffc5730 0x400dd653:0x3ffc5760 0x400dea3e:0x3ffc5880 0x400d90b9:0x3ffc58e0 0x400d8c5b:0x3ffc5930 0x4019b21f:0x3ffc5950 0x4008b58d:0x3ffc5980
0x400819ee: panic_abort at D:/ESP32/toolchain_5_2_2/Espressif/frameworks/esp-idf-v5.2.2/components/esp_system/panic.c:466
0x4008a99d: esp_system_abort at D:/ESP32/toolchain_5_2_2/Espressif/frameworks/esp-idf-v5.2.2/components/esp_system/port/esp_system_chip.c:93
0x40093009: abort at D:/ESP32/toolchain_5_2_2/Espressif/frameworks/esp-idf-v5.2.2/components/newlib/abort.c:38
0x4008a993: _esp_error_check_failed at D:/ESP32/toolchain_5_2_2/Espressif/frameworks/esp-idf-v5.2.2/components/esp_system/esp_err.c:50
0x400dd653: wifi_init_station at D:/ESP32/commbox_fw/application/source/wifi/wifi.c:290 (discriminator 1)
0x400dea3e: wifi_init at D:/ESP32/commbox_fw/application/source/wifi/wifi.c:326
0x400d90b9: app_main_entry at D:/ESP32/commbox_fw/application/source/app_main_entry/app_main_entry.c:249
0x400d8c5b: app_main at D:/ESP32/commbox_fw/application/esp32_cb_e01a_v2/main/main.c:17
0x4019b21f: main_task at D:/ESP32/toolchain_5_2_2/Espressif/frameworks/esp-idf-v5.2.2/components/freertos/app_startup.c:208
0x4008b58d: vPortTaskWrapper at D:/ESP32/toolchain_5_2_2/Espressif/frameworks/esp-idf-v5.2.2/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:134

How to properly use this API and does it help on the WiFi certification

ESP_Sprite
Posts: 9761
Joined: Thu Nov 26, 2015 4:08 am

Re: How to use the esp_wifi_set_dynamic_cs API in v5.2.2

Postby ESP_Sprite » Wed Jul 24, 2024 1:56 am

From the docs: "This API should be called after esp_wifi_start()."

Who is online

Users browsing this forum: Majestic-12 [Bot] and 122 guests