From acbdbcd95e6d953b08f0642a844c1808323e0b7c Mon Sep 17 00:00:00 2001 From: Jim Mussared Date: Thu, 21 Mar 2024 15:46:41 +1100 Subject: [PATCH] esp32: Workaround IDF issue placing ISR ringbuf functions in IRAM. This workaround makes sure that all ringbuf functions that may be called from an ISR are placed in IRAM. See https://github.com/espressif/esp-idf/issues/13378 Note that this means that all esp32-og builds get non-ISR ringbuf functions placed in flash now, whereas previously it was just the spiram variant. This might be a good thing (e.g. free up some IRAM for native/viper). Fixes issue #14005. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared --- ports/esp32/boards/sdkconfig.spiram | 2 +- ports/esp32/esp32_common.cmake | 2 ++ ports/esp32/main_esp32/linker.lf | 39 +++++++++++++++++++++++++++++ ports/esp32/main_esp32c3/linker.lf | 1 + ports/esp32/main_esp32s2/linker.lf | 1 + ports/esp32/main_esp32s3/linker.lf | 1 + 6 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 ports/esp32/main_esp32/linker.lf create mode 100644 ports/esp32/main_esp32c3/linker.lf create mode 100644 ports/esp32/main_esp32s2/linker.lf create mode 100644 ports/esp32/main_esp32s3/linker.lf diff --git a/ports/esp32/boards/sdkconfig.spiram b/ports/esp32/boards/sdkconfig.spiram index f5503d5541..35fe3c676d 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 +# CONFIG_RINGBUF_PLACE_FUNCTIONS_INTO_FLASH=y # Workaround required: see main_esp32/linker.lf 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 a3637870f4..89e46f9cfb 100644 --- a/ports/esp32/esp32_common.cmake +++ b/ports/esp32/esp32_common.cmake @@ -151,6 +151,8 @@ idf_component_register( ${MICROPY_PORT_DIR} ${MICROPY_BOARD_DIR} ${CMAKE_BINARY_DIR} + LDFRAGMENTS + linker.lf REQUIRES ${IDF_COMPONENTS} ) diff --git a/ports/esp32/main_esp32/linker.lf b/ports/esp32/main_esp32/linker.lf new file mode 100644 index 0000000000..e00cd63f55 --- /dev/null +++ b/ports/esp32/main_esp32/linker.lf @@ -0,0 +1,39 @@ +# 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/linker.lf b/ports/esp32/main_esp32c3/linker.lf new file mode 100644 index 0000000000..31c5b4563c --- /dev/null +++ b/ports/esp32/main_esp32c3/linker.lf @@ -0,0 +1 @@ +# Empty linker fragment (no workaround required for C3, see main_esp32/linker.lf). diff --git a/ports/esp32/main_esp32s2/linker.lf b/ports/esp32/main_esp32s2/linker.lf new file mode 100644 index 0000000000..3c496fa878 --- /dev/null +++ b/ports/esp32/main_esp32s2/linker.lf @@ -0,0 +1 @@ +# Empty linker fragment (no workaround required for S2, see main_esp32/linker.lf). diff --git a/ports/esp32/main_esp32s3/linker.lf b/ports/esp32/main_esp32s3/linker.lf new file mode 100644 index 0000000000..81d27906be --- /dev/null +++ b/ports/esp32/main_esp32s3/linker.lf @@ -0,0 +1 @@ +# Empty linker fragment (no workaround required for S3, see main_esp32/linker.lf).