arch/xtensa/esp32[|s3]: Fix ROM strdup heap issue in USER_HEAP mode #18728
Merged
jerpelea merged 3 commits intoapache:masterfrom Apr 14, 2026
Merged
arch/xtensa/esp32[|s3]: Fix ROM strdup heap issue in USER_HEAP mode #18728jerpelea merged 3 commits intoapache:masterfrom
jerpelea merged 3 commits intoapache:masterfrom
Conversation
In ESP32-S3 flat build with USER_HEAP mode, ROM strdup internally calls malloc which may be mapped to a different heap than lib_free, causing cross-heap allocation issues and system crashes. This commit adds a new Kconfig option ESP32S3_DONT_USE_ROM_LIBC to allow using NuttX libc instead of ROM newlib functions. When USER_HEAP mode is selected, this option is automatically enabled. Fixes: 60ca804 ("esp32s3: Fix bug related to the PSRAM-allocated task stack") Signed-off-by: 461911662 <461911662@qq.com> Reviewed-by: Tiago Medicci Serrano <tiago.medicci@espressif.com> Reviewed-by: Almir Okato <almir.okato@espressif.com> Reviewed-by: Eren Terzioglu <eren.terzioglu@espressif.com>
When ESP32's flat build mode is selected with the external PSRAM on USER_HEAP mode, the ROM strdup internally calls malloc which may be mapped to a different heap than lib_free, causing cross-heap allocation issues and system crashes. This commit adds a new Kconfig option ESP32_DONT_USE_ROM_LIBC to allow using NuttX libc instead of ROM newlib functions. When USER_HEAP mode is selected, this option is automatically enabled. Signed-off-by: Tiago Medicci Serrano <tiago.medicci@espressif.com>
When both CONFIG_ESP32_SPIRAM and CONFIG_ESP32_SPIRAM_USER_HEAP are selected, the device must not select CONFIG_NSH_ARCHINIT. Instead, CONFIG_BOARD_LATE_INITIALIZE must be selected. This is necessary because the SPI flash initialization disables the cache, and only internal memory is then accessible. So, if the SPI flash initialization is performed by the entry task (nsh_main, a regular task), it would use the user heap to allocate memory, which would cause a system crash when the cache is disabled. On the other hand, by selecting CONFIG_BOARD_LATE_INITIALIZE, a kernel thread is dedicated to perform the initialization, and the cache can be safely disabled. Signed-off-by: Tiago Medicci Serrano <tiago.medicci@espressif.com>
xiaoxiang781216
approved these changes
Apr 14, 2026
jerpelea
approved these changes
Apr 14, 2026
eren-terzioglu
approved these changes
Apr 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
boards/xtensa/esp32/esp32-devkitc: Fix psram_usrheap defconfig
arch/xtensa/esp32: Fix ROM strdup heap issue in USER_HEAP mode
Please note that this PR incorporates (and closes) #18563. Original authorship is kept.
Impact
Impact on user: Yes. Enable using
esp32-devkitc:psram_usrheapas expected.Impact on build: No.
Impact on hardware: Yes. ESP32 with an external PSRAM (which can now be assigned to the user heap)
Impact on documentation: No.
Impact on security: No.
Impact on compatibility: No.
Testing
Build
esp32-devkitc:psram_usrheapwith DEBUG_ASSERTIONS. Flash the firmware, format the SPI flash partition and check user and kernel heap.Building
Running
After flashing, use
picocom -b 115200 /dev/ttyUSB1, to runmksmartfs /dev/smart0and check available memory withfreeResults