From 9d7bd6a8ddf63cf7ccb4b5a4c764624ffd5d80e2 Mon Sep 17 00:00:00 2001 From: xiehang Date: Mon, 25 Mar 2024 17:54:38 +0800 Subject: [PATCH 1/2] change(esp_phy): Add SOC_PHY_SUPPORTED to control phy mode --- components/esp_phy/CMakeLists.txt | 6 + components/esp_phy/Kconfig | 315 +++++++++--------- components/esp_wifi/src/wifi_init.c | 11 +- .../soc/esp32/include/soc/Kconfig.soc_caps.in | 4 + components/soc/esp32/include/soc/soc_caps.h | 1 + .../esp32c2/include/soc/Kconfig.soc_caps.in | 4 + components/soc/esp32c2/include/soc/soc_caps.h | 1 + .../esp32c3/include/soc/Kconfig.soc_caps.in | 4 + components/soc/esp32c3/include/soc/soc_caps.h | 1 + .../esp32c6/include/soc/Kconfig.soc_caps.in | 4 + components/soc/esp32c6/include/soc/soc_caps.h | 1 + .../esp32c61/include/soc/Kconfig.soc_caps.in | 4 + .../soc/esp32c61/include/soc/soc_caps.h | 1 + .../esp32h2/include/soc/Kconfig.soc_caps.in | 4 + components/soc/esp32h2/include/soc/soc_caps.h | 1 + .../esp32s2/include/soc/Kconfig.soc_caps.in | 4 + components/soc/esp32s2/include/soc/soc_caps.h | 1 + .../esp32s3/include/soc/Kconfig.soc_caps.in | 4 + components/soc/esp32s3/include/soc/soc_caps.h | 1 + 19 files changed, 217 insertions(+), 155 deletions(-) diff --git a/components/esp_phy/CMakeLists.txt b/components/esp_phy/CMakeLists.txt index d542d6ab51..a1c4a37b59 100644 --- a/components/esp_phy/CMakeLists.txt +++ b/components/esp_phy/CMakeLists.txt @@ -9,6 +9,8 @@ if(IDF_TARGET STREQUAL "esp32p4" OR IDF_TARGET STREQUAL "esp32c61") return() endif() +if(CONFIG_ESP_PHY_ENABLED) + set(srcs "src/phy_override.c" "src/lib_printf.c" "src/phy_common.c") if(CONFIG_APP_NO_BLOBS) @@ -46,6 +48,7 @@ if(CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN_EMBED) set(embed_files "${build_dir}/phy_multiple_init_data.bin") endif() endif() +endif() # [refactor-todo]: requires "driver" component for periph_ctrl header file idf_component_register(SRCS "${srcs}" @@ -55,6 +58,7 @@ idf_component_register(SRCS "${srcs}" EMBED_FILES ${embed_files} ) +if(CONFIG_ESP_PHY_ENABLED) set(target_name "${idf_target}") target_link_directories(${COMPONENT_LIB} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/lib/${target_name}") @@ -122,3 +126,5 @@ if(CONFIG_ESP_PHY_INIT_DATA_IN_PARTITION) esptool_py_flash_target_image(${phy_name}-flash ${phy_name} "${phy_partition_offset}" "${phy_init_data_bin}") esptool_py_flash_target_image(flash ${phy_name} "${phy_partition_offset}" "${phy_init_data_bin}") endif() + +endif() diff --git a/components/esp_phy/Kconfig b/components/esp_phy/Kconfig index b6b4e4923e..e6835b30fe 100644 --- a/components/esp_phy/Kconfig +++ b/components/esp_phy/Kconfig @@ -1,170 +1,177 @@ menu "PHY" - config ESP_PHY_CALIBRATION_AND_DATA_STORAGE - bool "Store phy calibration data in NVS" - default y - help - If this option is enabled, NVS will be initialized and calibration data will be loaded from there. - PHY calibration will be skipped on deep sleep wakeup. If calibration data is not found, full calibration - will be performed and stored in NVS. Normally, only partial calibration will be performed. - If this option is disabled, full calibration will be performed. + config ESP_PHY_ENABLED + bool + default y if (SOC_PHY_SUPPORTED) - If it's easy that your board calibrate bad data, choose 'n'. - Two cases for example, you should choose 'n': - 1.If your board is easy to be booted up with antenna disconnected. - 2.Because of your board design, each time when you do calibration, the result are too unstable. - If unsure, choose 'y'. + if (ESP_PHY_ENABLED) + config ESP_PHY_CALIBRATION_AND_DATA_STORAGE + bool "Store phy calibration data in NVS" + default y + help + If this option is enabled, NVS will be initialized and calibration data will be loaded from there. + PHY calibration will be skipped on deep sleep wakeup. If calibration data is not found, full + calibration will be performed and stored in NVS. Normally, only partial calibration will be performed. + If this option is disabled, full calibration will be performed. - menuconfig ESP_PHY_INIT_DATA_IN_PARTITION - bool "Use a partition to store PHY init data" - depends on SOC_WIFI_SUPPORTED - default n - help - If enabled, PHY init data will be loaded from a partition. - When using a custom partition table, make sure that PHY data - partition is included (type: 'data', subtype: 'phy'). - With default partition tables, this is done automatically. - If PHY init data is stored in a partition, it has to be flashed there, - otherwise runtime error will occur. + If it's easy that your board calibrate bad data, choose 'n'. + Two cases for example, you should choose 'n': + 1.If your board is easy to be booted up with antenna disconnected. + 2.Because of your board design, each time when you do calibration, the result are too unstable. + If unsure, choose 'y'. - If this option is not enabled, PHY init data will be embedded - into the application binary. + menuconfig ESP_PHY_INIT_DATA_IN_PARTITION + bool "Use a partition to store PHY init data" + depends on SOC_WIFI_SUPPORTED + default n + help + If enabled, PHY init data will be loaded from a partition. + When using a custom partition table, make sure that PHY data + partition is included (type: 'data', subtype: 'phy'). + With default partition tables, this is done automatically. + If PHY init data is stored in a partition, it has to be flashed there, + otherwise runtime error will occur. - If unsure, choose 'n'. + If this option is not enabled, PHY init data will be embedded + into the application binary. - config ESP_PHY_DEFAULT_INIT_IF_INVALID - bool "Reset default PHY init data if invalid" - default n - depends on ESP_PHY_INIT_DATA_IN_PARTITION - help - If enabled, PHY init data will be restored to default if - it cannot be verified successfully to avoid endless bootloops. + If unsure, choose 'n'. - If unsure, choose 'n'. - - if ESP_PHY_INIT_DATA_IN_PARTITION - config ESP_PHY_MULTIPLE_INIT_DATA_BIN - bool "Support multiple PHY init data bin" + config ESP_PHY_DEFAULT_INIT_IF_INVALID + bool "Reset default PHY init data if invalid" + default n depends on ESP_PHY_INIT_DATA_IN_PARTITION - default n help - If enabled, the corresponding PHY init data type can be automatically switched - according to the country code. China's PHY init data bin is used by default. - Can be modified by country information in API esp_wifi_set_country(). - The priority of switching the PHY init data type is: - 1. Country configured by API esp_wifi_set_country() - and the parameter policy is WIFI_COUNTRY_POLICY_MANUAL. - 2. Country notified by the connected AP. - 3. Country configured by API esp_wifi_set_country() - and the parameter policy is WIFI_COUNTRY_POLICY_AUTO. + If enabled, PHY init data will be restored to default if + it cannot be verified successfully to avoid endless bootloops. - config ESP_PHY_MULTIPLE_INIT_DATA_BIN_EMBED - bool "Support embedded multiple phy init data bin to app bin" - depends on ESP_PHY_MULTIPLE_INIT_DATA_BIN - default n - help - If enabled, multiple phy init data bin will embedded into app bin - If not enabled, multiple phy init data bin will still leave alone, and need to be flashed by users. + If unsure, choose 'n'. - config ESP_PHY_INIT_DATA_ERROR - bool "Terminate operation when PHY init data error" - depends on ESP_PHY_MULTIPLE_INIT_DATA_BIN + if ESP_PHY_INIT_DATA_IN_PARTITION + config ESP_PHY_MULTIPLE_INIT_DATA_BIN + bool "Support multiple PHY init data bin" + depends on ESP_PHY_INIT_DATA_IN_PARTITION + default n + help + If enabled, the corresponding PHY init data type can be automatically switched + according to the country code. China's PHY init data bin is used by default. + Can be modified by country information in API esp_wifi_set_country(). + The priority of switching the PHY init data type is: + 1. Country configured by API esp_wifi_set_country() + and the parameter policy is WIFI_COUNTRY_POLICY_MANUAL. + 2. Country notified by the connected AP. + 3. Country configured by API esp_wifi_set_country() + and the parameter policy is WIFI_COUNTRY_POLICY_AUTO. + + config ESP_PHY_MULTIPLE_INIT_DATA_BIN_EMBED + bool "Support embedded multiple phy init data bin to app bin" + depends on ESP_PHY_MULTIPLE_INIT_DATA_BIN + default n + help + If enabled, multiple phy init data bin will embedded into app bin + If not enabled, multiple phy init data bin will still leave alone, and need to be flashed by users. + + config ESP_PHY_INIT_DATA_ERROR + bool "Terminate operation when PHY init data error" + depends on ESP_PHY_MULTIPLE_INIT_DATA_BIN + default n + help + If enabled, when an error occurs while the PHY init data is updated, + the program will terminate and restart. + If not enabled, the PHY init data will not be updated when an error occurs. + endif + + config ESP_PHY_MAX_WIFI_TX_POWER + int "Max WiFi TX power (dBm)" + range 10 20 + default 20 + help + Set maximum transmit power for WiFi radio. Actual transmit power for high + data rates may be lower than this setting. + + config ESP_PHY_MAX_TX_POWER + int + default ESP_PHY_MAX_WIFI_TX_POWER + + config ESP_PHY_MAC_BB_PD + bool "Power down MAC and baseband of Wi-Fi and Bluetooth when PHY is disabled" + depends on SOC_PM_SUPPORT_MAC_BB_PD && FREERTOS_USE_TICKLESS_IDLE default n help - If enabled, when an error occurs while the PHY init data is updated, - the program will terminate and restart. - If not enabled, the PHY init data will not be updated when an error occurs. + If enabled, the MAC and baseband of Wi-Fi and Bluetooth will be powered + down when PHY is disabled. Enabling this setting reduces power consumption + by a small amount but increases RAM use by approximately 4 KB(Wi-Fi only), + 2 KB(Bluetooth only) or 5.3 KB(Wi-Fi + Bluetooth). + + config ESP_PHY_REDUCE_TX_POWER + bool "Reduce PHY TX power when brownout reset" + depends on ESP_BROWNOUT_DET + default n + help + When brownout reset occurs, reduce PHY TX power to keep the code running. + + config ESP_PHY_ENABLE_USB + bool "Keep the USB PHY enabled when initializing WiFi" + depends on SOC_WIFI_PHY_NEEDS_USB_WORKAROUND + default y if IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32S3 \ + || ESP_CONSOLE_USB_SERIAL_JTAG || ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG + default n + help + On some ESP targets, the USB PHY can interfere with WiFi thus lowering WiFi performance. + As a result, on those affected ESP targets, the ESP PHY library's initialization will automatically + disable the USB PHY to get best WiFi performance. + This option controls whether or not the ESP PHY library will keep the USB PHY enabled on + initialization. + + Note: This option can be disabled to increase WiFi performance. However, disabling this option will + also mean that the USB PHY cannot be used while WiFi is enabled. + + + config ESP_PHY_ENABLE_CERT_TEST + bool "Enable RF certification test functions" + default n + depends on IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32S3 + help + If enabled, you can use RF certification test APIs. + + choice ESP_PHY_CALIBRATION_MODE + prompt "Calibration mode" + default ESP_PHY_RF_CAL_PARTIAL + help + Select PHY calibration mode. During RF initialization, the partial calibration + method is used by default for RF calibration. Full calibration takes about 100ms + more than partial calibration. If boot duration is not critical, it is suggested + to use the full calibration method. No calibration method is only used when the + device wakes up from deep sleep. + + config ESP_PHY_RF_CAL_PARTIAL + bool "Calibration partial" + config ESP_PHY_RF_CAL_NONE + bool "Calibration none" + config ESP_PHY_RF_CAL_FULL + bool "Calibration full" + endchoice #ESP_PHY_CALIBRATION_MODE + + config ESP_PHY_CALIBRATION_MODE + int + default 0 if ESP_PHY_RF_CAL_PARTIAL + default 1 if ESP_PHY_RF_CAL_NONE + default 2 if ESP_PHY_RF_CAL_FULL + + config ESP_PHY_IMPROVE_RX_11B + bool "Improve Wi-Fi receive 11b pkts" + default n + depends on SOC_PHY_IMPROVE_RX_11B + help + This is a workaround to improve Wi-Fi receive 11b pkts for some modules using AC-DC power supply with + high interference, enable this option will sacrifice Wi-Fi OFDM receive performance. + But to guarantee 11b receive performance serves as a bottom line in this case. + + config ESP_PHY_PLL_TRACK_DEBUG + bool "Enable pll track logging" + default n + help + If enabled, there will be some logs while pll tracking + endif - - config ESP_PHY_MAX_WIFI_TX_POWER - int "Max WiFi TX power (dBm)" - range 10 20 - default 20 - help - Set maximum transmit power for WiFi radio. Actual transmit power for high - data rates may be lower than this setting. - - config ESP_PHY_MAX_TX_POWER - int - default ESP_PHY_MAX_WIFI_TX_POWER - - config ESP_PHY_MAC_BB_PD - bool "Power down MAC and baseband of Wi-Fi and Bluetooth when PHY is disabled" - depends on SOC_PM_SUPPORT_MAC_BB_PD && FREERTOS_USE_TICKLESS_IDLE - default n - help - If enabled, the MAC and baseband of Wi-Fi and Bluetooth will be powered - down when PHY is disabled. Enabling this setting reduces power consumption - by a small amount but increases RAM use by approximately 4 KB(Wi-Fi only), - 2 KB(Bluetooth only) or 5.3 KB(Wi-Fi + Bluetooth). - - config ESP_PHY_REDUCE_TX_POWER - bool "Reduce PHY TX power when brownout reset" - depends on ESP_BROWNOUT_DET - default n - help - When brownout reset occurs, reduce PHY TX power to keep the code running. - - config ESP_PHY_ENABLE_USB - bool "Keep the USB PHY enabled when initializing WiFi" - depends on SOC_WIFI_PHY_NEEDS_USB_WORKAROUND - default y if IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32S3 \ - || ESP_CONSOLE_USB_SERIAL_JTAG || ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG - default n - help - On some ESP targets, the USB PHY can interfere with WiFi thus lowering WiFi performance. As a result, on - those affected ESP targets, the ESP PHY library's initialization will automatically disable the USB PHY to - get best WiFi performance. This option controls whether or not the ESP PHY library will keep the USB PHY - enabled on initialization. - - Note: This option can be disabled to increase WiFi performance. However, disabling this option will also - mean that the USB PHY cannot be used while WiFi is enabled. - - - config ESP_PHY_ENABLE_CERT_TEST - bool "Enable RF certification test functions" - default n - depends on IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32S3 - help - If enabled, you can use RF certification test APIs. - - choice ESP_PHY_CALIBRATION_MODE - prompt "Calibration mode" - default ESP_PHY_RF_CAL_PARTIAL - help - Select PHY calibration mode. During RF initialization, the partial calibration - method is used by default for RF calibration. Full calibration takes about 100ms - more than partial calibration. If boot duration is not critical, it is suggested - to use the full calibration method. No calibration method is only used when the - device wakes up from deep sleep. - - config ESP_PHY_RF_CAL_PARTIAL - bool "Calibration partial" - config ESP_PHY_RF_CAL_NONE - bool "Calibration none" - config ESP_PHY_RF_CAL_FULL - bool "Calibration full" - endchoice #ESP_PHY_CALIBRATION_MODE - - config ESP_PHY_CALIBRATION_MODE - int - default 0 if ESP_PHY_RF_CAL_PARTIAL - default 1 if ESP_PHY_RF_CAL_NONE - default 2 if ESP_PHY_RF_CAL_FULL - - config ESP_PHY_IMPROVE_RX_11B - bool "Improve Wi-Fi receive 11b pkts" - default n - depends on SOC_PHY_IMPROVE_RX_11B - help - This is a workaround to improve Wi-Fi receive 11b pkts for some modules using AC-DC power supply with - high interference, enable this option will sacrifice Wi-Fi OFDM receive performance. - But to guarantee 11b receive performance serves as a bottom line in this case. - - config ESP_PHY_PLL_TRACK_DEBUG - bool "Enable pll track logging" - default n - help - If enabled, there will be some logs while pll tracking - endmenu # PHY diff --git a/components/esp_wifi/src/wifi_init.c b/components/esp_wifi/src/wifi_init.c index a244afbac9..a92cedb885 100644 --- a/components/esp_wifi/src/wifi_init.c +++ b/components/esp_wifi/src/wifi_init.c @@ -18,8 +18,10 @@ #include "esp_wpa.h" #include "esp_netif.h" #include "private/esp_coexist_internal.h" +#ifdef CONFIG_ESP_PHY_ENABLED #include "esp_phy_init.h" #include "esp_private/phy.h" +#endif #if __has_include("esp_psram.h") #include "esp_psram.h" #endif @@ -183,7 +185,9 @@ static esp_err_t wifi_deinit_internal(void) s_wifi_modem_sleep_lock = NULL; } #endif +#ifdef CONFIG_ESP_PHY_ENABLED esp_wifi_power_domain_off(); +#endif #if CONFIG_ESP_WIFI_SLP_BEACON_LOST_OPT wifi_beacon_monitor_config_t monitor_config = WIFI_BEACON_MONITOR_CONFIG_DEFAULT(false); @@ -217,8 +221,9 @@ static esp_err_t wifi_deinit_internal(void) esp_wifi_internal_modem_state_configure(false); esp_pm_unregister_skip_light_sleep_callback(sleep_modem_wifi_modem_state_skip_light_sleep); #endif +#ifdef CONFIG_ESP_PHY_ENABLED esp_phy_modem_deinit(); - +#endif s_wifi_inited = false; return err; @@ -379,7 +384,9 @@ esp_err_t esp_wifi_init(const wifi_init_config_t *config) coex_init(); #endif esp_wifi_set_log_level(); +#ifdef CONFIG_ESP_PHY_ENABLED esp_wifi_power_domain_on(); +#endif #ifdef CONFIG_ESP_WIFI_FTM_ENABLE esp_chip_info_t info = {0}; esp_chip_info(&info); @@ -393,7 +400,9 @@ esp_err_t esp_wifi_init(const wifi_init_config_t *config) esp_mac_bb_pd_mem_init(); esp_wifi_mac_pd_mem_init(); #endif +#ifdef CONFIG_ESP_PHY_ENABLED esp_phy_modem_init(); +#endif #if CONFIG_ESP_WIFI_ENHANCED_LIGHT_SLEEP if (sleep_modem_wifi_modem_state_enabled()) { esp_pm_register_skip_light_sleep_callback(sleep_modem_wifi_modem_state_skip_light_sleep); diff --git a/components/soc/esp32/include/soc/Kconfig.soc_caps.in b/components/soc/esp32/include/soc/Kconfig.soc_caps.in index 9557e43dd7..198272568a 100644 --- a/components/soc/esp32/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32/include/soc/Kconfig.soc_caps.in @@ -51,6 +51,10 @@ config SOC_PCNT_SUPPORTED bool default y +config SOC_PHY_SUPPORTED + bool + default y + config SOC_WIFI_SUPPORTED bool default y diff --git a/components/soc/esp32/include/soc/soc_caps.h b/components/soc/esp32/include/soc/soc_caps.h index 68d79952b1..a84de003fd 100644 --- a/components/soc/esp32/include/soc/soc_caps.h +++ b/components/soc/esp32/include/soc/soc_caps.h @@ -70,6 +70,7 @@ #define SOC_SDMMC_HOST_SUPPORTED 1 #define SOC_BT_SUPPORTED 1 #define SOC_PCNT_SUPPORTED 1 +#define SOC_PHY_SUPPORTED 1 #define SOC_WIFI_SUPPORTED 1 #define SOC_SDIO_SLAVE_SUPPORTED 1 #define SOC_TWAI_SUPPORTED 1 diff --git a/components/soc/esp32c2/include/soc/Kconfig.soc_caps.in b/components/soc/esp32c2/include/soc/Kconfig.soc_caps.in index 5b277eaac7..b7171e209d 100644 --- a/components/soc/esp32c2/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32c2/include/soc/Kconfig.soc_caps.in @@ -27,6 +27,10 @@ config SOC_GPTIMER_SUPPORTED bool default y +config SOC_PHY_SUPPORTED + bool + default y + config SOC_BT_SUPPORTED bool default y diff --git a/components/soc/esp32c2/include/soc/soc_caps.h b/components/soc/esp32c2/include/soc/soc_caps.h index eda25b6638..ee5ff59b04 100644 --- a/components/soc/esp32c2/include/soc/soc_caps.h +++ b/components/soc/esp32c2/include/soc/soc_caps.h @@ -23,6 +23,7 @@ #define SOC_GDMA_SUPPORTED 1 #define SOC_AHB_GDMA_SUPPORTED 1 #define SOC_GPTIMER_SUPPORTED 1 +#define SOC_PHY_SUPPORTED 1 #define SOC_BT_SUPPORTED 1 #define SOC_WIFI_SUPPORTED 1 #define SOC_ASYNC_MEMCPY_SUPPORTED 1 diff --git a/components/soc/esp32c3/include/soc/Kconfig.soc_caps.in b/components/soc/esp32c3/include/soc/Kconfig.soc_caps.in index ad46552c11..a3fafe32da 100644 --- a/components/soc/esp32c3/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32c3/include/soc/Kconfig.soc_caps.in @@ -51,6 +51,10 @@ config SOC_XT_WDT_SUPPORTED bool default y +config SOC_PHY_SUPPORTED + bool + default y + config SOC_WIFI_SUPPORTED bool default y diff --git a/components/soc/esp32c3/include/soc/soc_caps.h b/components/soc/esp32c3/include/soc/soc_caps.h index 468b0d858a..8d97e3ec31 100644 --- a/components/soc/esp32c3/include/soc/soc_caps.h +++ b/components/soc/esp32c3/include/soc/soc_caps.h @@ -29,6 +29,7 @@ #define SOC_USB_SERIAL_JTAG_SUPPORTED 1 #define SOC_TEMP_SENSOR_SUPPORTED 1 #define SOC_XT_WDT_SUPPORTED 1 +#define SOC_PHY_SUPPORTED 1 #define SOC_WIFI_SUPPORTED 1 #define SOC_SUPPORTS_SECURE_DL_MODE 1 #define SOC_EFUSE_KEY_PURPOSE_FIELD 1 diff --git a/components/soc/esp32c6/include/soc/Kconfig.soc_caps.in b/components/soc/esp32c6/include/soc/Kconfig.soc_caps.in index 50e474b0a0..23acbc517a 100644 --- a/components/soc/esp32c6/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32c6/include/soc/Kconfig.soc_caps.in @@ -67,6 +67,10 @@ config SOC_TEMP_SENSOR_SUPPORTED bool default y +config SOC_PHY_SUPPORTED + bool + default y + config SOC_WIFI_SUPPORTED bool default y diff --git a/components/soc/esp32c6/include/soc/soc_caps.h b/components/soc/esp32c6/include/soc/soc_caps.h index 31e6debdac..fb5a8eda03 100644 --- a/components/soc/esp32c6/include/soc/soc_caps.h +++ b/components/soc/esp32c6/include/soc/soc_caps.h @@ -33,6 +33,7 @@ #define SOC_ASYNC_MEMCPY_SUPPORTED 1 #define SOC_USB_SERIAL_JTAG_SUPPORTED 1 #define SOC_TEMP_SENSOR_SUPPORTED 1 +#define SOC_PHY_SUPPORTED 1 #define SOC_WIFI_SUPPORTED 1 #define SOC_SUPPORTS_SECURE_DL_MODE 1 #define SOC_ULP_SUPPORTED 1 diff --git a/components/soc/esp32c61/include/soc/Kconfig.soc_caps.in b/components/soc/esp32c61/include/soc/Kconfig.soc_caps.in index 92502615ee..b3249adc72 100644 --- a/components/soc/esp32c61/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32c61/include/soc/Kconfig.soc_caps.in @@ -7,6 +7,10 @@ config SOC_UART_SUPPORTED bool default y +config SOC_PHY_SUPPORTED + bool + default y + config SOC_SUPPORTS_SECURE_DL_MODE bool default y diff --git a/components/soc/esp32c61/include/soc/soc_caps.h b/components/soc/esp32c61/include/soc/soc_caps.h index 35c2fa3403..165bc93727 100644 --- a/components/soc/esp32c61/include/soc/soc_caps.h +++ b/components/soc/esp32c61/include/soc/soc_caps.h @@ -28,6 +28,7 @@ // #define SOC_ASYNC_MEMCPY_SUPPORTED 1 //TODO: [ESP32C61] IDF-9315 // #define SOC_USB_SERIAL_JTAG_SUPPORTED 1 //TODO: [ESP32C61] IDF-9319 // #define SOC_TEMP_SENSOR_SUPPORTED 1 //TODO: [ESP32C61] IDF-9322 +#define SOC_PHY_SUPPORTED 1 // #define SOC_WIFI_SUPPORTED 1 #define SOC_SUPPORTS_SECURE_DL_MODE 1 // #define SOC_ULP_SUPPORTED 1 diff --git a/components/soc/esp32h2/include/soc/Kconfig.soc_caps.in b/components/soc/esp32h2/include/soc/Kconfig.soc_caps.in index 2e41f0cb3c..a41bfe252d 100644 --- a/components/soc/esp32h2/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32h2/include/soc/Kconfig.soc_caps.in @@ -43,6 +43,10 @@ config SOC_TWAI_SUPPORTED bool default y +config SOC_PHY_SUPPORTED + bool + default y + config SOC_BT_SUPPORTED bool default y diff --git a/components/soc/esp32h2/include/soc/soc_caps.h b/components/soc/esp32h2/include/soc/soc_caps.h index 7dc38d4486..38bc58e629 100644 --- a/components/soc/esp32h2/include/soc/soc_caps.h +++ b/components/soc/esp32h2/include/soc/soc_caps.h @@ -27,6 +27,7 @@ #define SOC_PCNT_SUPPORTED 1 #define SOC_MCPWM_SUPPORTED 1 #define SOC_TWAI_SUPPORTED 1 +#define SOC_PHY_SUPPORTED 1 #define SOC_BT_SUPPORTED 1 #define SOC_GPTIMER_SUPPORTED 1 #define SOC_IEEE802154_SUPPORTED 1 diff --git a/components/soc/esp32s2/include/soc/Kconfig.soc_caps.in b/components/soc/esp32s2/include/soc/Kconfig.soc_caps.in index d986427ee4..aeedc899b5 100644 --- a/components/soc/esp32s2/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32s2/include/soc/Kconfig.soc_caps.in @@ -51,6 +51,10 @@ config SOC_PCNT_SUPPORTED bool default y +config SOC_PHY_SUPPORTED + bool + default y + config SOC_WIFI_SUPPORTED bool default y diff --git a/components/soc/esp32s2/include/soc/soc_caps.h b/components/soc/esp32s2/include/soc/soc_caps.h index 4c5365fc66..121909c1b0 100644 --- a/components/soc/esp32s2/include/soc/soc_caps.h +++ b/components/soc/esp32s2/include/soc/soc_caps.h @@ -49,6 +49,7 @@ #define SOC_RISCV_COPROC_SUPPORTED 1 #define SOC_USB_OTG_SUPPORTED 1 #define SOC_PCNT_SUPPORTED 1 +#define SOC_PHY_SUPPORTED 1 #define SOC_WIFI_SUPPORTED 1 #define SOC_ULP_SUPPORTED 1 #define SOC_CCOMP_TIMER_SUPPORTED 1 diff --git a/components/soc/esp32s3/include/soc/Kconfig.soc_caps.in b/components/soc/esp32s3/include/soc/Kconfig.soc_caps.in index 7314e76574..459752c179 100644 --- a/components/soc/esp32s3/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32s3/include/soc/Kconfig.soc_caps.in @@ -35,6 +35,10 @@ config SOC_PCNT_SUPPORTED bool default y +config SOC_PHY_SUPPORTED + bool + default y + config SOC_WIFI_SUPPORTED bool default y diff --git a/components/soc/esp32s3/include/soc/soc_caps.h b/components/soc/esp32s3/include/soc/soc_caps.h index 4d8eba5221..2ad970e252 100644 --- a/components/soc/esp32s3/include/soc/soc_caps.h +++ b/components/soc/esp32s3/include/soc/soc_caps.h @@ -25,6 +25,7 @@ #define SOC_ADC_SUPPORTED 1 #define SOC_UART_SUPPORTED 1 #define SOC_PCNT_SUPPORTED 1 +#define SOC_PHY_SUPPORTED 1 #define SOC_WIFI_SUPPORTED 1 #define SOC_TWAI_SUPPORTED 1 #define SOC_GDMA_SUPPORTED 1 From f3c50476387a12c050c4abfccf0205946763addd Mon Sep 17 00:00:00 2001 From: xiehang Date: Wed, 27 Mar 2024 16:29:09 +0800 Subject: [PATCH 2/2] feat(extconn): Supports external WiFi connections for ESP32p4 and other espressf chips --- .../bt/host/bluedroid/bta/dm/bta_dm_main.c | 4 +- components/esp_coex/CMakeLists.txt | 55 +- components/esp_coex/Kconfig | 53 +- components/esp_coex/src/lib_printf.c | 52 ++ components/esp_phy/CMakeLists.txt | 172 ++-- components/esp_phy/src/lib_printf.c | 92 +-- components/esp_wifi/CMakeLists.txt | 22 +- components/esp_wifi/Kconfig | 33 +- components/esp_wifi/esp32p4/esp_adapter.c | 754 ++++++++++++++++++ .../include/esp_private/wifi_os_adapter.h | 4 +- components/esp_wifi/lib | 2 +- components/esp_wifi/src/lib_printf.c | 106 +++ components/esp_wifi/src/wifi_init.c | 2 + components/soc/esp32/include/soc/soc_caps.h | 2 +- components/soc/esp32c2/include/soc/soc_caps.h | 2 +- components/soc/esp32c3/include/soc/soc_caps.h | 2 +- components/soc/esp32c6/include/soc/soc_caps.h | 4 +- .../esp32c61/include/soc/Kconfig.soc_caps.in | 4 - .../soc/esp32c61/include/soc/soc_caps.h | 5 +- components/soc/esp32h2/include/soc/soc_caps.h | 4 +- .../esp32p4/include/soc/Kconfig.soc_caps.in | 4 + components/soc/esp32p4/include/soc/soc_caps.h | 1 + components/soc/esp32s2/include/soc/soc_caps.h | 6 +- components/soc/esp32s3/include/soc/soc_caps.h | 2 +- components/wpa_supplicant/CMakeLists.txt | 2 +- .../station/main/station_example_main.c | 2 +- 26 files changed, 1128 insertions(+), 263 deletions(-) create mode 100644 components/esp_coex/src/lib_printf.c create mode 100644 components/esp_wifi/esp32p4/esp_adapter.c create mode 100644 components/esp_wifi/src/lib_printf.c diff --git a/components/bt/host/bluedroid/bta/dm/bta_dm_main.c b/components/bt/host/bluedroid/bta/dm/bta_dm_main.c index 27fd96109e..aa5188da63 100644 --- a/components/bt/host/bluedroid/bta/dm/bta_dm_main.c +++ b/components/bt/host/bluedroid/bta/dm/bta_dm_main.c @@ -31,7 +31,9 @@ #include "osi/allocator.h" #include +#ifdef CONFIG_ESP_COEX_ENABLED #include "esp_coexist.h" +#endif /***************************************************************************** ** Constants and types @@ -91,7 +93,7 @@ const tBTA_DM_ACTION bta_dm_action[BTA_DM_MAX_EVT] = { bta_dm_pin_reply, /* BTA_DM_API_PIN_REPLY_EVT */ #endif ///SMP_INCLUDED == TRUE #if (BTA_DM_PM_INCLUDED == TRUE) - /* power manger events */ + /* power manager events */ bta_dm_pm_btm_status, /* BTA_DM_PM_BTM_STATUS_EVT */ bta_dm_pm_timer, /* BTA_DM_PM_TIMER_EVT */ #endif /* #if (BTA_DM_PM_INCLUDED == TRUE) */ diff --git a/components/esp_coex/CMakeLists.txt b/components/esp_coex/CMakeLists.txt index c2ab2fb34c..6f0258636c 100644 --- a/components/esp_coex/CMakeLists.txt +++ b/components/esp_coex/CMakeLists.txt @@ -4,20 +4,23 @@ if(${idf_target} STREQUAL "linux") return() # This component is not supported by the POSIX/Linux simulator endif() -if(CONFIG_ESP_COEX_SW_COEXIST_ENABLE OR CONFIG_ESP_COEX_EXTERNAL_COEXIST_ENABLE) - if(CONFIG_APP_NO_BLOBS) - set(link_binary_libs 0) - set(ldfragments) - else() - set(link_binary_libs 1) - set(ldfragments "linker.lf") +if(CONFIG_ESP_COEX_ENABLED) + if(CONFIG_ESP_COEX_SW_COEXIST_ENABLE OR CONFIG_ESP_COEX_EXTERNAL_COEXIST_ENABLE) + if(CONFIG_APP_NO_BLOBS) + set(link_binary_libs 0) + set(ldfragments) + else() + set(link_binary_libs 1) + set(ldfragments "linker.lf") + endif() + set(srcs "src/coexist.c" + "src/lib_printf.c" + "${idf_target}/esp_coex_adapter.c") endif() - set(srcs "src/coexist.c" - "${idf_target}/esp_coex_adapter.c") -endif() -if(CONFIG_ESP_WIFI_ENABLED) - list(APPEND srcs "${idf_target}/esp_coex_adapter.c") + if(CONFIG_ESP_WIFI_ENABLED) + list(APPEND srcs "${idf_target}/esp_coex_adapter.c") + endif() endif() idf_component_register(SRCS "${srcs}" @@ -25,21 +28,23 @@ idf_component_register(SRCS "${srcs}" PRIV_REQUIRES esp_timer driver esp_event LDFRAGMENTS "${ldfragments}") -if(CONFIG_ESP_COEX_SW_COEXIST_ENABLE OR CONFIG_ESP_COEX_EXTERNAL_COEXIST_ENABLE) - idf_build_get_property(build_dir BUILD_DIR) +if(CONFIG_ESP_COEX_ENABLED) + if(CONFIG_ESP_COEX_SW_COEXIST_ENABLE OR CONFIG_ESP_COEX_EXTERNAL_COEXIST_ENABLE) + idf_build_get_property(build_dir BUILD_DIR) - set(target_name "${idf_target}") - target_link_directories(${COMPONENT_LIB} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/lib/${target_name}") + set(target_name "${idf_target}") + target_link_directories(${COMPONENT_LIB} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/lib/${target_name}") - if(link_binary_libs) - set(blob coexist) - add_prebuilt_library(${blob} "${CMAKE_CURRENT_SOURCE_DIR}/lib/${target_name}/lib${blob}.a" - REQUIRES ${COMPONENT_NAME}) - target_link_libraries(${COMPONENT_LIB} PUBLIC ${blob}) - if(CONFIG_IDF_TARGET_ESP32) - target_link_libraries(${COMPONENT_LIB} PRIVATE btdm_app) + if(link_binary_libs) + set(blob coexist) + add_prebuilt_library(${blob} "${CMAKE_CURRENT_SOURCE_DIR}/lib/${target_name}/lib${blob}.a" + REQUIRES ${COMPONENT_NAME}) + target_link_libraries(${COMPONENT_LIB} PUBLIC ${blob}) + if(CONFIG_IDF_TARGET_ESP32) + target_link_libraries(${COMPONENT_LIB} PRIVATE btdm_app) + endif() endif() - endif() - target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format") + target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format") + endif() endif() diff --git a/components/esp_coex/Kconfig b/components/esp_coex/Kconfig index 8dd2ec3fcc..fb982aeb0e 100644 --- a/components/esp_coex/Kconfig +++ b/components/esp_coex/Kconfig @@ -1,29 +1,36 @@ menu "Wireless Coexistence" - config ESP_COEX_SW_COEXIST_ENABLE - bool "Software controls WiFi/Bluetooth coexistence" - depends on (ESP_WIFI_ENABLED && BT_ENABLED) || \ - (ESP_WIFI_ENABLED && IEEE802154_ENABLED) || \ - (IEEE802154_ENABLED && BT_ENABLED) - default y - select ESP_WIFI_STA_DISCONNECTED_PM_ENABLE if (ESP_WIFI_ENABLED) - help - If enabled, WiFi & Bluetooth coexistence is controlled by software rather than hardware. - Recommended for heavy traffic scenarios. Both coexistence configuration options are - automatically managed, no user intervention is required. - If only Bluetooth is used, it is recommended to disable this option to reduce binary file - size. - config ESP_COEX_EXTERNAL_COEXIST_ENABLE - bool "External Coexistence" - default n - depends on (!(BT_ENABLED||NIMBLE_ENABLED)&&(!IDF_TARGET_ESP32)) - help - If enabled, HW External coexistence arbitration is managed by GPIO pins. - It can support three types of wired combinations so far which are 1-wired/2-wired/3-wired. - User can select GPIO pins in application code with configure interfaces. + config ESP_COEX_ENABLED + bool + default y if (!SOC_WIRELESS_HOST_SUPPORTED) - This function depends on BT-off - because currently we do not support external coex and internal coex simultaneously. + if(ESP_COEX_ENABLED) + config ESP_COEX_SW_COEXIST_ENABLE + bool "Software controls WiFi/Bluetooth coexistence" + depends on (ESP_WIFI_ENABLED && BT_ENABLED) || \ + (ESP_WIFI_ENABLED && IEEE802154_ENABLED) || \ + (IEEE802154_ENABLED && BT_ENABLED) + default y + select ESP_WIFI_STA_DISCONNECTED_PM_ENABLE if (ESP_WIFI_ENABLED) + help + If enabled, WiFi & Bluetooth coexistence is controlled by software rather than hardware. + Recommended for heavy traffic scenarios. Both coexistence configuration options are + automatically managed, no user intervention is required. + If only Bluetooth is used, it is recommended to disable this option to reduce binary file + size. + config ESP_COEX_EXTERNAL_COEXIST_ENABLE + bool "External Coexistence" + default n + depends on (!(BT_ENABLED||NIMBLE_ENABLED)&&(!IDF_TARGET_ESP32)) + help + If enabled, HW External coexistence arbitration is managed by GPIO pins. + It can support three types of wired combinations so far which are 1-wired/2-wired/3-wired. + User can select GPIO pins in application code with configure interfaces. + + This function depends on BT-off + because currently we do not support external coex and internal coex simultaneously. + + endif endmenu # Wireless Coexistence diff --git a/components/esp_coex/src/lib_printf.c b/components/esp_coex/src/lib_printf.c new file mode 100644 index 0000000000..265874399f --- /dev/null +++ b/components/esp_coex/src/lib_printf.c @@ -0,0 +1,52 @@ +/* + * SPDX-FileCopyrightText: 2016-2024 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @file lib_printf.c + * + * This file contains library-specific printf functions + * used by WiFi libraries in the `lib` directory. + * These function are used to catch any output which gets printed + * by libraries, and redirect it to ESP_LOG macros. + * + * Eventually WiFi libraries will use ESP_LOG functions internally + * and these definitions will be removed. + */ + +#include +#include +#include "esp_log.h" +#include "esp_attr.h" + +#define VPRINTF_STACK_BUFFER_SIZE 80 + +static int lib_printf(const char* tag, const char* format, va_list arg) +{ + char temp[VPRINTF_STACK_BUFFER_SIZE]; + int len = vsnprintf(temp, sizeof(temp) - 1, format, arg); + temp[sizeof(temp) - 1] = 0; + int i; + for (i = len - 1; i >= 0; --i) { + if (temp[i] != '\n' && temp[i] != '\r' && temp[i] != ' ') { + break; + } + temp[i] = 0; + } + if (i > 0) { + ESP_LOGI(tag, "%s", temp); + } + va_end(arg); + return len; +} + +int coexist_printf(const char* format, ...) +{ + va_list arg; + va_start(arg, format); + int res = lib_printf("coexist", format, arg); + va_end(arg); + return res; +} diff --git a/components/esp_phy/CMakeLists.txt b/components/esp_phy/CMakeLists.txt index a1c4a37b59..c4561af352 100644 --- a/components/esp_phy/CMakeLists.txt +++ b/components/esp_phy/CMakeLists.txt @@ -11,43 +11,44 @@ endif() if(CONFIG_ESP_PHY_ENABLED) -set(srcs "src/phy_override.c" "src/lib_printf.c" "src/phy_common.c") + set(srcs "src/phy_override.c" "src/lib_printf.c" "src/phy_common.c") -if(CONFIG_APP_NO_BLOBS) - set(link_binary_libs 0) - set(ldfragments) -else() - set(link_binary_libs 1) - set(ldfragments "linker.lf") -endif() - -if(CONFIG_SOC_IEEE802154_BLE_ONLY) - list(APPEND srcs "src/phy_init_esp32hxx.c") -else() - list(APPEND srcs "src/phy_init.c") -endif() - -if(CONFIG_SOC_BT_SUPPORTED OR CONFIG_SOC_IEEE802154_SUPPORTED OR CONFIG_SOC_IEEE802154_BLE_ONLY) - list(APPEND srcs "src/btbb_init.c") -endif() - -if(CONFIG_ESP_PHY_ENABLE_CERT_TEST) - list(APPEND srcs "src/phy_callback.c") -endif() - -idf_build_get_property(build_dir BUILD_DIR) - -if(CONFIG_SOC_WIFI_SUPPORTED) -if(CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN) - if(NOT EXISTS "${build_dir}/phy_multiple_init_data.bin") - file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/${idf_target}/phy_multiple_init_data.bin DESTINATION "${build_dir}") + if(CONFIG_APP_NO_BLOBS) + set(link_binary_libs 0) + set(ldfragments) + else() + set(link_binary_libs 1) + set(ldfragments "linker.lf") endif() -endif() -if(CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN_EMBED) - set(embed_files "${build_dir}/phy_multiple_init_data.bin") -endif() -endif() + if(CONFIG_SOC_IEEE802154_BLE_ONLY) + list(APPEND srcs "src/phy_init_esp32hxx.c") + else() + list(APPEND srcs "src/phy_init.c") + endif() + + if(CONFIG_SOC_BT_SUPPORTED OR CONFIG_SOC_IEEE802154_SUPPORTED OR CONFIG_SOC_IEEE802154_BLE_ONLY) + list(APPEND srcs "src/btbb_init.c") + endif() + + if(CONFIG_ESP_PHY_ENABLE_CERT_TEST) + list(APPEND srcs "src/phy_callback.c") + endif() + + idf_build_get_property(build_dir BUILD_DIR) + + if(CONFIG_SOC_WIFI_SUPPORTED) + if(CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN) + if(NOT EXISTS "${build_dir}/phy_multiple_init_data.bin") + file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/${idf_target}/phy_multiple_init_data.bin + DESTINATION "${build_dir}") + endif() + endif() + + if(CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN_EMBED) + set(embed_files "${build_dir}/phy_multiple_init_data.bin") + endif() + endif() endif() # [refactor-todo]: requires "driver" component for periph_ctrl header file @@ -59,29 +60,29 @@ idf_component_register(SRCS "${srcs}" ) if(CONFIG_ESP_PHY_ENABLED) -set(target_name "${idf_target}") -target_link_directories(${COMPONENT_LIB} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/lib/${target_name}") + set(target_name "${idf_target}") + target_link_directories(${COMPONENT_LIB} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/lib/${target_name}") -# Override functions in PHY lib with the functions in 'phy_override.c' -target_link_libraries(${COMPONENT_LIB} INTERFACE "-u include_esp_phy_override") + # Override functions in PHY lib with the functions in 'phy_override.c' + target_link_libraries(${COMPONENT_LIB} INTERFACE "-u include_esp_phy_override") -if(link_binary_libs) - target_link_libraries(${COMPONENT_LIB} PUBLIC phy) + if(link_binary_libs) + target_link_libraries(${COMPONENT_LIB} PUBLIC phy) - idf_component_get_property(esp_phy_lib esp_phy COMPONENT_LIB) + idf_component_get_property(esp_phy_lib esp_phy COMPONENT_LIB) - if(CONFIG_IDF_TARGET_ESP32) - target_link_libraries(${COMPONENT_LIB} PUBLIC rtc) - target_link_libraries(${COMPONENT_LIB} INTERFACE $ libphy.a librtc.a - $) - elseif(CONFIG_IDF_TARGET_ESP32S2) - target_link_libraries(${COMPONENT_LIB} INTERFACE $ libphy.a - $) - elseif(CONFIG_SOC_BT_SUPPORTED OR CONFIG_SOC_IEEE802154_SUPPORTED) - target_link_libraries(${COMPONENT_LIB} PUBLIC btbb) - target_link_libraries(${COMPONENT_LIB} INTERFACE $ libphy.a libbtbb.a - $) - endif() + if(CONFIG_IDF_TARGET_ESP32) + target_link_libraries(${COMPONENT_LIB} PUBLIC rtc) + target_link_libraries(${COMPONENT_LIB} INTERFACE $ libphy.a librtc.a + $) + elseif(CONFIG_IDF_TARGET_ESP32S2) + target_link_libraries(${COMPONENT_LIB} INTERFACE $ libphy.a + $) + elseif(CONFIG_SOC_BT_SUPPORTED OR CONFIG_SOC_IEEE802154_SUPPORTED) + target_link_libraries(${COMPONENT_LIB} PUBLIC btbb) + target_link_libraries(${COMPONENT_LIB} INTERFACE $ libphy.a libbtbb.a + $) + endif() if(CONFIG_ESP_PHY_ENABLE_CERT_TEST) target_link_libraries(${COMPONENT_LIB} INTERFACE $ libbttestmode.a @@ -89,42 +90,43 @@ if(link_binary_libs) endif() endif() -if(CONFIG_ESP_PHY_INIT_DATA_IN_PARTITION) - idf_component_get_property(esp_common_dir esp_common COMPONENT_DIR) - partition_table_get_partition_info(phy_partition_offset "--partition-type data --partition-subtype phy" "offset") + if(CONFIG_ESP_PHY_INIT_DATA_IN_PARTITION) + idf_component_get_property(esp_common_dir esp_common COMPONENT_DIR) + partition_table_get_partition_info(phy_partition_offset + "--partition-type data --partition-subtype phy" "offset") - if(CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN) - set(phy_init_data_bin "${build_dir}/phy_multiple_init_data.bin") - if(CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN_EMBED) - set(COMPONENT_EMBED_FILES "${build_dir}/phy_multiple_init_data.bin") + if(CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN) + set(phy_init_data_bin "${build_dir}/phy_multiple_init_data.bin") + if(CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN_EMBED) + set(COMPONENT_EMBED_FILES "${build_dir}/phy_multiple_init_data.bin") + endif() + else() + set(phy_init_data_bin "${build_dir}/phy_init_data.bin") + + # To get the phy_init_data.bin file, compile phy_init_data.h as a C file and then objcopy + # the object file to a raw binary + idf_build_get_property(config_dir CONFIG_DIR) + add_custom_command( + OUTPUT ${phy_init_data_bin} + DEPENDS ${CMAKE_CURRENT_LIST_DIR}/${idf_target}/include/phy_init_data.h + COMMAND ${CMAKE_C_COMPILER} -x c -c + -I ${esp_common_dir}/include -I ${CMAKE_CURRENT_LIST_DIR}/include -I ${config_dir} + -o phy_init_data.obj + ${CMAKE_CURRENT_LIST_DIR}/${idf_target}/include/phy_init_data.h + COMMAND ${CMAKE_OBJCOPY} -O binary phy_init_data.obj ${phy_init_data_bin} + ) + add_custom_target(phy_init_data ALL DEPENDS ${phy_init_data_bin}) + add_dependencies(flash phy_init_data) + + idf_component_get_property(main_args esptool_py FLASH_ARGS) + idf_component_get_property(sub_args esptool_py FLASH_SUB_ARGS) endif() - else() - set(phy_init_data_bin "${build_dir}/phy_init_data.bin") - # To get the phy_init_data.bin file, compile phy_init_data.h as a C file and then objcopy - # the object file to a raw binary - idf_build_get_property(config_dir CONFIG_DIR) - add_custom_command( - OUTPUT ${phy_init_data_bin} - DEPENDS ${CMAKE_CURRENT_LIST_DIR}/${idf_target}/include/phy_init_data.h - COMMAND ${CMAKE_C_COMPILER} -x c -c - -I ${esp_common_dir}/include -I ${CMAKE_CURRENT_LIST_DIR}/include -I ${config_dir} - -o phy_init_data.obj - ${CMAKE_CURRENT_LIST_DIR}/${idf_target}/include/phy_init_data.h - COMMAND ${CMAKE_OBJCOPY} -O binary phy_init_data.obj ${phy_init_data_bin} - ) - add_custom_target(phy_init_data ALL DEPENDS ${phy_init_data_bin}) - add_dependencies(flash phy_init_data) + set(phy_name "phy") - idf_component_get_property(main_args esptool_py FLASH_ARGS) - idf_component_get_property(sub_args esptool_py FLASH_SUB_ARGS) + esptool_py_flash_target(${phy_name}-flash "${main_args}" "${sub_args}") + esptool_py_flash_target_image(${phy_name}-flash ${phy_name} "${phy_partition_offset}" "${phy_init_data_bin}") + esptool_py_flash_target_image(flash ${phy_name} "${phy_partition_offset}" "${phy_init_data_bin}") endif() - set(phy_name "phy") - - esptool_py_flash_target(${phy_name}-flash "${main_args}" "${sub_args}") - esptool_py_flash_target_image(${phy_name}-flash ${phy_name} "${phy_partition_offset}" "${phy_init_data_bin}") - esptool_py_flash_target_image(flash ${phy_name} "${phy_partition_offset}" "${phy_init_data_bin}") -endif() - endif() diff --git a/components/esp_phy/src/lib_printf.c b/components/esp_phy/src/lib_printf.c index 8c5a8421db..4a97ae2bae 100644 --- a/components/esp_phy/src/lib_printf.c +++ b/components/esp_phy/src/lib_printf.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2016-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2016-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -60,93 +60,3 @@ int rtc_printf(const char* format, ...) va_end(arg); return res; } - -int wpa_printf(const char* format, ...) -{ - va_list arg; - va_start(arg, format); - int res = lib_printf("wpa", format, arg); - va_end(arg); - return res; -} - -int wpa2_printf(const char* format, ...) -{ - va_list arg; - va_start(arg, format); - int res = lib_printf("wpa2", format, arg); - va_end(arg); - return res; -} - -int wps_printf(const char* format, ...) -{ - va_list arg; - va_start(arg, format); - int res = lib_printf("wps", format, arg); - va_end(arg); - return res; -} - -int pp_printf(const char* format, ...) -{ - va_list arg; - va_start(arg, format); - int res = lib_printf("pp", format, arg); - va_end(arg); - return res; -} - -int sc_printf(const char* format, ...) -{ - va_list arg; - va_start(arg, format); - int res = lib_printf("smartconfig", format, arg); - va_end(arg); - return res; -} - -int core_printf(const char* format, ...) -{ - va_list arg; - va_start(arg, format); - int res = lib_printf("core", format, arg); - va_end(arg); - return res; -} - -int net80211_printf(const char* format, ...) -{ - va_list arg; - va_start(arg, format); - int res = lib_printf("net80211", format, arg); - va_end(arg); - return res; -} - -int coexist_printf(const char* format, ...) -{ - va_list arg; - va_start(arg, format); - int res = lib_printf("coexist", format, arg); - va_end(arg); - return res; -} - -int wapi_printf(const char* format, ...) -{ - va_list arg; - va_start(arg, format); - int res = lib_printf("wapi", format, arg); - va_end(arg); - return res; -} - -int mesh_printf(const char* format, ...) -{ - va_list arg; - va_start(arg, format); - int res = lib_printf("mesh", format, arg); - va_end(arg); - return res; -} diff --git a/components/esp_wifi/CMakeLists.txt b/components/esp_wifi/CMakeLists.txt index 3844ab83ed..29caded012 100644 --- a/components/esp_wifi/CMakeLists.txt +++ b/components/esp_wifi/CMakeLists.txt @@ -4,7 +4,7 @@ if(${idf_target} STREQUAL "linux") return() # This component is not supported by the POSIX/Linux simulator endif() -if(CONFIG_ESP_WIFI_ENABLED) +if(CONFIG_ESP_WIFI_ENABLED OR CONFIG_ESP_HOST_WIFI_ENABLED) if(CONFIG_APP_NO_BLOBS) set(link_binary_libs 0) @@ -22,6 +22,7 @@ if(CONFIG_ESP_WIFI_ENABLED) endif() set(srcs + "src/lib_printf.c" "src/mesh_event.c" "src/smartconfig.c" "src/wifi_init.c" @@ -55,17 +56,26 @@ idf_component_register(SRCS "${srcs}" wpa_supplicant hal lwip esp_coex ${extra_priv_requires} LDFRAGMENTS "${ldfragments}") -if(CONFIG_ESP_WIFI_ENABLED) +if(CONFIG_ESP_WIFI_ENABLED OR CONFIG_ESP_HOST_WIFI_ENABLED) idf_build_get_property(build_dir BUILD_DIR) - set(target_name "${idf_target}") + if(CONFIG_ESP_HOST_WIFI_ENABLED) + set(target_name "${CONFIG_ESP_WIFI_CONTROLLER_TARGET}_host") + else() + set(target_name "${idf_target}") + endif() + target_link_directories(${COMPONENT_LIB} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/lib/${target_name}") if(link_binary_libs) - if(CONFIG_IDF_TARGET_ESP32C2) - set(blobs core espnow net80211 pp smartconfig) + if(CONFIG_ESP_HOST_WIFI_ENABLED) + set(blobs core espnow net80211 target smartconfig wapi) else() - set(blobs core espnow mesh net80211 pp smartconfig wapi) + if(CONFIG_IDF_TARGET_ESP32C2) + set(blobs core espnow net80211 pp smartconfig) + else() + set(blobs core espnow mesh net80211 pp smartconfig wapi) + endif() endif() foreach(blob ${blobs}) diff --git a/components/esp_wifi/Kconfig b/components/esp_wifi/Kconfig index 95d00e3d79..f9c534a510 100644 --- a/components/esp_wifi/Kconfig +++ b/components/esp_wifi/Kconfig @@ -7,7 +7,22 @@ menu "Wi-Fi" bool default y if SOC_WIFI_SUPPORTED - if ESP_WIFI_ENABLED + config ESP_HOST_WIFI_ENABLED + bool "Host WiFi Enable" + depends on SOC_WIRELESS_HOST_SUPPORTED + default n + + config ESP_WIFI_CONTROLLER_TARGET + depends on ESP_HOST_WIFI_ENABLED + string + default "esp32" + + config ESP_WIFI_TARGET_ESP32 + depends on ESP_HOST_WIFI_ENABLED + bool + default y if ESP_WIFI_CONTROLLER_TARGET="esp32" + + if (ESP_WIFI_ENABLED || ESP_HOST_WIFI_ENABLED) config ESP_WIFI_STATIC_RX_BUFFER_NUM int "Max number of WiFi static RX buffers" @@ -194,7 +209,7 @@ menu "Wi-Fi" Set the size of WiFi Block Ack RX window. Generally a bigger value means higher throughput and better compatibility but more memory. Most of time we should NOT change the default value unless special reason, e.g. test the maximum UDP RX throughput with iperf etc. For iperf test in shieldbox, the - recommended value is 9~12. If PSRAM is used and WiFi memory is prefered to allocat in PSRAM first, + recommended value is 9~12. If PSRAM is used and WiFi memory is preferred to allocate in PSRAM first, the default and minimum value should be 16 to achieve better throughput and compatibility with both stations and APs. @@ -231,14 +246,14 @@ menu "Wi-Fi" help ESP-MESH utilizes beacon frames to detect and resolve root node conflicts (see documentation). However the default length of a beacon frame can simultaneously hold only five root node identifier structures, - meaning that a root node conflict of up to five nodes can be detected at one time. In the occurence of + meaning that a root node conflict of up to five nodes can be detected at one time. In the occurrence of more root nodes conflict involving more than five root nodes, the conflict resolution process will detect five of the root nodes, resolve the conflict, and re-detect more root nodes. This process will repeat until all root node conflicts are resolved. However this process can generally take a very long time. To counter this situation, the beacon frame length can be increased such that more root nodes can be - detected simultaneously. Each additional root node will require 36 bytes and should be added ontop of + detected simultaneously. Each additional root node will require 36 bytes and should be added on top of the default beacon frame length of 752 bytes. For example, if you want to detect 10 root nodes simultaneously, you need to set the beacon frame length as @@ -490,9 +505,9 @@ menu "Wi-Fi" help Select this option to use MbedTLS TLS client for WPA2 enterprise connection. Please note that from MbedTLS-3.0 onwards, MbedTLS does not support SSL-3.0 - TLS-v1.0, TLS-v1.1 versions. Incase your server is using one of these version, + TLS-v1.0, TLS-v1.1 versions. In case your server is using one of these version, it is advisable to update your server. - Please disable this option for compatibilty with older TLS versions. + Please disable this option for compatibility with older TLS versions. config ESP_WIFI_EAP_TLS1_3 bool "Enable EAP-TLS v1.3 Support for WiFi Enterprise connection" @@ -600,7 +615,7 @@ menu "Wi-Fi" default n help Select this option to enable validate each WPS attribute - rigorously. Disabling this add the workaorunds with various APs. + rigorously. Disabling this add the workarounds with various APs. Enabling this may cause inter operability issues with some APs. config ESP_WIFI_WPS_PASSPHRASE @@ -608,9 +623,9 @@ menu "Wi-Fi" default n help Select this option to get passphrase during WPS configuration. - This option fakes the virtual display capabilites to get the + This option fakes the virtual display capabilities to get the configuration in passphrase mode. - Not recommanded to be used since WPS credentials should not + Not recommended to be used since WPS credentials should not be shared to other devices, making it in readable format increases that risk, also passphrase requires pbkdf2 to convert in psk. diff --git a/components/esp_wifi/esp32p4/esp_adapter.c b/components/esp_wifi/esp32p4/esp_adapter.c new file mode 100644 index 0000000000..69494a94cc --- /dev/null +++ b/components/esp_wifi/esp32p4/esp_adapter.c @@ -0,0 +1,754 @@ +/* + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include +#include + +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "freertos/queue.h" +#include "freertos/semphr.h" +#include "freertos/event_groups.h" +#include "freertos/portmacro.h" +#include "riscv/interrupt.h" +#include "esp_types.h" +#include "esp_random.h" +#include "esp_mac.h" +#include "esp_task.h" +#include "esp_intr_alloc.h" +#include "esp_attr.h" +#include "esp_log.h" +#include "esp_event.h" +#include "esp_heap_caps.h" +#include "esp_timer.h" +#include "esp_private/esp_modem_clock.h" +#include "esp_private/wifi_os_adapter.h" +#include "esp_private/wifi.h" +#include "soc/rtc_cntl_periph.h" +#include "soc/rtc.h" +#include "esp_private/periph_ctrl.h" +#include "esp_private/esp_clk.h" +#include "nvs.h" +#include "os.h" +#include "esp_smartconfig.h" +#include "esp32p4/rom/ets_sys.h" +#include "esp_private/esp_modem_clock.h" + +#if SOC_PM_MODEM_RETENTION_BY_REGDMA +#include "esp_private/esp_regdma.h" +#include "esp_private/sleep_retention.h" +#endif + +#define TAG "esp_adapter" + +#ifdef CONFIG_PM_ENABLE +extern void wifi_apb80m_request(void); +extern void wifi_apb80m_release(void); +#endif + +IRAM_ATTR void *wifi_malloc( size_t size ) +{ +#if CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP + return heap_caps_malloc_prefer(size, 2, MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL); +#else + return malloc(size); +#endif +} + +/* + If CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP is enabled. Prefer to allocate a chunk of memory in SPIRAM firstly. + If failed, try to allocate it in internal memory then. + */ +IRAM_ATTR void *wifi_realloc( void *ptr, size_t size ) +{ +#if CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP + return heap_caps_realloc_prefer(ptr, size, 2, MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL); +#else + return realloc(ptr, size); +#endif +} + +/* + If CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP is enabled. Prefer to allocate a chunk of memory in SPIRAM firstly. + If failed, try to allocate it in internal memory then. + */ +IRAM_ATTR void *wifi_calloc( size_t n, size_t size ) +{ +#if CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP + return heap_caps_calloc_prefer(n, size, 2, MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL); +#else + return calloc(n, size); +#endif +} + +static void *IRAM_ATTR wifi_zalloc_wrapper(size_t size) +{ + void *ptr = wifi_calloc(1, size); + return ptr; +} + +wifi_static_queue_t *wifi_create_queue( int queue_len, int item_size) +{ + wifi_static_queue_t *queue = NULL; + + queue = (wifi_static_queue_t *)heap_caps_malloc(sizeof(wifi_static_queue_t), MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT); + if (!queue) { + return NULL; + } + +#if CONFIG_SPIRAM_USE_MALLOC + + queue->storage = heap_caps_calloc(1, sizeof(StaticQueue_t) + (queue_len*item_size), MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); + if (!queue->storage) { + goto _error; + } + + queue->handle = xQueueCreateStatic( queue_len, item_size, ((uint8_t*)(queue->storage)) + sizeof(StaticQueue_t), (StaticQueue_t*)(queue->storage)); + + if (!queue->handle) { + goto _error; + } + + return queue; + +_error: + if (queue) { + if (queue->storage) { + free(queue->storage); + } + + free(queue); + } + + return NULL; +#else + queue->handle = xQueueCreate( queue_len, item_size); + return queue; +#endif +} + +void wifi_delete_queue(wifi_static_queue_t *queue) +{ + if (queue) { + vQueueDelete(queue->handle); + +#if CONFIG_SPIRAM_USE_MALLOC + if (queue->storage) { + free(queue->storage); + } +#endif + + free(queue); + } +} + +static void *wifi_create_queue_wrapper(int queue_len, int item_size) +{ + return wifi_create_queue(queue_len, item_size); +} + +static void wifi_delete_queue_wrapper(void *queue) +{ + wifi_delete_queue(queue); +} + +static void set_intr_wrapper(int32_t cpu_no, uint32_t intr_source, uint32_t intr_num, int32_t intr_prio) +{ + esp_rom_route_intr_matrix(cpu_no, intr_source, intr_num); + esprv_int_set_priority(intr_num, intr_prio); + esprv_int_set_type(intr_num, INTR_TYPE_LEVEL); +} + +static void clear_intr_wrapper(uint32_t intr_source, uint32_t intr_num) +{ + +} + +static void set_isr_wrapper(int32_t n, void *f, void *arg) +{ + intr_handler_set(n, (intr_handler_t)f, arg); +} + +static void enable_intr_wrapper(uint32_t intr_mask) +{ + esprv_int_enable(intr_mask); +} + +static void disable_intr_wrapper(uint32_t intr_mask) +{ + esprv_int_disable(intr_mask); +} + +static bool IRAM_ATTR is_from_isr_wrapper(void) +{ + return !xPortCanYield(); +} + +static void wifi_thread_semphr_free(void *data) +{ + SemaphoreHandle_t *sem = (SemaphoreHandle_t *)(data); + + if (sem) { + vSemaphoreDelete(sem); + } +} + +static void *wifi_thread_semphr_get_wrapper(void) +{ + static bool s_wifi_thread_sem_key_init = false; + static pthread_key_t s_wifi_thread_sem_key; + SemaphoreHandle_t sem = NULL; + + if (s_wifi_thread_sem_key_init == false) { + if (0 != pthread_key_create(&s_wifi_thread_sem_key, wifi_thread_semphr_free)) { + return NULL; + } + s_wifi_thread_sem_key_init = true; + } + + sem = pthread_getspecific(s_wifi_thread_sem_key); + if (!sem) { + sem = xSemaphoreCreateCounting(1, 0); + if (sem) { + pthread_setspecific(s_wifi_thread_sem_key, sem); + ESP_LOGV(TAG, "thread sem create: sem=%p", sem); + } + } + + ESP_LOGV(TAG, "thread sem get: sem=%p", sem); + return (void *)sem; +} + +static void *recursive_mutex_create_wrapper(void) +{ + return (void *)xSemaphoreCreateRecursiveMutex(); +} + +static void *mutex_create_wrapper(void) +{ + return (void *)xSemaphoreCreateMutex(); +} + +static void mutex_delete_wrapper(void *mutex) +{ + vSemaphoreDelete(mutex); +} + +static int32_t IRAM_ATTR mutex_lock_wrapper(void *mutex) +{ + return (int32_t)xSemaphoreTakeRecursive(mutex, portMAX_DELAY); +} + +static int32_t IRAM_ATTR mutex_unlock_wrapper(void *mutex) +{ + return (int32_t)xSemaphoreGiveRecursive(mutex); +} + +static void *queue_create_wrapper(uint32_t queue_len, uint32_t item_size) +{ + return (void *)xQueueCreate(queue_len, item_size); +} + +static int32_t queue_send_wrapper(void *queue, void *item, uint32_t block_time_tick) +{ + if (block_time_tick == OSI_FUNCS_TIME_BLOCKING) { + return (int32_t)xQueueSend(queue, item, portMAX_DELAY); + } else { + return (int32_t)xQueueSend(queue, item, block_time_tick); + } +} + +static int32_t IRAM_ATTR queue_send_from_isr_wrapper(void *queue, void *item, void *hptw) +{ + return (int32_t)xQueueSendFromISR(queue, item, hptw); +} + +static int32_t queue_send_to_back_wrapper(void *queue, void *item, uint32_t block_time_tick) +{ + return (int32_t)xQueueGenericSend(queue, item, block_time_tick, queueSEND_TO_BACK); +} + +static int32_t queue_send_to_front_wrapper(void *queue, void *item, uint32_t block_time_tick) +{ + return (int32_t)xQueueGenericSend(queue, item, block_time_tick, queueSEND_TO_FRONT); +} + +static int32_t queue_recv_wrapper(void *queue, void *item, uint32_t block_time_tick) +{ + if (block_time_tick == OSI_FUNCS_TIME_BLOCKING) { + return (int32_t)xQueueReceive(queue, item, portMAX_DELAY); + } else { + return (int32_t)xQueueReceive(queue, item, block_time_tick); + } +} + +static uint32_t event_group_wait_bits_wrapper(void *event, uint32_t bits_to_wait_for, int clear_on_exit, int wait_for_all_bits, uint32_t block_time_tick) +{ + if (block_time_tick == OSI_FUNCS_TIME_BLOCKING) { + return (uint32_t)xEventGroupWaitBits(event, bits_to_wait_for, clear_on_exit, wait_for_all_bits, portMAX_DELAY); + } else { + return (uint32_t)xEventGroupWaitBits(event, bits_to_wait_for, clear_on_exit, wait_for_all_bits, block_time_tick); + } +} + +static int32_t task_create_pinned_to_core_wrapper(void *task_func, const char *name, uint32_t stack_depth, void *param, uint32_t prio, void *task_handle, uint32_t core_id) +{ + return (uint32_t)xTaskCreatePinnedToCore(task_func, name, stack_depth, param, prio, task_handle, (core_id < portNUM_PROCESSORS ? core_id : tskNO_AFFINITY)); +} + +static int32_t task_create_wrapper(void *task_func, const char *name, uint32_t stack_depth, void *param, uint32_t prio, void *task_handle) +{ + return (uint32_t)xTaskCreate(task_func, name, stack_depth, param, prio, task_handle); +} + +static int32_t IRAM_ATTR task_ms_to_tick_wrapper(uint32_t ms) +{ + return (int32_t)(ms / portTICK_PERIOD_MS); +} + +static int32_t task_get_max_priority_wrapper(void) +{ + return (int32_t)(configMAX_PRIORITIES); +} + +static int32_t esp_event_post_wrapper(const char *event_base, int32_t event_id, void *event_data, size_t event_data_size, uint32_t ticks_to_wait) +{ + if (ticks_to_wait == OSI_FUNCS_TIME_BLOCKING) { + return (int32_t)esp_event_post(event_base, event_id, event_data, event_data_size, portMAX_DELAY); + } else { + return (int32_t)esp_event_post(event_base, event_id, event_data, event_data_size, ticks_to_wait); + } +} + +static void IRAM_ATTR wifi_apb80m_request_wrapper(void) +{ +#ifdef CONFIG_PM_ENABLE + wifi_apb80m_request(); +#endif +} + +static void IRAM_ATTR wifi_apb80m_release_wrapper(void) +{ +#ifdef CONFIG_PM_ENABLE + wifi_apb80m_release(); +#endif +} + +static void IRAM_ATTR timer_arm_wrapper(void *timer, uint32_t tmout, bool repeat) +{ + ets_timer_arm(timer, tmout, repeat); +} + +static void wifi_reset_mac_wrapper(void) +{ + // modem_clock_module_mac_reset(PERIPH_WIFI_MODULE); +} + +static void wifi_clock_enable_wrapper(void) +{ + // wifi_module_enable(); +} + +static void wifi_clock_disable_wrapper(void) +{ + // wifi_module_disable(); +} + +static int get_time_wrapper(void *t) +{ + return os_get_time(t); +} + +static void *IRAM_ATTR realloc_internal_wrapper(void *ptr, size_t size) +{ + return heap_caps_realloc(ptr, size, MALLOC_CAP_8BIT | MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL); +} + +static void *IRAM_ATTR calloc_internal_wrapper(size_t n, size_t size) +{ + return heap_caps_calloc(n, size, MALLOC_CAP_8BIT | MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL); +} + +static void *IRAM_ATTR zalloc_internal_wrapper(size_t size) +{ + void *ptr = heap_caps_calloc(1, size, MALLOC_CAP_8BIT | MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL); + return ptr; +} + +static esp_err_t nvs_open_wrapper(const char *name, unsigned int open_mode, nvs_handle_t *out_handle) +{ + return nvs_open(name, (nvs_open_mode_t)open_mode, out_handle); +} + +static void esp_log_writev_wrapper(unsigned int level, const char *tag, const char *format, va_list args) +{ + return esp_log_writev((esp_log_level_t)level, tag, format, args); +} + +static void esp_log_write_wrapper(unsigned int level, const char *tag, const char *format, ...) +{ + va_list list; + va_start(list, format); + esp_log_writev((esp_log_level_t)level, tag, format, list); + va_end(list); +} + +static esp_err_t esp_read_mac_wrapper(uint8_t *mac, unsigned int type) +{ + return ESP_FAIL; +} + +static int coex_init_wrapper(void) +{ + return 0; +} + +static void coex_deinit_wrapper(void) +{ +} + +static int coex_enable_wrapper(void) +{ + return 0; +} + +static void coex_disable_wrapper(void) +{ +} + +static IRAM_ATTR uint32_t coex_status_get_wrapper(void) +{ + return 0; +} + +static int coex_wifi_request_wrapper(uint32_t event, uint32_t latency, uint32_t duration) +{ + return 0; +} + +static IRAM_ATTR int coex_wifi_release_wrapper(uint32_t event) +{ + return 0; +} + +static int coex_wifi_channel_set_wrapper(uint8_t primary, uint8_t secondary) +{ + return 0; +} + +static IRAM_ATTR int coex_event_duration_get_wrapper(uint32_t event, uint32_t *duration) +{ + return 0; +} + +static int coex_pti_get_wrapper(uint32_t event, uint8_t *pti) +{ + return 0; +} + +static void coex_schm_status_bit_clear_wrapper(uint32_t type, uint32_t status) +{ +} + +static void coex_schm_status_bit_set_wrapper(uint32_t type, uint32_t status) +{ +} + +static IRAM_ATTR int coex_schm_interval_set_wrapper(uint32_t interval) +{ + return 0; +} + +static uint32_t coex_schm_interval_get_wrapper(void) +{ + return 0; +} + +static uint8_t coex_schm_curr_period_get_wrapper(void) +{ + return 0; +} + +static void *coex_schm_curr_phase_get_wrapper(void) +{ + return NULL; +} + +static int coex_register_start_cb_wrapper(int (* cb)(void)) +{ + return 0; +} + +static int coex_schm_process_restart_wrapper(void) +{ + return 0; +} + +static int coex_schm_register_cb_wrapper(int type, int(*cb)(int)) +{ + return 0; +} + +static void IRAM_ATTR esp_empty_wrapper(void) +{ + +} + +static void esp_phy_enable_wrapper(void) +{ + // esp_phy_enable(PHY_MODEM_WIFI); + // phy_wifi_enable_set(1); +} + +static void esp_phy_disable_wrapper(void) +{ + // phy_wifi_enable_set(0); + // esp_phy_disable(PHY_MODEM_WIFI); +} + +void esp_phy_disable(void) +{ + +} + +void esp_phy_enable(void) +{ + +} + +void esp_phy_common_clock_enable(void) +{ + +} + +void esp_phy_common_clock_disable(void) +{ + +} + +esp_err_t esp_phy_update_country_info(const char *country) +{ + return ESP_OK; +} + +bool IRAM_ATTR esp_coex_common_env_is_chip_wrapper(void) +{ +#ifdef CONFIG_IDF_ENV_FPGA + return false; +#else + return true; +#endif +} + +void * esp_coex_common_spin_lock_create_wrapper(void) +{ + portMUX_TYPE tmp = portMUX_INITIALIZER_UNLOCKED; + void *mux = heap_caps_malloc(sizeof(portMUX_TYPE), MALLOC_CAP_8BIT|MALLOC_CAP_INTERNAL); + + if (mux) { + memcpy(mux,&tmp,sizeof(portMUX_TYPE)); + return mux; + } + return NULL; +} + +uint32_t IRAM_ATTR esp_coex_common_int_disable_wrapper(void *wifi_int_mux) +{ + if (xPortInIsrContext()) { + portENTER_CRITICAL_ISR(wifi_int_mux); + } else { + portENTER_CRITICAL(wifi_int_mux); + } + + return 0; +} + +void IRAM_ATTR esp_coex_common_int_restore_wrapper(void *wifi_int_mux, uint32_t tmp) +{ + if (xPortInIsrContext()) { + portEXIT_CRITICAL_ISR(wifi_int_mux); + } else { + portEXIT_CRITICAL(wifi_int_mux); + } +} + +void IRAM_ATTR esp_coex_common_task_yield_from_isr_wrapper(void) +{ + portYIELD_FROM_ISR(); +} + +void * esp_coex_common_semphr_create_wrapper(uint32_t max, uint32_t init) +{ + return (void *)xSemaphoreCreateCounting(max, init); +} + +void esp_coex_common_semphr_delete_wrapper(void *semphr) +{ + vSemaphoreDelete(semphr); +} + +int32_t esp_coex_common_semphr_take_wrapper(void *semphr, uint32_t block_time_tick) +{ + if (block_time_tick == OSI_FUNCS_TIME_BLOCKING) { + return (int32_t)xSemaphoreTake(semphr, portMAX_DELAY); + } else { + return (int32_t)xSemaphoreTake(semphr, block_time_tick); + } +} + +int32_t esp_coex_common_semphr_give_wrapper(void *semphr) +{ + return (int32_t)xSemaphoreGive(semphr); +} + +void IRAM_ATTR esp_coex_common_timer_disarm_wrapper(void *timer) +{ + ets_timer_disarm(timer); +} + +void esp_coex_common_timer_done_wrapper(void *ptimer) +{ + ets_timer_done(ptimer); +} + +void esp_coex_common_timer_setfn_wrapper(void *ptimer, void *pfunction, void *parg) +{ + ets_timer_setfn(ptimer, pfunction, parg); +} + +void IRAM_ATTR esp_coex_common_timer_arm_us_wrapper(void *ptimer, uint32_t us, bool repeat) +{ + ets_timer_arm_us(ptimer, us, repeat); +} + +void * IRAM_ATTR esp_coex_common_malloc_internal_wrapper(size_t size) +{ + return heap_caps_malloc(size, MALLOC_CAP_8BIT|MALLOC_CAP_DMA|MALLOC_CAP_INTERNAL); +} + +wifi_osi_funcs_t g_wifi_osi_funcs = { + ._version = ESP_WIFI_OS_ADAPTER_VERSION, + ._env_is_chip = esp_coex_common_env_is_chip_wrapper, + ._set_intr = set_intr_wrapper, + ._clear_intr = clear_intr_wrapper, + ._set_isr = set_isr_wrapper, + ._ints_on = enable_intr_wrapper, + ._ints_off = disable_intr_wrapper, + ._is_from_isr = is_from_isr_wrapper, + ._spin_lock_create = esp_coex_common_spin_lock_create_wrapper, + ._spin_lock_delete = free, + ._wifi_int_disable = esp_coex_common_int_disable_wrapper, + ._wifi_int_restore = esp_coex_common_int_restore_wrapper, + ._task_yield_from_isr = esp_coex_common_task_yield_from_isr_wrapper, + ._semphr_create = esp_coex_common_semphr_create_wrapper, + ._semphr_delete = esp_coex_common_semphr_delete_wrapper, + ._semphr_take = esp_coex_common_semphr_take_wrapper, + ._semphr_give = esp_coex_common_semphr_give_wrapper, + ._wifi_thread_semphr_get = wifi_thread_semphr_get_wrapper, + ._mutex_create = mutex_create_wrapper, + ._recursive_mutex_create = recursive_mutex_create_wrapper, + ._mutex_delete = mutex_delete_wrapper, + ._mutex_lock = mutex_lock_wrapper, + ._mutex_unlock = mutex_unlock_wrapper, + ._queue_create = queue_create_wrapper, + ._queue_delete = (void(*)(void *))vQueueDelete, + ._queue_send = queue_send_wrapper, + ._queue_send_from_isr = queue_send_from_isr_wrapper, + ._queue_send_to_back = queue_send_to_back_wrapper, + ._queue_send_to_front = queue_send_to_front_wrapper, + ._queue_recv = queue_recv_wrapper, + ._queue_msg_waiting = (uint32_t(*)(void *))uxQueueMessagesWaiting, + ._event_group_create = (void *(*)(void))xEventGroupCreate, + ._event_group_delete = (void(*)(void *))vEventGroupDelete, + ._event_group_set_bits = (uint32_t(*)(void *, uint32_t))xEventGroupSetBits, + ._event_group_clear_bits = (uint32_t(*)(void *, uint32_t))xEventGroupClearBits, + ._event_group_wait_bits = event_group_wait_bits_wrapper, + ._task_create_pinned_to_core = task_create_pinned_to_core_wrapper, + ._task_create = task_create_wrapper, + ._task_delete = (void(*)(void *))vTaskDelete, + ._task_delay = vTaskDelay, + ._task_ms_to_tick = task_ms_to_tick_wrapper, + ._task_get_current_task = (void *(*)(void))xTaskGetCurrentTaskHandle, + ._task_get_max_priority = task_get_max_priority_wrapper, + ._malloc = malloc, + ._free = free, + ._event_post = esp_event_post_wrapper, + ._get_free_heap_size = esp_get_free_internal_heap_size, + ._rand = esp_random, + ._dport_access_stall_other_cpu_start_wrap = esp_empty_wrapper, + ._dport_access_stall_other_cpu_end_wrap = esp_empty_wrapper, + ._wifi_apb80m_request = wifi_apb80m_request_wrapper, + ._wifi_apb80m_release = wifi_apb80m_release_wrapper, + ._phy_disable = esp_phy_disable_wrapper, + ._phy_enable = esp_phy_enable_wrapper, + ._phy_common_clock_enable = esp_phy_common_clock_enable, + ._phy_common_clock_disable = esp_phy_common_clock_disable, + ._phy_update_country_info = esp_phy_update_country_info, + ._read_mac = esp_read_mac_wrapper, + ._timer_arm = timer_arm_wrapper, + ._timer_disarm = esp_coex_common_timer_disarm_wrapper, + ._timer_done = esp_coex_common_timer_done_wrapper, + ._timer_setfn = esp_coex_common_timer_setfn_wrapper, + ._timer_arm_us = esp_coex_common_timer_arm_us_wrapper, + ._wifi_reset_mac = wifi_reset_mac_wrapper, + ._wifi_clock_enable = wifi_clock_enable_wrapper, + ._wifi_clock_disable = wifi_clock_disable_wrapper, + ._wifi_rtc_enable_iso = esp_empty_wrapper, + ._wifi_rtc_disable_iso = esp_empty_wrapper, + ._esp_timer_get_time = esp_timer_get_time, + ._nvs_set_i8 = nvs_set_i8, + ._nvs_get_i8 = nvs_get_i8, + ._nvs_set_u8 = nvs_set_u8, + ._nvs_get_u8 = nvs_get_u8, + ._nvs_set_u16 = nvs_set_u16, + ._nvs_get_u16 = nvs_get_u16, + ._nvs_open = nvs_open_wrapper, + ._nvs_close = nvs_close, + ._nvs_commit = nvs_commit, + ._nvs_set_blob = nvs_set_blob, + ._nvs_get_blob = nvs_get_blob, + ._nvs_erase_key = nvs_erase_key, + ._get_random = os_get_random, + ._get_time = get_time_wrapper, + ._random = os_random, + ._log_write = esp_log_write_wrapper, + ._log_writev = esp_log_writev_wrapper, + ._log_timestamp = esp_log_timestamp, + ._malloc_internal = esp_coex_common_malloc_internal_wrapper, + ._realloc_internal = realloc_internal_wrapper, + ._calloc_internal = calloc_internal_wrapper, + ._zalloc_internal = zalloc_internal_wrapper, + ._wifi_malloc = wifi_malloc, + ._wifi_realloc = wifi_realloc, + ._wifi_calloc = wifi_calloc, + ._wifi_zalloc = wifi_zalloc_wrapper, + ._wifi_create_queue = wifi_create_queue_wrapper, + ._wifi_delete_queue = wifi_delete_queue_wrapper, + ._coex_init = coex_init_wrapper, + ._coex_deinit = coex_deinit_wrapper, + ._coex_enable = coex_enable_wrapper, + ._coex_disable = coex_disable_wrapper, + ._coex_status_get = coex_status_get_wrapper, + ._coex_wifi_request = coex_wifi_request_wrapper, + ._coex_wifi_release = coex_wifi_release_wrapper, + ._coex_wifi_channel_set = coex_wifi_channel_set_wrapper, + ._coex_event_duration_get = coex_event_duration_get_wrapper, + ._coex_pti_get = coex_pti_get_wrapper, + ._coex_schm_status_bit_clear = coex_schm_status_bit_clear_wrapper, + ._coex_schm_status_bit_set = coex_schm_status_bit_set_wrapper, + ._coex_schm_interval_set = coex_schm_interval_set_wrapper, + ._coex_schm_interval_get = coex_schm_interval_get_wrapper, + ._coex_schm_curr_period_get = coex_schm_curr_period_get_wrapper, + ._coex_schm_curr_phase_get = coex_schm_curr_phase_get_wrapper, + ._coex_register_start_cb = coex_register_start_cb_wrapper, + ._coex_schm_process_restart = coex_schm_process_restart_wrapper, + ._coex_schm_register_cb = coex_schm_register_cb_wrapper, + ._magic = ESP_WIFI_OS_ADAPTER_MAGIC, +}; diff --git a/components/esp_wifi/include/esp_private/wifi_os_adapter.h b/components/esp_wifi/include/esp_private/wifi_os_adapter.h index 07f1194523..e5554d861c 100644 --- a/components/esp_wifi/include/esp_private/wifi_os_adapter.h +++ b/components/esp_wifi/include/esp_private/wifi_os_adapter.h @@ -81,7 +81,7 @@ typedef struct wifi_osi_funcs_t { void (* _wifi_apb80m_release)(void); void (* _phy_disable)(void); void (* _phy_enable)(void); -#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 +#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_ESP_WIFI_TARGET_ESP32 void (* _phy_common_clock_enable)(void); void (* _phy_common_clock_disable)(void); #endif @@ -113,7 +113,7 @@ typedef struct wifi_osi_funcs_t { int (* _get_random)(uint8_t *buf, size_t len); int (* _get_time)(void *t); unsigned long (* _random)(void); -#if !CONFIG_IDF_TARGET_ESP32 +#if !CONFIG_IDF_TARGET_ESP32 && !CONFIG_ESP_WIFI_TARGET_ESP32 uint32_t (* _slowclk_cal_get)(void); #endif void (* _log_write)(unsigned int level, const char* tag, const char* format, ...); diff --git a/components/esp_wifi/lib b/components/esp_wifi/lib index 4eac0d1c3d..1fbf7cd430 160000 --- a/components/esp_wifi/lib +++ b/components/esp_wifi/lib @@ -1 +1 @@ -Subproject commit 4eac0d1c3d5e0663949b5c0364e7612d423d6205 +Subproject commit 1fbf7cd43098b06be5afe9226eb483c6998d46f1 diff --git a/components/esp_wifi/src/lib_printf.c b/components/esp_wifi/src/lib_printf.c new file mode 100644 index 0000000000..3a6b8a52cb --- /dev/null +++ b/components/esp_wifi/src/lib_printf.c @@ -0,0 +1,106 @@ +/* + * SPDX-FileCopyrightText: 2016-2024 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @file lib_printf.c + * + * This file contains library-specific printf functions + * used by WiFi libraries in the `lib` directory. + * These function are used to catch any output which gets printed + * by libraries, and redirect it to ESP_LOG macros. + * + * Eventually WiFi libraries will use ESP_LOG functions internally + * and these definitions will be removed. + */ + +#include +#include +#include "esp_log.h" +#include "esp_attr.h" + +#define VPRINTF_STACK_BUFFER_SIZE 80 + +static int lib_printf(const char* tag, const char* format, va_list arg) +{ + char temp[VPRINTF_STACK_BUFFER_SIZE]; + int len = vsnprintf(temp, sizeof(temp) - 1, format, arg); + temp[sizeof(temp) - 1] = 0; + int i; + for (i = len - 1; i >= 0; --i) { + if (temp[i] != '\n' && temp[i] != '\r' && temp[i] != ' ') { + break; + } + temp[i] = 0; + } + if (i > 0) { + ESP_LOGI(tag, "%s", temp); + } + va_end(arg); + return len; +} + +int pp_printf(const char* format, ...) +{ + va_list arg; + va_start(arg, format); + int res = lib_printf("pp", format, arg); + va_end(arg); + return res; +} + +int sc_printf(const char* format, ...) +{ + va_list arg; + va_start(arg, format); + int res = lib_printf("smartconfig", format, arg); + va_end(arg); + return res; +} + +int core_printf(const char* format, ...) +{ + va_list arg; + va_start(arg, format); + int res = lib_printf("core", format, arg); + va_end(arg); + return res; +} + +int net80211_printf(const char* format, ...) +{ + va_list arg; + va_start(arg, format); + int res = lib_printf("net80211", format, arg); + va_end(arg); + return res; +} + +int target_printf(const char* format, ...) +{ + va_list arg; + va_start(arg, format); + int res = lib_printf("target", format, arg); + va_end(arg); + return res; +} + +int wapi_printf(const char* format, ...) +{ + va_list arg; + va_start(arg, format); + int res = lib_printf("wapi", format, arg); + va_end(arg); + return res; +} + +int mesh_printf(const char* format, ...) +{ + va_list arg; + va_start(arg, format); + int res = lib_printf("mesh", format, arg); + va_end(arg); + return res; +} diff --git a/components/esp_wifi/src/wifi_init.c b/components/esp_wifi/src/wifi_init.c index a92cedb885..a0c210bd30 100644 --- a/components/esp_wifi/src/wifi_init.c +++ b/components/esp_wifi/src/wifi_init.c @@ -17,7 +17,9 @@ #include "esp_private/esp_clk.h" #include "esp_wpa.h" #include "esp_netif.h" +#ifdef CONFIG_ESP_COEX_ENABLED #include "private/esp_coexist_internal.h" +#endif #ifdef CONFIG_ESP_PHY_ENABLED #include "esp_phy_init.h" #include "esp_private/phy.h" diff --git a/components/soc/esp32/include/soc/soc_caps.h b/components/soc/esp32/include/soc/soc_caps.h index a84de003fd..c10bf6fd61 100644 --- a/components/soc/esp32/include/soc/soc_caps.h +++ b/components/soc/esp32/include/soc/soc_caps.h @@ -187,7 +187,7 @@ // digital I/O pad powered by VDD3P3_CPU or VDD_SPI(GPIO_NUM: 1, 3, 5, 6, 7, 8, 9, 10, 11, 16, 17, 18, 19, 21, 22, 23) #define SOC_GPIO_VALID_DIGITAL_IO_PAD_MASK 0xEF0FEAULL -// The Clock Out singnal is binding to the pin's IO_MUX function +// The Clock Out signal is binding to the pin's IO_MUX function #define SOC_GPIO_CLOCKOUT_BY_IO_MUX (1) /*-------------------------- I2C CAPS ----------------------------------------*/ diff --git a/components/soc/esp32c2/include/soc/soc_caps.h b/components/soc/esp32c2/include/soc/soc_caps.h index ee5ff59b04..bb7c38cb3f 100644 --- a/components/soc/esp32c2/include/soc/soc_caps.h +++ b/components/soc/esp32c2/include/soc/soc_caps.h @@ -136,7 +136,7 @@ // digital I/O pad powered by VDD3P3_CPU or VDD_SPI(GPIO_NUM_6~GPIO_NUM_20) #define SOC_GPIO_VALID_DIGITAL_IO_PAD_MASK 0x00000000001FFFC0ULL -// The Clock Out singnal is route to the pin by GPIO matrix +// The Clock Out signal is route to the pin by GPIO matrix #define SOC_GPIO_CLOCKOUT_BY_GPIO_MATRIX (1) /*-------------------------- Dedicated GPIO CAPS -----------------------------*/ diff --git a/components/soc/esp32c3/include/soc/soc_caps.h b/components/soc/esp32c3/include/soc/soc_caps.h index 8d97e3ec31..f514b969f7 100644 --- a/components/soc/esp32c3/include/soc/soc_caps.h +++ b/components/soc/esp32c3/include/soc/soc_caps.h @@ -174,7 +174,7 @@ // digital I/O pad powered by VDD3P3_CPU or VDD_SPI(GPIO_NUM_6~GPIO_NUM_21) #define SOC_GPIO_VALID_DIGITAL_IO_PAD_MASK 0x00000000003FFFC0ULL -// The Clock Out singnal is route to the pin by GPIO matrix +// The Clock Out signal is route to the pin by GPIO matrix #define SOC_GPIO_CLOCKOUT_BY_GPIO_MATRIX (1) /*-------------------------- Dedicated GPIO CAPS -----------------------------*/ diff --git a/components/soc/esp32c6/include/soc/soc_caps.h b/components/soc/esp32c6/include/soc/soc_caps.h index fb5a8eda03..08b7b5f7c5 100644 --- a/components/soc/esp32c6/include/soc/soc_caps.h +++ b/components/soc/esp32c6/include/soc/soc_caps.h @@ -212,7 +212,7 @@ // Support to hold a single digital I/O when the digital domain is powered off #define SOC_GPIO_SUPPORT_HOLD_SINGLE_IO_IN_DSLP (1) -// The Clock Out singnal is route to the pin by GPIO matrix +// The Clock Out signal is route to the pin by GPIO matrix #define SOC_GPIO_CLOCKOUT_BY_GPIO_MATRIX (1) #define SOC_CLOCKOUT_HAS_SOURCE_GATE (1) @@ -511,7 +511,7 @@ #define SOC_PM_SUPPORT_BEACON_WAKEUP (1) #define SOC_PM_SUPPORT_BT_WAKEUP (1) #define SOC_PM_SUPPORT_EXT1_WAKEUP (1) -#define SOC_PM_SUPPORT_EXT1_WAKEUP_MODE_PER_PIN (1) /*! 8). + /* Authmode threshold resets to WPA2 as default if password matches WPA2 standards (password len => 8). * If you want to connect the device to deprecated WEP/WPA networks, Please set the threshold value * to WIFI_AUTH_WEP/WIFI_AUTH_WPA_PSK and set the password with length and format matching to * WIFI_AUTH_WEP/WIFI_AUTH_WPA_PSK standards.