From 4b1c666c28ef9adb5a9b5156624bccd6a3d129b6 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Tue, 4 Mar 2025 12:20:02 +1100 Subject: [PATCH 1/2] esp32: Merge the per-SoC "main" components back together. Removes redundant metadata from each, shouldn't otherwise change any build output. Reverts the split originally added in e4650125. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton --- ports/esp32/CMakeLists.txt | 3 -- ports/esp32/esp32_common.cmake | 14 ++++++- .../esp32/{main_esp32 => main}/CMakeLists.txt | 0 .../{main_esp32 => main}/idf_component.yml | 4 ++ ports/esp32/main/linker_esp32.lf | 41 +++++++++++++++++++ ports/esp32/main_esp32/linker.lf | 39 ------------------ ports/esp32/main_esp32c3/CMakeLists.txt | 14 ------- ports/esp32/main_esp32c3/idf_component.yml | 5 --- ports/esp32/main_esp32c3/linker.lf | 1 - ports/esp32/main_esp32c6/CMakeLists.txt | 14 ------- ports/esp32/main_esp32c6/idf_component.yml | 5 --- ports/esp32/main_esp32c6/linker.lf | 1 - ports/esp32/main_esp32s2/CMakeLists.txt | 13 ------ ports/esp32/main_esp32s2/idf_component.yml | 6 --- ports/esp32/main_esp32s2/linker.lf | 1 - ports/esp32/main_esp32s3/CMakeLists.txt | 13 ------ ports/esp32/main_esp32s3/idf_component.yml | 6 --- ports/esp32/main_esp32s3/linker.lf | 1 - 18 files changed, 58 insertions(+), 123 deletions(-) rename ports/esp32/{main_esp32 => main}/CMakeLists.txt (100%) rename ports/esp32/{main_esp32 => main}/idf_component.yml (52%) create mode 100644 ports/esp32/main/linker_esp32.lf delete mode 100644 ports/esp32/main_esp32/linker.lf delete mode 100644 ports/esp32/main_esp32c3/CMakeLists.txt delete mode 100644 ports/esp32/main_esp32c3/idf_component.yml delete mode 100644 ports/esp32/main_esp32c3/linker.lf delete mode 100644 ports/esp32/main_esp32c6/CMakeLists.txt delete mode 100644 ports/esp32/main_esp32c6/idf_component.yml delete mode 100644 ports/esp32/main_esp32c6/linker.lf delete mode 100644 ports/esp32/main_esp32s2/CMakeLists.txt delete mode 100644 ports/esp32/main_esp32s2/idf_component.yml delete mode 100644 ports/esp32/main_esp32s2/linker.lf delete mode 100644 ports/esp32/main_esp32s3/CMakeLists.txt delete mode 100644 ports/esp32/main_esp32s3/idf_component.yml delete mode 100644 ports/esp32/main_esp32s3/linker.lf diff --git a/ports/esp32/CMakeLists.txt b/ports/esp32/CMakeLists.txt index c3a675eb2b78f..1db374b40a431 100644 --- a/ports/esp32/CMakeLists.txt +++ b/ports/esp32/CMakeLists.txt @@ -61,8 +61,5 @@ set(SDKCONFIG_DEFAULTS ${CMAKE_BINARY_DIR}/sdkconfig.combined) # Include main IDF cmake file. include($ENV{IDF_PATH}/tools/cmake/project.cmake) -# Set the location of the main component for the project (one per target). -list(APPEND EXTRA_COMPONENT_DIRS main_${IDF_TARGET}) - # Define the project. project(micropython) diff --git a/ports/esp32/esp32_common.cmake b/ports/esp32/esp32_common.cmake index 059989c10a4db..09952363d6d50 100644 --- a/ports/esp32/esp32_common.cmake +++ b/ports/esp32/esp32_common.cmake @@ -14,6 +14,18 @@ if(NOT MICROPY_PORT_DIR) get_filename_component(MICROPY_PORT_DIR ${MICROPY_DIR}/ports/esp32 ABSOLUTE) endif() +# RISC-V specific inclusions +if(CONFIG_IDF_TARGET_ARCH_RISCV) + list(APPEND MICROPY_SOURCE_LIB ${MICROPY_DIR}/shared/runtime/gchelper_generic.c) + list(APPEND IDF_COMPONENTS riscv) +endif() + +if(NOT DEFINED MICROPY_PY_TINYUSB) + if(CONFIG_IDF_TARGET_ESP32S2 OR CONFIG_IDF_TARGET_ESP32S3) + set(MICROPY_PY_TINYUSB ON) + endif() +endif() + # Include core source components. include(${MICROPY_DIR}/py/py.cmake) @@ -182,7 +194,7 @@ list(APPEND IDF_COMPONENTS if (MICROPY_USER_LDFRAGMENTS) set(MICROPY_LDFRAGMENTS ${MICROPY_USER_LDFRAGMENTS}) else() - set(MICROPY_LDFRAGMENTS linker.lf) + set(MICROPY_LDFRAGMENTS linker_esp32.lf) endif() # Register the main IDF component. diff --git a/ports/esp32/main_esp32/CMakeLists.txt b/ports/esp32/main/CMakeLists.txt similarity index 100% rename from ports/esp32/main_esp32/CMakeLists.txt rename to ports/esp32/main/CMakeLists.txt diff --git a/ports/esp32/main_esp32/idf_component.yml b/ports/esp32/main/idf_component.yml similarity index 52% rename from ports/esp32/main_esp32/idf_component.yml rename to ports/esp32/main/idf_component.yml index 11f078f69f761..ccbde1f27e412 100644 --- a/ports/esp32/main_esp32/idf_component.yml +++ b/ports/esp32/main/idf_component.yml @@ -1,5 +1,9 @@ ## IDF Component Manager Manifest File dependencies: espressif/mdns: "~1.1.0" + espressif/esp_tinyusb: + rules: + - if: "target in [esp32s2, esp32s3]" + version: "~1.0.0" idf: version: ">=5.2.0" diff --git a/ports/esp32/main/linker_esp32.lf b/ports/esp32/main/linker_esp32.lf new file mode 100644 index 0000000000000..27e4ac2194c1b --- /dev/null +++ b/ports/esp32/main/linker_esp32.lf @@ -0,0 +1,41 @@ +# This fixes components/esp_ringbuf/linker.lf for ESP32 only to allow us to put +# non-ISR ringbuf functions in flash. + +# Requires that both RINGBUF_PLACE_FUNCTIONS_INTO_FLASH and RINGBUF_PLACE_ISR_FUNCTIONS_INTO_FLASH +# are set to "n" (which is the default), otherwise this would result in duplicate section config +# when resolving the linker fragments. + +# The effect of this file is to leave the ISR functions in RAM (which we require), but apply a fixed +# version of RINGBUF_PLACE_FUNCTIONS_INTO_FLASH=y (leaving out prvGetFreeSize and prvGetCurMaxSizeByteBuf) +# See https://github.com/espressif/esp-idf/issues/13378 + +[mapping:esp_ringbuf_fix] +archive: libesp_ringbuf.a +entries: + if IDF_TARGET_ESP32 = y: + # This is exactly the list of functions from RINGBUF_PLACE_FUNCTIONS_INTO_FLASH=y, + # but with prvGetFreeSize and prvGetCurMaxSizeByteBuf removed. + ringbuf: prvGetCurMaxSizeNoSplit (default) + ringbuf: prvGetCurMaxSizeAllowSplit (default) + ringbuf: prvInitializeNewRingbuffer (default) + ringbuf: prvReceiveGeneric (default) + ringbuf: vRingbufferDelete (default) + ringbuf: vRingbufferGetInfo (default) + ringbuf: vRingbufferReturnItem (default) + ringbuf: xRingbufferAddToQueueSetRead (default) + ringbuf: xRingbufferCanRead (default) + ringbuf: xRingbufferCreate (default) + ringbuf: xRingbufferCreateStatic (default) + ringbuf: xRingbufferCreateNoSplit (default) + ringbuf: xRingbufferReceive (default) + ringbuf: xRingbufferReceiveSplit (default) + ringbuf: xRingbufferReceiveUpTo (default) + ringbuf: xRingbufferRemoveFromQueueSetRead (default) + ringbuf: xRingbufferSend (default) + ringbuf: xRingbufferSendAcquire (default) + ringbuf: xRingbufferSendComplete (default) + ringbuf: xRingbufferPrintInfo (default) + ringbuf: xRingbufferGetMaxItemSize (default) + ringbuf: xRingbufferGetCurFreeSize (default) + + # Everything else will have the default rule already applied (i.e. noflash_text). diff --git a/ports/esp32/main_esp32/linker.lf b/ports/esp32/main_esp32/linker.lf deleted file mode 100644 index e00cd63f5548d..0000000000000 --- a/ports/esp32/main_esp32/linker.lf +++ /dev/null @@ -1,39 +0,0 @@ -# This fixes components/esp_ringbuf/linker.lf to allow us to put non-ISR ringbuf functions in flash. - -# Requires that both RINGBUF_PLACE_FUNCTIONS_INTO_FLASH and RINGBUF_PLACE_ISR_FUNCTIONS_INTO_FLASH -# are set to "n" (which is the default), otherwise this would result in duplicate section config -# when resolving the linker fragments. - -# The effect of this file is to leave the ISR functions in RAM (which we require), but apply a fixed -# version of RINGBUF_PLACE_FUNCTIONS_INTO_FLASH=y (leaving out prvGetFreeSize and prvGetCurMaxSizeByteBuf) -# See https://github.com/espressif/esp-idf/issues/13378 - -[mapping:esp_ringbuf_fix] -archive: libesp_ringbuf.a -entries: - # This is exactly the list of functions from RINGBUF_PLACE_FUNCTIONS_INTO_FLASH=y, - # but with prvGetFreeSize and prvGetCurMaxSizeByteBuf removed. - ringbuf: prvGetCurMaxSizeNoSplit (default) - ringbuf: prvGetCurMaxSizeAllowSplit (default) - ringbuf: prvInitializeNewRingbuffer (default) - ringbuf: prvReceiveGeneric (default) - ringbuf: vRingbufferDelete (default) - ringbuf: vRingbufferGetInfo (default) - ringbuf: vRingbufferReturnItem (default) - ringbuf: xRingbufferAddToQueueSetRead (default) - ringbuf: xRingbufferCanRead (default) - ringbuf: xRingbufferCreate (default) - ringbuf: xRingbufferCreateStatic (default) - ringbuf: xRingbufferCreateNoSplit (default) - ringbuf: xRingbufferReceive (default) - ringbuf: xRingbufferReceiveSplit (default) - ringbuf: xRingbufferReceiveUpTo (default) - ringbuf: xRingbufferRemoveFromQueueSetRead (default) - ringbuf: xRingbufferSend (default) - ringbuf: xRingbufferSendAcquire (default) - ringbuf: xRingbufferSendComplete (default) - ringbuf: xRingbufferPrintInfo (default) - ringbuf: xRingbufferGetMaxItemSize (default) - ringbuf: xRingbufferGetCurFreeSize (default) - - # Everything else will have the default rule already applied (i.e. noflash_text). diff --git a/ports/esp32/main_esp32c3/CMakeLists.txt b/ports/esp32/main_esp32c3/CMakeLists.txt deleted file mode 100644 index 307c0f32183a9..0000000000000 --- a/ports/esp32/main_esp32c3/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -# Set location of base MicroPython directory. -if(NOT MICROPY_DIR) - get_filename_component(MICROPY_DIR ${CMAKE_CURRENT_LIST_DIR}/../../.. ABSOLUTE) -endif() - -# Set location of the ESP32 port directory. -if(NOT MICROPY_PORT_DIR) - get_filename_component(MICROPY_PORT_DIR ${MICROPY_DIR}/ports/esp32 ABSOLUTE) -endif() - -list(APPEND MICROPY_SOURCE_LIB ${MICROPY_DIR}/shared/runtime/gchelper_generic.c) -list(APPEND IDF_COMPONENTS riscv) - -include(${MICROPY_PORT_DIR}/esp32_common.cmake) diff --git a/ports/esp32/main_esp32c3/idf_component.yml b/ports/esp32/main_esp32c3/idf_component.yml deleted file mode 100644 index 11f078f69f761..0000000000000 --- a/ports/esp32/main_esp32c3/idf_component.yml +++ /dev/null @@ -1,5 +0,0 @@ -## IDF Component Manager Manifest File -dependencies: - espressif/mdns: "~1.1.0" - idf: - version: ">=5.2.0" diff --git a/ports/esp32/main_esp32c3/linker.lf b/ports/esp32/main_esp32c3/linker.lf deleted file mode 100644 index 31c5b4563ca9a..0000000000000 --- a/ports/esp32/main_esp32c3/linker.lf +++ /dev/null @@ -1 +0,0 @@ -# Empty linker fragment (no workaround required for C3, see main_esp32/linker.lf). diff --git a/ports/esp32/main_esp32c6/CMakeLists.txt b/ports/esp32/main_esp32c6/CMakeLists.txt deleted file mode 100644 index 307c0f32183a9..0000000000000 --- a/ports/esp32/main_esp32c6/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -# Set location of base MicroPython directory. -if(NOT MICROPY_DIR) - get_filename_component(MICROPY_DIR ${CMAKE_CURRENT_LIST_DIR}/../../.. ABSOLUTE) -endif() - -# Set location of the ESP32 port directory. -if(NOT MICROPY_PORT_DIR) - get_filename_component(MICROPY_PORT_DIR ${MICROPY_DIR}/ports/esp32 ABSOLUTE) -endif() - -list(APPEND MICROPY_SOURCE_LIB ${MICROPY_DIR}/shared/runtime/gchelper_generic.c) -list(APPEND IDF_COMPONENTS riscv) - -include(${MICROPY_PORT_DIR}/esp32_common.cmake) diff --git a/ports/esp32/main_esp32c6/idf_component.yml b/ports/esp32/main_esp32c6/idf_component.yml deleted file mode 100644 index 11f078f69f761..0000000000000 --- a/ports/esp32/main_esp32c6/idf_component.yml +++ /dev/null @@ -1,5 +0,0 @@ -## IDF Component Manager Manifest File -dependencies: - espressif/mdns: "~1.1.0" - idf: - version: ">=5.2.0" diff --git a/ports/esp32/main_esp32c6/linker.lf b/ports/esp32/main_esp32c6/linker.lf deleted file mode 100644 index cedabcf979350..0000000000000 --- a/ports/esp32/main_esp32c6/linker.lf +++ /dev/null @@ -1 +0,0 @@ -# Empty linker fragment (no workaround required for C6, see main_esp32/linker.lf). diff --git a/ports/esp32/main_esp32s2/CMakeLists.txt b/ports/esp32/main_esp32s2/CMakeLists.txt deleted file mode 100644 index bc5ab939c3ce3..0000000000000 --- a/ports/esp32/main_esp32s2/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -# Set location of base MicroPython directory. -if(NOT MICROPY_DIR) - get_filename_component(MICROPY_DIR ${CMAKE_CURRENT_LIST_DIR}/../../.. ABSOLUTE) -endif() - -# Set location of the ESP32 port directory. -if(NOT MICROPY_PORT_DIR) - get_filename_component(MICROPY_PORT_DIR ${MICROPY_DIR}/ports/esp32 ABSOLUTE) -endif() - -set(MICROPY_PY_TINYUSB ON) - -include(${MICROPY_PORT_DIR}/esp32_common.cmake) diff --git a/ports/esp32/main_esp32s2/idf_component.yml b/ports/esp32/main_esp32s2/idf_component.yml deleted file mode 100644 index 2ee00b287786b..0000000000000 --- a/ports/esp32/main_esp32s2/idf_component.yml +++ /dev/null @@ -1,6 +0,0 @@ -## IDF Component Manager Manifest File -dependencies: - espressif/mdns: "~1.1.0" - espressif/esp_tinyusb: "~1.0.0" - idf: - version: ">=5.2.0" diff --git a/ports/esp32/main_esp32s2/linker.lf b/ports/esp32/main_esp32s2/linker.lf deleted file mode 100644 index 3c496fa878b3f..0000000000000 --- a/ports/esp32/main_esp32s2/linker.lf +++ /dev/null @@ -1 +0,0 @@ -# Empty linker fragment (no workaround required for S2, see main_esp32/linker.lf). diff --git a/ports/esp32/main_esp32s3/CMakeLists.txt b/ports/esp32/main_esp32s3/CMakeLists.txt deleted file mode 100644 index bc5ab939c3ce3..0000000000000 --- a/ports/esp32/main_esp32s3/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -# Set location of base MicroPython directory. -if(NOT MICROPY_DIR) - get_filename_component(MICROPY_DIR ${CMAKE_CURRENT_LIST_DIR}/../../.. ABSOLUTE) -endif() - -# Set location of the ESP32 port directory. -if(NOT MICROPY_PORT_DIR) - get_filename_component(MICROPY_PORT_DIR ${MICROPY_DIR}/ports/esp32 ABSOLUTE) -endif() - -set(MICROPY_PY_TINYUSB ON) - -include(${MICROPY_PORT_DIR}/esp32_common.cmake) diff --git a/ports/esp32/main_esp32s3/idf_component.yml b/ports/esp32/main_esp32s3/idf_component.yml deleted file mode 100644 index 2ee00b287786b..0000000000000 --- a/ports/esp32/main_esp32s3/idf_component.yml +++ /dev/null @@ -1,6 +0,0 @@ -## IDF Component Manager Manifest File -dependencies: - espressif/mdns: "~1.1.0" - espressif/esp_tinyusb: "~1.0.0" - idf: - version: ">=5.2.0" diff --git a/ports/esp32/main_esp32s3/linker.lf b/ports/esp32/main_esp32s3/linker.lf deleted file mode 100644 index 81d27906be0e4..0000000000000 --- a/ports/esp32/main_esp32s3/linker.lf +++ /dev/null @@ -1 +0,0 @@ -# Empty linker fragment (no workaround required for S3, see main_esp32/linker.lf). From 4d65b4e26119ab19de362174ec62cc3ea68a836a Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Tue, 4 Mar 2025 12:30:10 +1100 Subject: [PATCH 2/2] esp32: Remove the ESP32 ringbuffer linker workaround. Reverts workaround added in acbdbcd9. According to the linked ESP-IDF issue this was only a problem for ESP-IDF V5.0.x, and support for versions older than V5.2 was dropped in 6e5d8d009. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton --- ports/esp32/boards/sdkconfig.spiram | 2 +- ports/esp32/esp32_common.cmake | 2 -- ports/esp32/main/linker_esp32.lf | 41 ----------------------------- 3 files changed, 1 insertion(+), 44 deletions(-) delete mode 100644 ports/esp32/main/linker_esp32.lf diff --git a/ports/esp32/boards/sdkconfig.spiram b/ports/esp32/boards/sdkconfig.spiram index 35fe3c676ddf4..f5503d554149c 100644 --- a/ports/esp32/boards/sdkconfig.spiram +++ b/ports/esp32/boards/sdkconfig.spiram @@ -13,6 +13,6 @@ CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL=8192 # to PSRAM bug workarounds. Apply some options to reduce the firmware size. CONFIG_COMPILER_OPTIMIZATION_SIZE=y CONFIG_COMPILER_OPTIMIZATION_CHECKS_SILENT=y -# CONFIG_RINGBUF_PLACE_FUNCTIONS_INTO_FLASH=y # Workaround required: see main_esp32/linker.lf +CONFIG_RINGBUF_PLACE_FUNCTIONS_INTO_FLASH=y CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH=y CONFIG_FREERTOS_PLACE_SNAPSHOT_FUNS_INTO_FLASH=y diff --git a/ports/esp32/esp32_common.cmake b/ports/esp32/esp32_common.cmake index 09952363d6d50..6473f04a53500 100644 --- a/ports/esp32/esp32_common.cmake +++ b/ports/esp32/esp32_common.cmake @@ -193,8 +193,6 @@ list(APPEND IDF_COMPONENTS # Provide the default LD fragment if not set if (MICROPY_USER_LDFRAGMENTS) set(MICROPY_LDFRAGMENTS ${MICROPY_USER_LDFRAGMENTS}) -else() - set(MICROPY_LDFRAGMENTS linker_esp32.lf) endif() # Register the main IDF component. diff --git a/ports/esp32/main/linker_esp32.lf b/ports/esp32/main/linker_esp32.lf deleted file mode 100644 index 27e4ac2194c1b..0000000000000 --- a/ports/esp32/main/linker_esp32.lf +++ /dev/null @@ -1,41 +0,0 @@ -# This fixes components/esp_ringbuf/linker.lf for ESP32 only to allow us to put -# non-ISR ringbuf functions in flash. - -# Requires that both RINGBUF_PLACE_FUNCTIONS_INTO_FLASH and RINGBUF_PLACE_ISR_FUNCTIONS_INTO_FLASH -# are set to "n" (which is the default), otherwise this would result in duplicate section config -# when resolving the linker fragments. - -# The effect of this file is to leave the ISR functions in RAM (which we require), but apply a fixed -# version of RINGBUF_PLACE_FUNCTIONS_INTO_FLASH=y (leaving out prvGetFreeSize and prvGetCurMaxSizeByteBuf) -# See https://github.com/espressif/esp-idf/issues/13378 - -[mapping:esp_ringbuf_fix] -archive: libesp_ringbuf.a -entries: - if IDF_TARGET_ESP32 = y: - # This is exactly the list of functions from RINGBUF_PLACE_FUNCTIONS_INTO_FLASH=y, - # but with prvGetFreeSize and prvGetCurMaxSizeByteBuf removed. - ringbuf: prvGetCurMaxSizeNoSplit (default) - ringbuf: prvGetCurMaxSizeAllowSplit (default) - ringbuf: prvInitializeNewRingbuffer (default) - ringbuf: prvReceiveGeneric (default) - ringbuf: vRingbufferDelete (default) - ringbuf: vRingbufferGetInfo (default) - ringbuf: vRingbufferReturnItem (default) - ringbuf: xRingbufferAddToQueueSetRead (default) - ringbuf: xRingbufferCanRead (default) - ringbuf: xRingbufferCreate (default) - ringbuf: xRingbufferCreateStatic (default) - ringbuf: xRingbufferCreateNoSplit (default) - ringbuf: xRingbufferReceive (default) - ringbuf: xRingbufferReceiveSplit (default) - ringbuf: xRingbufferReceiveUpTo (default) - ringbuf: xRingbufferRemoveFromQueueSetRead (default) - ringbuf: xRingbufferSend (default) - ringbuf: xRingbufferSendAcquire (default) - ringbuf: xRingbufferSendComplete (default) - ringbuf: xRingbufferPrintInfo (default) - ringbuf: xRingbufferGetMaxItemSize (default) - ringbuf: xRingbufferGetCurFreeSize (default) - - # Everything else will have the default rule already applied (i.e. noflash_text).