Skip to content

Add support for using XIP cache as SRAM#2932

Open
will-v-pi wants to merge 39 commits into
raspberrypi:developfrom
will-v-pi:xip-sram-new
Open

Add support for using XIP cache as SRAM#2932
will-v-pi wants to merge 39 commits into
raspberrypi:developfrom
will-v-pi:xip-sram-new

Conversation

@will-v-pi
Copy link
Copy Markdown
Contributor

This adds a new xip_ram binary type (RP2350 only) which puts all code & data in XIP SRAM, and a pico_use_xip_sram_for_time_critical CMake function to put functions marked as time_critical in XIP SRAM instead of regular SRAM. The pico_use_xip_sram_for_time_critical is only useful for copy_to_ram and no_flash binary types - it will still work for default binary types, but makes everything slower instead of faster.

Adds tests of both - currently the pico_xip_sram_test doesn't fit on Clang or Bazel so is skipped on both, and pico_use_xip_sram_for_time_critical is not implemented in Bazel, so pico_critical_xip_sram_test uses a custom linker script instead, for the same effect.

Supercedes #2660, and fixes #2653

will-v-pi added 30 commits March 6, 2026 15:29
Allows for much simpler custom linker scripts
…ript_var variables

Means that CMake doesn't need to know the default memory addresses for different platforms
…l files easier

Restructured so that it includes the platform-specific files before common ones, so common ones can be overridden
Use new include_linker_script_dir and use_linker_script_file functions to add the linker arguments
Breaking change for Bazel builds using different binary types, instead of setting PICO_DEFAULT_LINKER_SCRIPT to eg `//src/rp2_common/pico_crt0:no_flash_linker_script` it is now `//src/rp2_common/pico_standard_link:no_flash_linker_script`
Treat rp2040 layout (boot2 instead of embedded blocks) as the outlier
Allows overriding what to exclude from .text/.rodata and put in .data
These were being placed in Flash due to a missing space, and also are under libc on some compilers
Add PICO_LINKER_SCRIPT_INCLUDE_DIRS and PICO_LINKER_DEFAULT_LOCATIONS_PATH, instead of hardcoded paths under PICO_LINKER_SCRIPT_PATH

Also improve pico_set_linker_script_var and pico_add_linker_script_override_path to better utilise generator expressions
Required changes to the way bazel views these files
…d sections_... which contain multiple

Only exceptions are section_..._data and section_bss, as these contain data/bss and tdata/tbss - these are kept together as they are treated as a single section
…ink_libraries, as it uses generator expressions

Also add more checks to kitchen_sink
Intended for platform specific overrides, whereas post_end is for cross-platform overrides, similar to section_end vs section_platform_end
Use spinlock IDs that are unaffected by E2
…ead of new binary types

Adds pico_include_in_generated_section to fill section_generated_... files with lists of include files,
and pico_set_compile_definition to allow setting the same definition multiple times on a target without getting warnings
Has missed setting PICO_CRT0_PIN_XIP_SRAM
Ordering of transistions matters
@steffenyount
Copy link
Copy Markdown

steffenyount commented May 13, 2026

Hi, it's nice to see some progress on this, thanks!

In the description it says: "This adds a new xip_ram binary type (RP2350 only) which puts all code & data in XIP SRAM".

Can you clarify the intent and use case for this new xip_ram binary type?

By "all code & data" are you intending to put both .data and .text code sections into the eXecute In Place (XIP) SRAM, not just the eXecutable .text sections? That seems suboptimal. Is this some kind of provision to support External flash and PSRAM with the XIP hardware that I'm not familiar with?

Also, in the memmap_xip_ram.incl file, am I reading it correctly that all SRAM locations, including the usual SCRATCH X/Y locations, where the CPUs typically maintain their stack data, are being remapped into the XIP SRAM address space with the new xip_ram binary type?

From our previous conversations in #2660 and #2932 I had attempted the PR #2677 to add my two new build script functions separately, but I ran into supported CMAKE version limitations that precluded their inclusion. The build script functions were attempting to promote whole source file's contents like the "not_in_flash" and "time_critical" macros would, but at source file granularity:
pico_sections_time_critical(TARGET [SOURCES])
pico_sections_not_in_flash(TARGET [SOURCES])

Is the new xip_ram binary type an attempt to do something similar? I'm still focused in RP2040 development, and think a new "copy_to_xip_and_ram" binary type option, that is basically equivalent to the existing "copy_to_ram" binary type option, except that it places all the TARGET eXecutable .text and .time_critical.text content into XIP SRAM could be useful.

Maybe in addition to the new pico_use_xip_sram_for_time_critical(TARGET) build script function we could also add a new pico_use_xip_sram_for_functions(TARGET) build script function that places all the TARGET eXecutable .text and .time_critical.text content into the XIP SRAM? That would make my proposed "copy_to_xip_and_ram" binary type option redundant. Also, the "pico_use_xip_sram_for_time_critical()" could be renamed to "pico_use_xip_sram_for_time_critical_functions()" making the two function's relation and their instruction focus more obvious.

Cheers!

@will-v-pi
Copy link
Copy Markdown
Contributor Author

Can you clarify the intent and use case for this new xip_ram binary type?

The new xip_ram binary type is not for speed, it's to make a binary that doesn't use Main SRAM at all, so that Main SRAM can be used for something else - a use case for this could be a bootloader. It is entirely separate from all the changes we've discussed before.

The stuff we discussed before is now replaced with the pico_use_xip_sram_for_time_critical function, to avoid the need for new binary types. This places only the time critical functions in XIP SRAM.

Is the new xip_ram binary type an attempt to do something similar? I'm still focused in RP2040 development, and think a new "copy_to_xip_and_ram" binary type option, that is basically equivalent to the existing "copy_to_ram" binary type option, except that it places all the TARGET eXecutable .text and .time_critical.text content into XIP SRAM could be useful.

Placing all of .text in XIP SRAM could be an extension to this in a separate PR (it would be more complex), but I think a better extension is your #2677 to allow placing whole files in .time_critical.text (if it can be made to work for older CMake).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants