Why Most MCUs Use XIP to Execute Code?

Click the above“Embedded Intelligence Bureau”, select“Top/Star”

Embedded intelligence, delivered first-handWhy Most MCUs Use XIP to Execute Code?Hello everyone, I am the intelligence guy~Today I will share with you the technology and knowledge of XIP:

1. What is XIP

XIP, short for eXecute In Place, translates to “Execute In Place” or “Execute On Chip”.

It is a design feature of computer systems that allows the CPU to directly fetch and execute code from non-volatile storage media (such as NOR Flash, ROM), without the need to first copy the code to RAM (Random Access Memory) for execution as in traditional methods.

In simple terms, it means “the program runs where it is stored”.

2. Differences Between XIP and Traditional Methods

To understand the value of XIP, we first need to look at how systems operate without it.

1. Traditional Execution Method (Copy to RAM)

This is also the working method of most general-purpose computers (like our PCs, smartphones) and many embedded systems.

Why Most MCUs Use XIP to Execute Code?Steps:1. The system powers on.2. The Bootloader copies the application code from slower non-volatile memory (like NAND Flash, eMMC)to high-speed RAM.3. The CPU reads instructions from RAM and executes them.The advantage is that RAM has very fast read/write speeds, ensuring high efficiency in program execution. However, there are certain drawbacks, such as occupying RAM space: The code and data segments of the program need to fully occupy valuable RAM space. It is also important to note that time is required to copy the code from the storage medium to RAM, which is unacceptable for systems with strict startup time requirements..

2. XIP Execution Method (Execute In Place)

Why Most MCUs Use XIP to Execute Code?Steps:1. The system powers on.2. The CPUdirectly fetches instructions from a specific address in the XIP-supported storage medium (like NOR Flash) and executes them. There is no need to copy the code to RAM.The advantage is that the code runs in Flash, freeing up a significant amount of RAM space, only requiring RAM for stack and variables. This is crucial for cost-sensitive and RAM-limited microcontrollers (MCUs), which is why most MCUs adopt this scheme. Additionally, it eliminates the time spent copying code, allowing for “power-on and run,” resulting in extremely fast startup speeds.However, there are also drawbacks: the read speed of some storage media (like NOR Flash) is usually much slower than RAM, which can lead to performance bottlenecks. The CPU often has to wait for Flash to provide instructions (wait states). Writing operations to the storage medium where the code resides (like writing data) are usually slow and require special erase operations.

Feature Traditional Method (Copy to RAM) XIP Method (Execute In Place)
Execution Location High-speed RAM Non-volatile memory (like NOR Flash)
Startup Speed Slow (requires copy time) Extremely fast (no copy required)
RAM Usage High (code and data occupy RAM) Low (only variables and stack occupy RAM)
Execution Speed Fast (RAM speed is fast) Slower (limited by memory speed)
Cost Requires larger capacity RAM Can use smaller capacity RAM, reducing overall cost
Typical Storage NAND Flash, eMMC, SD Card NOR Flash, ROM
Applicable Scenarios High-performance applications, complex operating systems (Linux) Cost-sensitive, RAM-limited, fast startup MCU applications

3. Application Scenarios

  1. Embedded Microcontrollers (MCUs):

  • This is the most widely used field for XIP technology. For example, ST’s STM32 series, NXP’s i.MX RT series crossover processors, etc. Their programs are usually stored in internal or external NOR Flash and run directly from there, saving expensive on-chip RAM and reducing system costs.
  • Ultra-fast Startup Systems:

    • For devices that require instant startup, such as automotive airbag controllers, industrial emergency braking systems, etc., the time saved from copying code is crucial.
  • Boot ROM:

    • Almost all processors have a small block of mask ROM inside, where the initial Bootloader is hardcoded. The first instruction executed by the CPU after power-on is from this fixed address in the ROM, which is the classic application of XIP.

    Of course, it also has many challenges:

    1. Traditional serial interfaces transmit data through a single line at a time, leading to high data transfer latency and low throughput between the processor and external flash.

    2. The processor and external flash are powered separately, and the energy consumed during communication may increase the overall system power consumption.

    3. During OTA (Over-The-Air) updates, writing operations to external flash may block reads for a long time, causing the system to be unable to obtain the next instruction, leading to a deadlock.

    Finally

    The guy has collected some embedded learning materials, reply in the public account with 1024 to find the download link!

    Recommended good articles, click the blue text to jump to them
    ☞ Collection | Comprehensive Programming of Linux Applications
    ☞ Collection | Learn Some Networking Knowledge
    ☞ Collection | Handwritten C Language
    
    ☞ Collection | Handwritten C++ Language
    ☞ Collection | Experience Sharing
    ☞ Collection | From Microcontrollers to Linux
    ☞ Collection | Power Control Technology
    ☞ Collection | Essential Mathematics for Embedded Systems
    ☞  MCU Advanced Collection
    ☞  Embedded C Language Advanced Collection
    
    
    
    

    Leave a Comment