Skip to content

Facilitate RP2040 XIP-cache-as-RAM feature, reclaiming bus bandwidth for time critical instructions in COPY_TO_RAM and NO_FLASH builds #2653

@steffenyount

Description

@steffenyount

The pico-sdk and RP2040 hardware provide a few facilities that improve performance by moving runtime code and data into SRAM:

  1. "pico/platform/sections.h" currently provides the "__not_in_flash", "__not_in_flash_func", and "__time_critical_func" macros for placing runtime code and data into SRAM by assigning them linker section names in the source code.
  2. The pico-sdk CMake scripts allow any of four binary types to be selected with similarly named project properties for the RP2040: "default", "blocked_ram", "copy_to_ram", or "no_flash"
  3. The RP2040's eXecute-In-Place (XIP) cache has its own connection to the main AHB bus and provides SRAM speeds on cache hits when retrieving runtime code and data from flash

But this regime isn't perfect. The 16kB of XIP cache and its connection to the main AHB bus go mostly unused for PICO_COPY_TO_RAM and PICO_NO_FLASH binary type builds, leaving some performance opportunities unrealized in their implementations.

The RP2040's XIP cache can be disabled by clearing its CTRL.EN bit which allows its 16kB of memory to be used as SRAM directly.

I'd like to update the pico-sdk to support the following:

  1. Use the "__time_critical_func" macro to place runtime code into XIP RAM when it's available
  2. Add a couple new "copy_to_ram_using_xip_ram" and "no_flash_using_xip_ram" binary type builds for the RP2040 that support this XIP RAM code placement
  3. Add a new "PICO_USE_XIP_CACHE_AS_RAM" CMake property to enable the XIP cache's use as RAM for time critical instructions with PICO_COPY_TO_RAM and PICO_NO_FLASH binary type builds
  4. Add a couple new CMake functions "pico_sections_not_in_flash(TARGET [list_of_sources])" and "pico_sections_time_critical(TARGET [list_of_sources])" that target selected source file content or a whole CMake build target's list of source files for placement into RAM and/or XIP RAM

I've put together a PR that achieves these 4 goals. I've only tested it with CMake based builds on the RP2040 hardware that I have. That said, I have made an effort to fail fast when CMake configuration properties are incompatible, and I've also made an effort to stay compatible with preexisting linker scripts by building on the preexisting section naming conventions.

Please consider my PR and let me know if my changes are acceptable, or what I can/should change to make them acceptable.

Thanks

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions