use code sections in the external flash

We are currently working on a project using the Nordic nRF5340 and nRF7002 DK, which includes 1MB of internal flash and 2MB of external SPI flash. Our application codebase has grown substantially and is now utilizing approximately 900KB of the internal flash, leaving limited space for adding new features.

To address this constraint, we are exploring the feasibility of moving selected read-only data or less frequently used code sections to the external flash at runtime.

Project Setup:

External Flash Interface: SPI (non-memory-mapped)

SDK Version: nRF Connect SDK v2.6.4

Our Questions:

1. Is it possible to store certain parts of the code or read-only data in SPI-connected external flash while keeping the main application executing from internal flash?

2. What is the recommended approach to structure this setup, given that the external flash is not memory-mapped?

3. Is it necessary to load the contents from external flash into RAM before they can be executed?

4. Are there any example projects or documentation that demonstrate best practices for accessing code/data modules stored in SPI flash at runtime?

Our Goals:

1. Optimize Internal Flash Usage: Free up internal flash by relocating infrequently used code or read-only data to external flash.

2. Maintain Performance: Ensure critical code continues to run from internal flash or RAM for optimal performance.

We would appreciate it if you could share any relevant documentation, examples, or best practices for achieving this configuration using the nRF Connect SDK.

Parents Reply Children
  • Hi,

    Lavanya_Manohar said:
    1. We are currently using QSPI for the Wi-Fi interface. Is it possible to use the same QSPI peripheral for accessing external flash memory as well?

    The short answer to this one is that this is not possible.

    This means that you have one QSPI connected from the nrf5340 to two chips (7002 + external flash), which means that you can not use both of them simultaneous. This means that any firmware patch offloading is not possible, and it means that you can not access anything on the external flash while the 7002 is running and v.v cannot use the 7002 while the external flash is using the qspi bus. Furthermore, how will you multiplex the 

    If 2 implies that what you will be doing with the qspi in 1 is to execute code from the external flash and/or read/write to an external flash, then the answer is no. XIP is not a catch all solution if you're going over scope. You can only relocate code that can handle to be run slower than on the internal SoC flash. This means that you need to control every entrypoint in your firmware that will be entering into external flash to execute code. None of the code that you relocate can be timing critical or depending on any interrupts.

    Lavanya_Manohar said:
    2. Which Nordic SoCs support using QSPI to interface with external flash memory in XIP (eXecute In Place) mode?

    Execute in place from an external flash over QSPI is only supported for the nRF5340. The nRF54L15 and nRF54H20 has some execute in place features where you can relocate to TCM and/or SRAM that is located on the SoC itself, but not from an external flash device.

    Kind regards,
    Andreas

Related