From e4bc0e9554efdbd5bcd13b05e6ee84bac5cc461f Mon Sep 17 00:00:00 2001 From: Marius Vikhammer Date: Tue, 10 Mar 2026 10:17:50 +0800 Subject: [PATCH] fix(esp_coex): move coex init from esp_system to esp_coex component CMakev2's DEFERRED mode for idf_component_optional_requires only links optional components already present in the dependency graph. This caused esp_coex headers to be unavailable when building minimal examples on targets with both WiFi and IEEE802154 (e.g. esp32c5, esp32c6). Moving init_coexist to esp_coex removes the cross-component dependency and ensures the init function is only compiled when esp_coex itself is part of the build. A linker hook is added to guarantee the object file is not silently discarded by the linker. Made-with: Cursor --- components/esp_coex/CMakeLists.txt | 1 + components/esp_coex/src/coexist.c | 17 ++++++++++++++++- components/esp_system/CMakeLists.txt | 4 ---- components/esp_system/startup_funcs.c | 15 +-------------- components/esp_system/system_init_fn.txt | 2 +- 5 files changed, 19 insertions(+), 20 deletions(-) diff --git a/components/esp_coex/CMakeLists.txt b/components/esp_coex/CMakeLists.txt index 3160d55da2..252d3402ec 100644 --- a/components/esp_coex/CMakeLists.txt +++ b/components/esp_coex/CMakeLists.txt @@ -50,5 +50,6 @@ if(CONFIG_ESP_COEX_ENABLED) endif() target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format") + target_link_libraries(${COMPONENT_LIB} INTERFACE "-u esp_coex_init_include_func") endif() endif() diff --git a/components/esp_coex/src/coexist.c b/components/esp_coex/src/coexist.c index 1cb67c66f6..f78395f26f 100644 --- a/components/esp_coex/src/coexist.c +++ b/components/esp_coex/src/coexist.c @@ -1,11 +1,12 @@ /* - * SPDX-FileCopyrightText: 2018-2025 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2018-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ #include "esp_coexist.h" #include "private/esp_coexist_internal.h" +#include "esp_private/startup_internal.h" #include "soc/soc_caps.h" #if CONFIG_EXTERNAL_COEX_ENABLE @@ -295,3 +296,17 @@ esp_err_t esp_coex_wifi_i154_enable(void) return ESP_OK; } #endif + +#if CONFIG_ESP_COEX_SW_COEXIST_ENABLE || CONFIG_ESP_COEX_EXTERNAL_COEXIST_ENABLE +void esp_coex_init_include_func(void) +{ + // Hook to force the linker to include this file +} + +ESP_SYSTEM_INIT_FN(init_coexist, SECONDARY, BIT(0), 204) +{ + esp_coex_adapter_register(&g_coex_adapter_funcs); + coex_pre_init(); + return ESP_OK; +} +#endif // CONFIG_ESP_COEX_SW_COEXIST_ENABLE || CONFIG_ESP_COEX_EXTERNAL_COEXIST_ENABLE diff --git a/components/esp_system/CMakeLists.txt b/components/esp_system/CMakeLists.txt index 7a66992c93..5b6238c3ec 100644 --- a/components/esp_system/CMakeLists.txt +++ b/components/esp_system/CMakeLists.txt @@ -149,10 +149,6 @@ if(CONFIG_VFS_SUPPORT_IO) idf_component_optional_requires(PRIVATE vfs) endif() -if(CONFIG_SW_COEXIST_ENABLE OR CONFIG_EXTERNAL_COEX_ENABLE) - idf_component_optional_requires(PRIVATE esp_coex) -endif() - if(NOT BOOTLOADER_BUILD) if(CONFIG_SPIRAM) idf_component_optional_requires(PRIVATE esp_psram) diff --git a/components/esp_system/startup_funcs.c b/components/esp_system/startup_funcs.c index d5e6cf601b..3a4da31bd7 100644 --- a/components/esp_system/startup_funcs.c +++ b/components/esp_system/startup_funcs.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -23,10 +23,6 @@ #include "hal/uart_types.h" #include "hal/uart_ll.h" -#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE -#include "private/esp_coexist_internal.h" -#endif - #if CONFIG_PM_ENABLE || CONFIG_PM_WORKAROUND_FREQ_LIMIT_ENABLED #include "esp_pm.h" #include "esp_private/pm_impl.h" @@ -127,15 +123,6 @@ ESP_SYSTEM_INIT_FN(init_apb_dma, SECONDARY, BIT(0), 203) } #endif -#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE -ESP_SYSTEM_INIT_FN(init_coexist, SECONDARY, BIT(0), 204) -{ - esp_coex_adapter_register(&g_coex_adapter_funcs); - coex_pre_init(); - return ESP_OK; -} -#endif // CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE - #if SOC_RECOVERY_BOOTLOADER_SUPPORTED ESP_SYSTEM_INIT_FN(init_bootloader_offset, SECONDARY, BIT(0), 205) { diff --git a/components/esp_system/system_init_fn.txt b/components/esp_system/system_init_fn.txt index c4a8a0af6c..5a49ec922e 100644 --- a/components/esp_system/system_init_fn.txt +++ b/components/esp_system/system_init_fn.txt @@ -118,7 +118,7 @@ SECONDARY: 151: nvs_sec_provider_register_hmac_scheme in components/nvs_sec_prov SECONDARY: 201: init_pm in components/esp_system/startup_funcs.c on BIT(0) SECONDARY: 202: init_pm_flash_freq_limit in components/esp_pm/pm_c5_flash_freq_limit.c on BIT(0) SECONDARY: 203: init_apb_dma in components/esp_system/startup_funcs.c on BIT(0) -SECONDARY: 204: init_coexist in components/esp_system/startup_funcs.c on BIT(0) +SECONDARY: 204: init_coexist in components/esp_coex/src/coexist.c on BIT(0) SECONDARY: 205: init_bootloader_offset in components/esp_system/startup_funcs.c on BIT(0) # usb_console needs to create an esp_timer at startup.