Repository navigation
Conversation
CONFIG_SPIRAM_CACHE_WORKAROUND is defined in sdkconfig_esp32.h, but the corresponding compiler and linker flags were never used. ESP-IDF compiles all code with `-mfix-esp32-psram-cache-issue` and links the libc/libgcc multilib variants built with this workaround if SPI RAM is used on ESP32. Without it, writes to SPI RAM can get lost on ESP32 revisions < 3 when an interrupt occurs while a cache line is fetched, which corrupts e.g. the TLSF block headers of the heap in SPI RAM. Assisted-by: Claude Code Opus 5.5
9 of 18 tasks
This branch has not been deployed
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.
Contribution description
This PR fixes an issue with SPI RAM cache for ESP32 revisions < 3.
ESP32 revisions < 3 have a hardware bug in the SPI RAM cache: if an interrupt occurs while a cache line is fetched from SPI RAM, writes to SPI RAM can get lost. ESP-IDF works around this bug with
CONFIG_SPIRAM_CACHE_WORKAROUND, which is enabled by default if SPI RAM is used on ESP32. In that case, ESP-IDF (components/esp_psram/CMakeLists.txtandproject_include.cmake):-mfix-esp32-psram-cache-issueand-mfix-esp32-psram-cache-strategy=memw, so that the compiler avoids the vulnerable instruction sequences, and-mfix-esp32-psram-cache-issue, so that the linker uses theesp32/psrammultilib variants oflibcandlibgcc, which are compiled with this workaround.In RIOT,
CONFIG_SPIRAM_CACHE_WORKAROUNDandCONFIG_SPIRAM_CACHE_WORKAROUND_STRATEGY_MEMWare already defined insdkconfig_esp32.h, but the corresponding compiler and linker flags were never used. Writes to SPI RAM could therefore get lost on affected ESP32 modules. This corrupted, for example, the TLSF block headers of the heap in SPI RAM.This PR adds the flags to
CFLAGSandLINKFLAGSif moduleesp_spi_ramis used on ESP32. Other ESP32x SoCs are not affected.The issue was identified during the migration to ESP-IDF v6.1 in PR #22946. This PR is a split-off from of PR #22946 and simplifies PR #22946.
Testing procedure
Green CI.
Compile an application with SPI RAM for an ESP32 board, e.g.:
Check that the files are compiled with
-mfix-esp32-psram-cache-issue -mfix-esp32-psram-cache-strategy=memw, and the map file shows thatlibc_nano.aandlibgcc.aare taken from theesp32/psrammultilib directories of the toolchain.tests/sys/mallocwithUSEMODULE=esp_spi_ramon an ESP32 module with SPI RAM, ideally an ESP32 revision < 3 (e.g. the ESP32-WROVER of an olderesp32-wrover-kit), should still succeed:Issues/PRs references
Split-off from PR #22946
Declaration of AI-Tools / LLMs usage:
AI-Tools / LLMs that were used are: