Skip to content

Commit acbdbcd

Browse files
jimmodpgeorge
authored andcommitted
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 espressif/esp-idf#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 micropython#14005. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <[email protected]>
1 parent 71044a4 commit acbdbcd

File tree

6 files changed

+45
-1
lines changed

6 files changed

+45
-1
lines changed

ports/esp32/boards/sdkconfig.spiram

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL=8192
1313
# to PSRAM bug workarounds. Apply some options to reduce the firmware size.
1414
CONFIG_COMPILER_OPTIMIZATION_SIZE=y
1515
CONFIG_COMPILER_OPTIMIZATION_CHECKS_SILENT=y
16-
CONFIG_RINGBUF_PLACE_FUNCTIONS_INTO_FLASH=y
16+
# CONFIG_RINGBUF_PLACE_FUNCTIONS_INTO_FLASH=y # Workaround required: see main_esp32/linker.lf
1717
CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH=y
1818
CONFIG_FREERTOS_PLACE_SNAPSHOT_FUNS_INTO_FLASH=y

ports/esp32/esp32_common.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ idf_component_register(
151151
${MICROPY_PORT_DIR}
152152
${MICROPY_BOARD_DIR}
153153
${CMAKE_BINARY_DIR}
154+
LDFRAGMENTS
155+
linker.lf
154156
REQUIRES
155157
${IDF_COMPONENTS}
156158
)

ports/esp32/main_esp32/linker.lf

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# This fixes components/esp_ringbuf/linker.lf to allow us to put non-ISR ringbuf functions in flash.
2+
3+
# Requires that both RINGBUF_PLACE_FUNCTIONS_INTO_FLASH and RINGBUF_PLACE_ISR_FUNCTIONS_INTO_FLASH
4+
# are set to "n" (which is the default), otherwise this would result in duplicate section config
5+
# when resolving the linker fragments.
6+
7+
# The effect of this file is to leave the ISR functions in RAM (which we require), but apply a fixed
8+
# version of RINGBUF_PLACE_FUNCTIONS_INTO_FLASH=y (leaving out prvGetFreeSize and prvGetCurMaxSizeByteBuf)
9+
# See https://github.com/espressif/esp-idf/issues/13378
10+
11+
[mapping:esp_ringbuf_fix]
12+
archive: libesp_ringbuf.a
13+
entries:
14+
# This is exactly the list of functions from RINGBUF_PLACE_FUNCTIONS_INTO_FLASH=y,
15+
# but with prvGetFreeSize and prvGetCurMaxSizeByteBuf removed.
16+
ringbuf: prvGetCurMaxSizeNoSplit (default)
17+
ringbuf: prvGetCurMaxSizeAllowSplit (default)
18+
ringbuf: prvInitializeNewRingbuffer (default)
19+
ringbuf: prvReceiveGeneric (default)
20+
ringbuf: vRingbufferDelete (default)
21+
ringbuf: vRingbufferGetInfo (default)
22+
ringbuf: vRingbufferReturnItem (default)
23+
ringbuf: xRingbufferAddToQueueSetRead (default)
24+
ringbuf: xRingbufferCanRead (default)
25+
ringbuf: xRingbufferCreate (default)
26+
ringbuf: xRingbufferCreateStatic (default)
27+
ringbuf: xRingbufferCreateNoSplit (default)
28+
ringbuf: xRingbufferReceive (default)
29+
ringbuf: xRingbufferReceiveSplit (default)
30+
ringbuf: xRingbufferReceiveUpTo (default)
31+
ringbuf: xRingbufferRemoveFromQueueSetRead (default)
32+
ringbuf: xRingbufferSend (default)
33+
ringbuf: xRingbufferSendAcquire (default)
34+
ringbuf: xRingbufferSendComplete (default)
35+
ringbuf: xRingbufferPrintInfo (default)
36+
ringbuf: xRingbufferGetMaxItemSize (default)
37+
ringbuf: xRingbufferGetCurFreeSize (default)
38+
39+
# Everything else will have the default rule already applied (i.e. noflash_text).

ports/esp32/main_esp32c3/linker.lf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Empty linker fragment (no workaround required for C3, see main_esp32/linker.lf).

ports/esp32/main_esp32s2/linker.lf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Empty linker fragment (no workaround required for S2, see main_esp32/linker.lf).

ports/esp32/main_esp32s3/linker.lf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Empty linker fragment (no workaround required for S3, see main_esp32/linker.lf).

0 commit comments

Comments
 (0)