XIP vs. SRAM Execution Performance on Embedded MCUs: A Benchmark Comparison
This article compares real-world benchmark results for embedded MCU code running from internal SRAM versus external Flash using XIP (eXecute In Place). It explains why peak datasheet numbers often fail to match field performance, outlines the core differences between the two execution modes, and presents measured scores showing only a small single-digit percentage gap when XIP is properly configured. Readers will also find a practical porting checklist covering compiler flags, linker scripts, build macros, and boot configuration, followed by a tuning order for closing any remaining performance gap.
1. Background: Why Great Benchmarks Can Still Feel Slow
A long-standing debate in embedded selection and evaluation is that the compute performance quoted in datasheets and marketing materials is often hard to reproduce in real projects. The reason is straightforward. Most microcontrollers and processors integrate a limited amount of on-chip static storage that can be accessed without wait states, commonly called the zero-wait region. Externally expanded storage, constrained by bus protocol, clock division, data width, and the medium’s own read timing, usually requires one or more wait states, forming the so-called non-zero-wait region.
When the code footprint is small, placing all critical logic in the internal static storage naturally yields the best numbers. Once business complexity grows—protocol stacks, GUIs, algorithm libraries, and file systems get linked in—the code section inevitably overflows the zero-wait region and is forced to execute from the non-zero-wait region. If the medium or bus configuration is poor at that point, performance can drop off a cliff, and users experience “strong specs, sluggish feel.”
Therefore, evaluating a chip’s real usability means looking beyond its peak under the most favorable conditions. It also means examining its behavior in the most common deployment form: executing code in place from external media. That is the core question this article verifies: on the same chip, how large is the gap between running code from internal static storage and running it in external Flash XIP mode.
2. The Fundamental Difference Between the Two Modes
2.1 Running from Internal Static Storage
Code is linked into on-chip static storage, and instruction fetch is handled by the internal bus with no wait states, giving the best timing determinism. Its strengths are the lowest latency and minimal jitter, making it suitable for hot paths such as interrupt service routines, real-time control loops, and cryptographic and math operations. Its weakness is limited capacity and higher cost, so it cannot host a complete application.
2.2 External Flash XIP (eXecute In Place)
XIP means the processor reads and executes content directly from the medium through the external memory interface, without first copying code into RAM. Its strengths are large capacity, low cost, and the ability to host complex applications. Its weakness is a longer instruction fetch path, with performance affected by interface mode (single/dual/quad), clock frequency, bus arbitration, and cache strategy together.
It is worth stressing that XIP performance is not inherently slow. When the interface runs in high-speed quad mode with reasonable wait states and a prefetch strategy, instruction fetch throughput can approach that of internal storage, shrinking the gap to an acceptable range.
3. Test Method and Results
This verification used the same benchmark program compiled under two link configurations:
- Internal static storage execution: score around 4702
- External Flash XIP execution: score around 4570
- Difference: about 132 points, a relative gap of roughly 2.8%
Three conclusions follow. First, on this platform the performance gap between XIP and internal storage is small, on the order of a single-digit percentage rather than an order of magnitude. Second, the XIP score is even higher than the official reference value, showing that external media can fully handle high-performance scenarios as long as the interface mode and wait states are configured properly. Third, the “discount” users actually experience comes more from misconfiguration (reduced interface speed, excessive wait states, disabled cache) than from a hard architectural flaw.
4. Porting and Configuration Checklist
To make both modes run correctly, four alignment changes are needed at the project level. The following descriptions are generic; refer to the reference manual of the chip in use for specific registers and macro names.
4.1 Instruction Set Extensions and Compiler Options
Confirm the toolchain enables the instruction extensions required by the target architecture, and keep the same optimization level under both configurations. Enabling at least basic optimization is recommended to avoid performance distortion from debug configurations.
# Example: aligning compiler options-march=<target architecture extensions>-O2 # use the same optimization level for release and debug
4.2 Linker Script Partitions
The two modes use different memory maps, so the linker script must be maintained separately:
# XIP configuration example: code resides in external mediaFLASH (rx) : ORIGIN = <external media mapped base>, LENGTH = <capacity># SRAM configuration example: code resides in internal static storageRAM (rx) : ORIGIN = <internal storage base>, LENGTH = <capacity>
The key point: the XIP configuration must place the vector table and code section in the external media mapped region and ensure the startup code correctly completes media interface initialization; the SRAM configuration places the code section in internal storage, either relocated by the startup flow or linked directly.
4.3 Macro Definitions
Use compile macros to isolate the two configurations and avoid cross-contamination:
# XIP build-DUSE_XIP=1# SRAM build-DUSE_XIP=0
4.4 Boot Switches and Media Initialization
The boot medium is usually selected by hardware switches. XIP mode requires switching to external media boot and initializing the interface clock, line width, and wait states early; SRAM mode relies on a debugger or loader to place the image into internal storage before jumping to it. The switch settings for the two modes must not be mixed, otherwise the typical “flashes fine, won’t boot” failure occurs.
5. Performance Tuning Recommendations
If the measured gap is large, troubleshoot in this order: confirm the external interface runs at the highest available line width and frequency; verify wait states are set to the minimum values from the medium’s datasheet; enable instruction cache or prefetch; place the interrupt vector and hot functions in the zero-wait region; and only then consider moving critical loops entirely into internal storage. In most cases, the first three steps bring the gap back to a single-digit percentage.
6. Conclusion
For developers, selection should not be swayed by zero-wait benchmark numbers alone; instead, require verification of real data under XIP deployment. This article’s measurements show that, with proper configuration, the performance gap between external media XIP and internal storage execution is controllable, and complex applications can confidently run from external media. Only by baking the verification method, configuration checklist, and tuning order into an engineering template can the gap between “great-looking specs” and “discounted experience” be avoided.
