fdcavalcanti opened a new pull request, #16921: URL: https://github.com/apache/nuttx/pull/16921
## Summary This PR refactors the Wi-Fi driver for RISC-V Espressif devices, affecting ESP32-C3 and ESP32-C6. It now better implements the `netdev_ops` and `wireless_ops` as defined in `nuttx/net/netdev_lowerhalf.h`. Some modifications and code organization was required to streamline the implementation and allow it to be reused efficiently. On the common layer of Espressif devices, we have the following: - `esp_wifi_api.c`: wraps the Espressif Wi-Fi driver functions. - `esp_wlan_netdev.c`: defines the `struct wireless_ops_s` and `netdev_ops_s`. - Defines the `esp_wlan_priv_s` which is the interface for the Wi-Fi peripheral (STA and SoftAP each has one `esp_wlan_priv_s`.) - Defines `esp_wlan_initialize` which is called from board level to initialize the wireless interface. - `esp_wifi_utils.c`: generic functions that are moved to make the code cleaner and reusable. Includes Wi-Fi scan routines, mutex locks. - `esp_wifi_event_handler.c`: deals with events generated from the Wi-Fi driver. On the arch specific layer, we have: - `esp_wifi_adapter.c`: defines the `wifi_osi_funcs_t` struct, which is a requirement for the lower-half Wi-Fi driver. - `esp_coex_adapter.c`: required for Wi-Fi/Bluetooth coexistance. ### Main Changes: - Architecture Restructuring: Separated Wi-Fi API layer from network device layer - Created esp_wifi_api.c/h for Wi-Fi control functions - Created esp_wlan_netdev.c/h for network device operations - Moved event handling to dedicated esp_wifi_event_handler.c ### Buffer Management Improvements: - Added CONFIG_IOB_BUFSIZE=128 and CONFIG_IOB_NBUFFERS=160 to all configs - Added CONFIG_NET_ETH_PKTSIZE=1514 for larger packet support - Enhanced buffer allocation and management ### Code Organization: - Removed monolithic esp_wlan.c (1772 lines deleted) - Split functionality into focused modules - Improved separation of concerns between Wi-Fi control and networking ### Configuration Updates: - Updated all ESP32-C3 and ESP32-C6 board configurations - Added CONFIG_NETUTILS_IPERF=y for performance testing - Enhanced network stack configuration ### Error Handling: - Replaced wlerr() with syslog(LOG_ERR, ...) for better logging - Improved error reporting and debugging capabilities ### Performance: - Fix low and inconsistent bandwidth issues - Improve buffer management for better throughput - Cleaner implementation for easier debugging and maintenance ## Impact - Impact on user: Yes, users now have a more stable and higher throughput. Also improved wapi function support. - Impact on build: No. - Impact on hardware: No. - Impact on documentation: No. - Impact on security: No. - Impact on compatibility: No. ## Testing Tested extensively on ESP32-C3 and ESP32-C6. Test involves wapi function usage, IPERF test for stability and throughput, DHCP and both operating modes: Wi-Fi station and AP. ### Building - ./tools/configure.sh esp32c3-generic:sta_softap - make and flash ### Running Many tests are used for Wi-Fi, so I won't show them all here, but would be happy to share them if needed. I´ll share the process for IPERF testing on AP and STA. IPERF testing example with ESP device running as client: ``` wapi psk wlan0 espmint123 3 3 wapi essid wlan0 Nuttx-IOT 1 renew wlan0 iperf -c 192.168.0.125 -i 3 -t 60 ``` For running as IPERF server, use the following instead: `iperf -s` ### Results Connecting to AP: ``` nsh> wapi psk wlan0 espmint123 3 3 nsh> wapi essid wlan0 Nuttx-IOT 1 nsh> renew wlan0 nsh> ifconfig wlan0 Link encap:Ethernet HWaddr 58:cf:79:07:51:e8 at RUNNING mtu 1500 inet addr:192.168.0.30 DRaddr:192.168.0.1 Mask:255.255.255.0 wlan1 Link encap:Ethernet HWaddr 58:cf:79:07:51:e9 at DOWN mtu 1500 inet addr:0.0.0.0 DRaddr:0.0.0.0 Mask:0.0.0.0 ``` Running IPERF client results in: ``` nsh> iperf -c 192.168.0.125 -i 3 -t 60 IP: 192.168.0.30 mode=tcp-client sip=192.168.0.30:5001,dip=192.168.0.125:5001, interval=3, time=60 Interval Transfer Bandwidth 0.00- 3.01 sec 3276800 Bytes 8.71 Mbits/sec 3.01- 6.02 sec 3899392 Bytes 10.36 Mbits/sec 6.02- 9.03 sec 3686400 Bytes 9.80 Mbits/sec 9.03- 12.04 sec 3244032 Bytes 8.62 Mbits/sec 12.04- 15.05 sec 3702784 Bytes 9.84 Mbits/sec 15.05- 18.06 sec 3784704 Bytes 10.06 Mbits/sec 18.06- 21.07 sec 3833856 Bytes 10.19 Mbits/sec 21.07- 24.08 sec 4030464 Bytes 10.71 Mbits/sec 24.08- 27.10 sec 4210688 Bytes 11.15 Mbits/sec 27.10- 30.11 sec 4046848 Bytes 10.76 Mbits/sec 30.11- 33.12 sec 3784704 Bytes 10.06 Mbits/sec 33.12- 36.13 sec 3620864 Bytes 9.62 Mbits/sec 36.13- 39.14 sec 3719168 Bytes 9.88 Mbits/sec 39.14- 42.15 sec 3801088 Bytes 10.10 Mbits/sec 42.15- 45.16 sec 3768320 Bytes 10.02 Mbits/sec 45.16- 48.17 sec 3637248 Bytes 9.67 Mbits/sec 48.17- 51.18 sec 3670016 Bytes 9.75 Mbits/sec 51.18- 54.19 sec 3817472 Bytes 10.15 Mbits/sec 54.19- 57.20 sec 3686400 Bytes 9.80 Mbits/sec 57.20- 60.21 sec 3883008 Bytes 10.32 Mbits/sec 0.00- 60.21 sec 75120640 Bytes 9.98 Mbits/sec ``` ### Extra Test Results ``` testsuites/tests/test_wifi.py::test_device_sanity PASSED [ 20%] testsuites/tests/test_wifi.py::test_wifi_reconnect_on_psk PASSED [ 40%] testsuites/tests/test_wifi.py::test_disconnect_from_ap PASSED [ 60%] testsuites/tests/test_wifi.py::test_connect_wrong_password PASSED [ 80%] testsuites/tests/test_wifi.py::test_iperf PASSED [100%] ``` ``` testsuites/tests/test_sta_softap.py::test_network_device_sanity PASSED [ 12%] testsuites/tests/test_sta_softap.py::test_ping_ap PASSED [ 25%] testsuites/tests/test_sta_softap.py::test_provide_less_secure_ap PASSED [ 37%] testsuites/tests/test_sta_softap.py::test_save_wifi_data PASSED [ 50%] testsuites/tests/test_sta_softap.py::test_reboot_and_reconnect PASSED [62%] testsuites/tests/test_sta_softap.py::test_disable_ip_iface PASSED [75%] testsuites/tests/test_sta_softap.py::test_boot_connection_fails PASSED [87%] testsuites/tests/test_sta_softap.py::test_enable_disable_softap PASSED [100%] ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org