Add PSRAM support#2919
Open
will-v-pi wants to merge 37 commits into
Open
Conversation
Supports either enabling PSRAM via boot2, or by injecting a function that runs when restoring QMI CS1 settings
If not detected, it sets address translation to 0, so all PSRAM access Busfaults
It barely fit in boot2 anyway, and would have required embedding boot2 on RP2350
Also remove some bazel TODOs - CMake gates RP2350 only stuff in src/cmake/rp2_common.cmake
Attempts size detection with every possible CS pin
Also fix auto-detection GPIO setup
Also add kitchen sink test that it works
This will always run runtime_init_setup_psram function when hardware_psram is linked If PICO_PSRAM_SIZE_BYTES and PICO_AUTO_DETECT_PSRAM_SIZE are both 0 or undefined, it will only initialise when flash_devinfo is already setup (eg with OTP) Also setup to bus fault with too small PSRAM, add kitchen sink test for those bus faults, and don't trigger those bus faults in runtime_init_setup_psram
Also fix no_flash binaries, and the tiny_psram test
These will either statically allocate in psram, or malloc if the static allocation is not in available psram. Sections are sorted, so the group can be used to set priority. Not sure how useful these are, so could be removed if not wanted.
lurch
reviewed
May 5, 2026
lurch
reviewed
May 5, 2026
lurch
reviewed
May 5, 2026
This removes the need for default_psram_region in bazel linker scripts, and prevents PSRAM appearing in RP2040 elf.map files
lurch
reviewed
May 5, 2026
lurch
reviewed
May 5, 2026
lurch
reviewed
May 5, 2026
lurch
reviewed
May 5, 2026
lurch
reviewed
May 5, 2026
lurch
reviewed
May 5, 2026
lurch
reviewed
May 5, 2026
lurch
reviewed
May 5, 2026
lurch
reviewed
May 5, 2026
lurch
reviewed
May 7, 2026
Improve PICO_AUTO_DETECT_PSRAM_CS_SKIP_DEFAULTS description Add docs from PR description to psram.h Fix kitchen sink compile for small/tiny psram Rearrange runtime_init_setup_psram to make it clearer that stuff gets skipped if setup in OTP
Inconsistent naming, whitespace, still use count_of for uint8_t, psram is rwx
Clang was trying to place persistent_data in PSRAM at the relevant address (eg 0x200xxxxx), and then complaining that it overflowed Fix is to add `> XXX` to the end, to explicitly put it in RAM/XIP_RAM
lurch
reviewed
May 8, 2026
lurch
reviewed
May 8, 2026
lurch
reviewed
May 8, 2026
lurch
reviewed
May 8, 2026
lurch
reviewed
May 8, 2026
Comment on lines
+25
to
+26
| * will be wiggled. By default, it will skip over some which are defined in the board | ||
| * header (see `PICO_AUTO_DETECT_PSRAM_CS_SKIP_DEFAULTS`). |
Contributor
There was a problem hiding this comment.
Hmm, I wonder if there's a use-case for being able to say "never attempt to probe this list-of-GPIOs for PSRAM CS" if there are certain pins which the user doesn't want to get wiggled, but which aren't covered by any of the board-header _DEFAULT_ defines? 🤔
Contributor
Author
There was a problem hiding this comment.
Maybe, and that could be a better way of including the default pins
lurch
reviewed
May 8, 2026
lurch
reviewed
May 8, 2026
lurch
reviewed
May 8, 2026
lurch
reviewed
May 8, 2026
lurch
reviewed
May 8, 2026
Contributor
|
Should this PR also be adding |
Fixup docs at top of psram.h, and add to index.h
Reduce code size slightly by only checking defaults that are CS GPIOs, and add PICO_AUTO_DETECT_PSRAM_CS_SKIP_PINS for user defined ones
lurch
reviewed
May 13, 2026
lurch
reviewed
May 13, 2026
Copied from extract_cmake_configs.py
lurch
reviewed
May 14, 2026
Without this, tlsX_not_needed_marker gets placed in PSRAM for some reason, which then doesn't fit if PSRAM_SIZE_BYTES is 0
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.
This adds a
hardware_psramlibrary to the SDK to add PSRAM support, as requested in #2372Adds PSRAM defines to board headers for boards that have PSRAM - I may not have captured them all
Has three ways it will detect PSRAM when you link
hardware_psram, in order of priority:PICO_AUTO_DETECT_PSRAMis set it will attempt to detect PSRAM size and GPIO on CS1PICO_PSRAM_SIZE_BYTESis set (eg configured in board header, or withpico_override_psram_size) it will initialise PSRAM with that size and GPIOVariables can be placed in PSRAM using
__psramor__psram_uninitialisedmacros, and you can also write directly to the memory addresses.If there are variables placed in PSRAM, it will setup ATRANS to prevent any access to PSRAM addresses greater than the size available (from flash_devinfo, auto-detection, or
PICO_PSRAM_SIZE_BYTES), which will cause bus faults. Thepsram_is_availablefunction should be used before accessing variables in PSRAM when auto-detection is on, to prevent these bus faults.This support uses flash_devinfo to enable the bootrom support for PSRAM, then adds a callback with
flash_set_qmi_cs1_setup_functionwhich runs as part offlash_rp2350_restore_qmi_cs1to enable quad mode and setup faster timings. The RP2350-E14 workaround is included.The CS pin auto-detection iterates through all possible CS pins, skipping any that are defined as defaults in board header files with
remove_defaults_from_cs_gpios- this is an ugly function, but without it you get some garbled characters on the UART as pin 0 is a possible CS pin. Maybe some of the defaults could be removed from this, if they are unlikely to be affected by this auto-detection?This has
psram_or_mallocandpsram_or_freemacros, which statically allocate in PSRAM and use that if available, but usemallocif not available - not sure how useful these are, could be removed if we don't want them. They were to demostratepsram_check_addresswhich checks if an address is in available PSRAM, so you can avoid busfaults when using variables in PSRAM.In passing this also: