This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 8c23a9eb02e8925c1f8672188268a47f6ea205b0
Author: Arjav Patel <[email protected]>
AuthorDate: Fri May 1 02:19:01 2026 +0530

    arch/xtensa/espressif: Add CMake support for ESP32 Xtensa chips.
    
    Add a shared Espressif Xtensa CMake layer and chip-level CMake entry points
    for ESP32, ESP32-S2, and ESP32-S3 to mirror existing Make-based bring-up.
    This enables CMake builds to resolve common Espressif arch and HAL wiring.
    
    Signed-off-by: Arjav Patel <[email protected]>
---
 arch/xtensa/src/common/espressif/CMakeLists.txt    | 137 +++++++++++++++++++++
 .../common/espressif/hal_xtensa_espressif.cmake    |  96 +++++++++++++++
 arch/xtensa/src/esp32/CMakeLists.txt               |  44 +++++++
 arch/xtensa/src/esp32/hal_esp32.cmake              |   8 ++
 arch/xtensa/src/esp32s2/CMakeLists.txt             |  34 +++++
 arch/xtensa/src/esp32s2/hal_esp32s2.cmake          |   8 ++
 arch/xtensa/src/esp32s3/CMakeLists.txt             |  43 +++++++
 arch/xtensa/src/esp32s3/hal_esp32s3.cmake          |   8 ++
 8 files changed, 378 insertions(+)

diff --git a/arch/xtensa/src/common/espressif/CMakeLists.txt 
b/arch/xtensa/src/common/espressif/CMakeLists.txt
new file mode 100644
index 00000000000..48762d1a824
--- /dev/null
+++ b/arch/xtensa/src/common/espressif/CMakeLists.txt
@@ -0,0 +1,137 @@
+# 
##############################################################################
+# arch/xtensa/src/common/espressif/CMakeLists.txt
+#
+# SPDX-License-Identifier: Apache-2.0
+# 
##############################################################################
+
+set(SRCS)
+
+if(CONFIG_ESP_RMT)
+  list(APPEND SRCS esp_rmt.c)
+  if(CONFIG_DRIVERS_RC)
+    list(APPEND SRCS esp_lirc.c)
+  endif()
+  if(CONFIG_WS2812_NON_SPI_DRIVER)
+    list(APPEND SRCS esp_ws2812.c)
+  endif()
+endif()
+
+if(CONFIG_ESP_MCPWM)
+  list(APPEND SRCS esp_mcpwm.c)
+endif()
+
+if(CONFIG_ESPRESSIF_SIMPLE_BOOT
+   OR CONFIG_ESP32_APP_FORMAT_MCUBOOT
+   OR CONFIG_ESP32S2_APP_FORMAT_MCUBOOT
+   OR CONFIG_ESP32S3_APP_FORMAT_MCUBOOT)
+  list(APPEND SRCS esp_loader.c)
+endif()
+
+if(CONFIG_ESPRESSIF_TEMP)
+  list(APPEND SRCS esp_temperature_sensor.c)
+endif()
+
+if(CONFIG_ESP_SDM)
+  list(APPEND SRCS esp_sdm.c)
+endif()
+
+if(CONFIG_ESPRESSIF_I2S)
+  list(APPEND SRCS esp_i2s.c)
+endif()
+
+if(CONFIG_ESPRESSIF_I2C_BITBANG)
+  list(APPEND SRCS esp_i2c_bitbang.c)
+endif()
+
+if(CONFIG_ESPRESSIF_SPI_BITBANG)
+  list(APPEND SRCS esp_spi_bitbang.c)
+endif()
+
+if(CONFIG_ESP_PCNT)
+  list(APPEND SRCS esp_pcnt.c)
+  if(CONFIG_ESP_PCNT_AS_QE)
+    list(APPEND SRCS esp_qencoder.c)
+  endif()
+endif()
+
+if(CONFIG_ESPRESSIF_LEDC)
+  list(APPEND SRCS esp_ledc.c)
+endif()
+
+if(CONFIG_ESPRESSIF_SPIFLASH)
+  list(APPEND SRCS esp_spiflash.c)
+  if(CONFIG_ESPRESSIF_MTD)
+    list(APPEND SRCS esp_spiflash_mtd.c)
+  endif()
+endif()
+
+if(CONFIG_ESPRESSIF_I2C_PERIPH_SLAVE_MODE)
+  list(APPEND SRCS esp_i2c_slave.c)
+endif()
+
+if(CONFIG_ESPRESSIF_DEDICATED_GPIO)
+  list(APPEND SRCS esp_dedic_gpio.c)
+endif()
+
+if(CONFIG_ESPRESSIF_SHA_ACCELERATOR)
+  list(APPEND SRCS esp_sha.c)
+endif()
+
+if(CONFIG_ESPRESSIF_AES_ACCELERATOR)
+  list(APPEND SRCS esp_aes.c)
+endif()
+
+if(NOT CONFIG_ARCH_CHIP_ESP32 AND CONFIG_CRYPTO_CRYPTODEV_HARDWARE)
+  list(APPEND SRCS esp_crypto.c)
+endif()
+
+if(CONFIG_ESPRESSIF_USE_ULP_RISCV_CORE)
+  list(APPEND SRCS esp_ulp.c)
+endif()
+
+if(CONFIG_SYSTEM_NXDIAG_ESPRESSIF_CHIP_WO_TOOL)
+  list(APPEND SRCS esp_nxdiag.c)
+endif()
+
+if(CONFIG_ESPRESSIF_WIRELESS)
+  list(APPEND SRCS esp_wireless.c esp_wifi_utils.c)
+  if(CONFIG_ESPRESSIF_WIFI)
+    list(APPEND SRCS esp_wifi_event_handler.c esp_wlan_netdev.c esp_wifi_api.c)
+  endif()
+  if(CONFIG_ESPRESSIF_ESPNOW_PKTRADIO)
+    list(APPEND SRCS esp_espnow_pktradio.c)
+  endif()
+endif()
+
+if(CONFIG_ESPRESSIF_ADC)
+  list(APPEND SRCS esp_adc.c)
+endif()
+
+if(CONFIG_PM)
+  if(NOT CONFIG_ARCH_CUSTOM_PMINIT)
+    list(APPEND SRCS esp_pm_initialize.c)
+  endif()
+  list(APPEND SRCS esp_pm.c)
+endif()
+
+list(APPEND SRCS esp_efuse.c esp_irq.c esp_xtensa_intr.c esp_gpio.c)
+
+if(CONFIG_RTC_DRIVER)
+  list(APPEND SRCS esp_rtc.c)
+endif()
+
+if(CONFIG_ESPRESSIF_HR_TIMER)
+  list(APPEND SRCS esp_timer_adapter.c)
+endif()
+
+target_compile_options(arch PRIVATE -Wno-shadow -Wno-undef)
+target_link_options(nuttx PRIVATE "SHELL:-u esp_system_include_startup_funcs"
+                    "SHELL:-u esp_timer_init_include_func")
+
+if(CONFIG_ESPRESSIF_EFUSE)
+  target_link_options(nuttx PRIVATE "SHELL:-u esp_efuse_startup_include_func")
+endif()
+
+target_include_directories(arch
+                           PRIVATE 
${CMAKE_CURRENT_SOURCE_DIR}/platform_include)
+target_sources(arch PRIVATE ${SRCS})
diff --git a/arch/xtensa/src/common/espressif/hal_xtensa_espressif.cmake 
b/arch/xtensa/src/common/espressif/hal_xtensa_espressif.cmake
new file mode 100644
index 00000000000..7f566f64a5d
--- /dev/null
+++ b/arch/xtensa/src/common/espressif/hal_xtensa_espressif.cmake
@@ -0,0 +1,96 @@
+# 
##############################################################################
+# arch/xtensa/src/common/espressif/hal_xtensa_espressif.cmake
+#
+# SPDX-License-Identifier: Apache-2.0
+# 
##############################################################################
+
+if(NOT EXISTS ${ESP_HAL_3RDPARTY_REPO})
+  message(
+    FATAL_ERROR
+      "ESP_HAL_3RDPARTY_REPO does not exist: ${ESP_HAL_3RDPARTY_REPO}. Please 
ensure the HAL 3rd party repository is cloned correctly."
+  )
+endif()
+
+target_include_directories(
+  arch
+  PRIVATE
+    ${ESP_HAL_3RDPARTY_REPO}/nuttx/include
+    ${ESP_HAL_3RDPARTY_REPO}/nuttx/include/mbedtls
+    ${ESP_HAL_3RDPARTY_REPO}/nuttx/${CHIP_SERIES}/include
+    ${ESP_HAL_3RDPARTY_REPO}/components/bootloader_support/include
+    ${ESP_HAL_3RDPARTY_REPO}/components/bootloader_support/private_include
+    
${ESP_HAL_3RDPARTY_REPO}/components/bootloader_support/bootloader_flash/include
+    ${ESP_HAL_3RDPARTY_REPO}/components/efuse/include
+    ${ESP_HAL_3RDPARTY_REPO}/components/efuse/private_include
+    ${ESP_HAL_3RDPARTY_REPO}/components/efuse/${CHIP_SERIES}/include
+    ${ESP_HAL_3RDPARTY_REPO}/components/esp_common/include
+    ${ESP_HAL_3RDPARTY_REPO}/components/esp_event/include
+    ${ESP_HAL_3RDPARTY_REPO}/components/esp_adc/include
+    ${ESP_HAL_3RDPARTY_REPO}/components/esp_adc/interface
+    ${ESP_HAL_3RDPARTY_REPO}/components/esp_hw_support/include
+    ${ESP_HAL_3RDPARTY_REPO}/components/esp_hw_support/include/esp_private
+    ${ESP_HAL_3RDPARTY_REPO}/components/esp_hw_support/include/soc
+    
${ESP_HAL_3RDPARTY_REPO}/components/esp_hw_support/include/soc/${CHIP_SERIES}
+    ${ESP_HAL_3RDPARTY_REPO}/components/esp_mm/include
+    ${ESP_HAL_3RDPARTY_REPO}/components/esp_phy/include
+    ${ESP_HAL_3RDPARTY_REPO}/components/esp_phy/${CHIP_SERIES}/include
+    ${ESP_HAL_3RDPARTY_REPO}/components/esp_pm/include
+    ${ESP_HAL_3RDPARTY_REPO}/components/esp_rom/include
+    ${ESP_HAL_3RDPARTY_REPO}/components/esp_rom/${CHIP_SERIES}
+    ${ESP_HAL_3RDPARTY_REPO}/components/esp_rom/${CHIP_SERIES}/include
+    ${ESP_HAL_3RDPARTY_REPO}/components/esp_system/include
+    ${ESP_HAL_3RDPARTY_REPO}/components/esp_system/port/include
+    ${ESP_HAL_3RDPARTY_REPO}/components/esp_timer/include
+    ${ESP_HAL_3RDPARTY_REPO}/components/esp_timer/private_include
+    ${ESP_HAL_3RDPARTY_REPO}/components/hal/include
+    ${ESP_HAL_3RDPARTY_REPO}/components/hal/${CHIP_SERIES}/include
+    ${ESP_HAL_3RDPARTY_REPO}/components/log/include
+    ${ESP_HAL_3RDPARTY_REPO}/components/mbedtls/port/include
+    ${ESP_HAL_3RDPARTY_REPO}/components/mbedtls/mbedtls/include
+    ${ESP_HAL_3RDPARTY_REPO}/components/soc/include
+    ${ESP_HAL_3RDPARTY_REPO}/components/soc/${CHIP_SERIES}/include
+    ${ESP_HAL_3RDPARTY_REPO}/components/soc/${CHIP_SERIES}/register
+    ${ESP_HAL_3RDPARTY_REPO}/components/spi_flash/include
+    ${ESP_HAL_3RDPARTY_REPO}/components/spi_flash/include/esp_flash_chips
+    ${ESP_HAL_3RDPARTY_REPO}/components/xtensa/include
+    ${ESP_HAL_3RDPARTY_REPO}/components/xtensa/${CHIP_SERIES}/include
+    ${ESP_HAL_3RDPARTY_REPO}/components/upper_hal_gpio/include
+    ${ESP_HAL_3RDPARTY_REPO}/components/upper_hal_rmt/include
+    ${ESP_HAL_3RDPARTY_REPO}/components/upper_hal_rmt/src
+    ${ESP_HAL_3RDPARTY_REPO}/nuttx/src/components/esp_libc/platform_include)
+
+set(ESP_ROM_LD_DIR
+    ${ESP_HAL_3RDPARTY_REPO}/components/esp_rom/${CHIP_SERIES}/ld)
+set(ESP_SOC_LD_DIR ${ESP_HAL_3RDPARTY_REPO}/components/soc/${CHIP_SERIES}/ld)
+set_property(
+  GLOBAL APPEND
+  PROPERTY LD_SCRIPT ${ESP_ROM_LD_DIR}/${CHIP_SERIES}.rom.api.ld
+           ${ESP_ROM_LD_DIR}/${CHIP_SERIES}.rom.ld
+           ${ESP_SOC_LD_DIR}/${CHIP_SERIES}.peripherals.ld)
+
+set(HAL_SRCS)
+list(
+  APPEND
+  HAL_SRCS
+  ${ESP_HAL_3RDPARTY_REPO}/components/esp_common/src/esp_err_to_name.c
+  ${ESP_HAL_3RDPARTY_REPO}/components/esp_system/esp_system.c
+  ${ESP_HAL_3RDPARTY_REPO}/components/esp_system/esp_err.c
+  ${ESP_HAL_3RDPARTY_REPO}/components/esp_system/startup.c
+  ${ESP_HAL_3RDPARTY_REPO}/components/esp_system/startup_funcs.c
+  ${ESP_HAL_3RDPARTY_REPO}/components/esp_timer/src/esp_timer.c
+  ${ESP_HAL_3RDPARTY_REPO}/components/esp_timer/src/esp_timer_impl_common.c
+  ${ESP_HAL_3RDPARTY_REPO}/components/efuse/src/esp_efuse_api.c
+  ${ESP_HAL_3RDPARTY_REPO}/components/efuse/src/esp_efuse_utility.c
+  ${ESP_HAL_3RDPARTY_REPO}/components/efuse/${CHIP_SERIES}/esp_efuse_fields.c
+  ${ESP_HAL_3RDPARTY_REPO}/components/bootloader_support/src/flash_encrypt.c
+  
${ESP_HAL_3RDPARTY_REPO}/components/bootloader_support/bootloader_flash/src/bootloader_flash.c
+  ${ESP_HAL_3RDPARTY_REPO}/components/esp_rom/patches/esp_rom_sys.c
+  ${ESP_HAL_3RDPARTY_REPO}/components/esp_rom/patches/esp_rom_print.c
+  ${ESP_HAL_3RDPARTY_REPO}/components/spi_flash/esp_flash_api.c
+  ${ESP_HAL_3RDPARTY_REPO}/components/spi_flash/spi_flash_wrap.c
+  ${ESP_HAL_3RDPARTY_REPO}/components/log/src/log.c
+  ${ESP_HAL_3RDPARTY_REPO}/components/upper_hal_gpio/src/gpio.c
+  ${ESP_HAL_3RDPARTY_REPO}/nuttx/src/platform/os.c
+  ${ESP_HAL_3RDPARTY_REPO}/nuttx/src/heap_caps.c)
+
+target_sources(arch PRIVATE ${HAL_SRCS})
diff --git a/arch/xtensa/src/esp32/CMakeLists.txt 
b/arch/xtensa/src/esp32/CMakeLists.txt
new file mode 100644
index 00000000000..98d28fb1f2e
--- /dev/null
+++ b/arch/xtensa/src/esp32/CMakeLists.txt
@@ -0,0 +1,44 @@
+# 
##############################################################################
+# arch/xtensa/src/esp32/CMakeLists.txt
+#
+# SPDX-License-Identifier: Apache-2.0
+# 
##############################################################################
+
+add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../common/espressif espressif)
+
+set(SRCS
+    esp32_start.c
+    esp32_wdt.c
+    esp32_allocateheap.c
+    esp32_systemreset.c
+    esp32_resetcause.c
+    esp32_region.c
+    esp32_rtc_gpio.c
+    esp32_user.c
+    esp32_libc_stubs.c
+    esp32_dma.c)
+
+if(NOT CONFIG_ARCH_IDLE_CUSTOM)
+  list(APPEND SRCS esp32_idle.c)
+endif()
+
+if(CONFIG_SCHED_TICKLESS)
+  list(APPEND SRCS esp32_tickless.c)
+else()
+  list(APPEND SRCS esp32_timerisr.c)
+endif()
+
+if(CONFIG_ESPRESSIF_WIFI)
+  list(APPEND SRCS esp32_wifi_adapter.c)
+endif()
+
+if(CONFIG_ESPRESSIF_BLE)
+  list(APPEND SRCS esp32_ble_adapter.c esp32_ble.c)
+endif()
+
+if(CONFIG_XTENSA_HAVE_WINDOW_EXCEPTION_HOOKS)
+  list(APPEND SRCS esp32_window_hooks.S)
+endif()
+
+target_compile_definitions(arch PRIVATE ESP_PLATFORM=1)
+target_sources(arch PRIVATE ${SRCS})
diff --git a/arch/xtensa/src/esp32/hal_esp32.cmake 
b/arch/xtensa/src/esp32/hal_esp32.cmake
new file mode 100644
index 00000000000..5b4e8fe4023
--- /dev/null
+++ b/arch/xtensa/src/esp32/hal_esp32.cmake
@@ -0,0 +1,8 @@
+# 
##############################################################################
+# arch/xtensa/src/esp32/hal_esp32.cmake
+#
+# SPDX-License-Identifier: Apache-2.0
+# 
##############################################################################
+
+set(CHIP_SERIES esp32)
+include(${NUTTX_ARCH_ABS_DIR}/src/common/espressif/hal_xtensa_espressif.cmake)
diff --git a/arch/xtensa/src/esp32s2/CMakeLists.txt 
b/arch/xtensa/src/esp32s2/CMakeLists.txt
new file mode 100644
index 00000000000..d05d1e962f0
--- /dev/null
+++ b/arch/xtensa/src/esp32s2/CMakeLists.txt
@@ -0,0 +1,34 @@
+# 
##############################################################################
+# arch/xtensa/src/esp32s2/CMakeLists.txt
+#
+# SPDX-License-Identifier: Apache-2.0
+# 
##############################################################################
+
+add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../common/espressif espressif)
+
+set(SRCS
+    esp32s2_start.c
+    esp32s2_wdt.c
+    esp32s2_allocateheap.c
+    esp32s2_rtc_gpio.c
+    esp32s2_region.c
+    esp32s2_user.c
+    esp32s2_lowputc.c
+    esp32s2_systemreset.c
+    esp32s2_dma.c
+    esp32s2_libc_stubs.c)
+
+if(NOT CONFIG_ARCH_IDLE_CUSTOM)
+  list(APPEND SRCS esp32s2_idle.c)
+endif()
+
+if(NOT CONFIG_SCHED_TICKLESS)
+  list(APPEND SRCS esp32s2_timerisr.c)
+endif()
+
+if(CONFIG_ESPRESSIF_WIFI)
+  list(APPEND SRCS esp32s2_wifi_adapter.c)
+endif()
+
+target_compile_definitions(arch PRIVATE ESP_PLATFORM=1)
+target_sources(arch PRIVATE ${SRCS})
diff --git a/arch/xtensa/src/esp32s2/hal_esp32s2.cmake 
b/arch/xtensa/src/esp32s2/hal_esp32s2.cmake
new file mode 100644
index 00000000000..acc03f247e5
--- /dev/null
+++ b/arch/xtensa/src/esp32s2/hal_esp32s2.cmake
@@ -0,0 +1,8 @@
+# 
##############################################################################
+# arch/xtensa/src/esp32s2/hal_esp32s2.cmake
+#
+# SPDX-License-Identifier: Apache-2.0
+# 
##############################################################################
+
+set(CHIP_SERIES esp32s2)
+include(${NUTTX_ARCH_ABS_DIR}/src/common/espressif/hal_xtensa_espressif.cmake)
diff --git a/arch/xtensa/src/esp32s3/CMakeLists.txt 
b/arch/xtensa/src/esp32s3/CMakeLists.txt
new file mode 100644
index 00000000000..6f1a3d75666
--- /dev/null
+++ b/arch/xtensa/src/esp32s3/CMakeLists.txt
@@ -0,0 +1,43 @@
+# 
##############################################################################
+# arch/xtensa/src/esp32s3/CMakeLists.txt
+#
+# SPDX-License-Identifier: Apache-2.0
+# 
##############################################################################
+
+add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../common/espressif espressif)
+
+set(SRCS
+    esp32s3_start.c
+    esp32s3_cache.c
+    esp32s3_region.c
+    esp32s3_systemreset.c
+    esp32s3_user.c
+    esp32s3_allocateheap.c
+    esp32s3_reset_reasons.c
+    esp32s3_wdt.c
+    esp32s3_lowputc.c
+    esp32s3_serial.c
+    esp32s3_rtc_gpio.c
+    esp32s3_libc_stubs.c
+    esp32s3_spi_timing.c)
+
+if(NOT CONFIG_ARCH_IDLE_CUSTOM)
+  list(APPEND SRCS esp32s3_idle.c)
+endif()
+
+if(CONFIG_SCHED_TICKLESS)
+  list(APPEND SRCS esp32s3_tickless.c)
+else()
+  list(APPEND SRCS esp32s3_timerisr.c)
+endif()
+
+if(CONFIG_ESPRESSIF_WIFI)
+  list(APPEND SRCS esp32s3_wifi_adapter.c)
+endif()
+
+if(CONFIG_ESPRESSIF_BLE)
+  list(APPEND SRCS esp32s3_ble_adapter.c esp32s3_ble.c)
+endif()
+
+target_compile_definitions(arch PRIVATE _RETARGETABLE_LOCKING ESP_PLATFORM=1)
+target_sources(arch PRIVATE ${SRCS})
diff --git a/arch/xtensa/src/esp32s3/hal_esp32s3.cmake 
b/arch/xtensa/src/esp32s3/hal_esp32s3.cmake
new file mode 100644
index 00000000000..85cf461841d
--- /dev/null
+++ b/arch/xtensa/src/esp32s3/hal_esp32s3.cmake
@@ -0,0 +1,8 @@
+# 
##############################################################################
+# arch/xtensa/src/esp32s3/hal_esp32s3.cmake
+#
+# SPDX-License-Identifier: Apache-2.0
+# 
##############################################################################
+
+set(CHIP_SERIES esp32s3)
+include(${NUTTX_ARCH_ABS_DIR}/src/common/espressif/hal_xtensa_espressif.cmake)

Reply via email to