SoC
  • Home
  • Arm
  • Arm Cortex M0/M0+
  • Arm Cortex M4
  • Arm Cortex M3
  • Contact
Reading: Can I copy the vector table to SRAM, remap SRAM to 0x0, so interrupts fetch vectors from SRAM not flash?
SUBSCRIBE
SoCSoC
Font ResizerAa
  • Home
  • Arm
  • Arm Cortex M0/M0+
  • Arm Cortex M4
Search
  • Home
  • Arm
  • Arm Cortex M0/M0+
  • Arm Cortex M4
Have an existing account? Sign In
Follow US
  • Looking for Something?
  • Privacy Policy
  • About Us
  • Sitemap
  • Contact Us
© S-O-C.ORG, All Rights Reserved.
Arm

Can I copy the vector table to SRAM, remap SRAM to 0x0, so interrupts fetch vectors from SRAM not flash?

Andrew Irwin
Last updated: September 17, 2023 1:22 am
Andrew Irwin 5 Min Read
Share
SHARE

Yes, it is possible to copy the vector table from flash to SRAM, remap the SRAM to address 0x0, and have interrupts fetch vector addresses from SRAM instead of flash. This can provide performance benefits by reducing flash access latency during interrupt handling. The key steps are:

Contents
Overview of Vector Table and InterruptsCopy Vector Table Contents to SRAMRemap SRAM to Address 0x0Configure Interrupt HandlingAdvantages of Relocating Vector TableDisadvantages and ConsiderationsSummary

Overview of Vector Table and Interrupts

On ARM Cortex-M processors, the vector table is a structure located at the start of memory that contains the reset and interrupt vector addresses. By default, it resides in flash memory starting at address 0x0. When an interrupt occurs, the processor fetches the corresponding vector address and jumps to the handler function.

Flash memory has higher read latency compared to SRAM. So fetching vector addresses from flash can increase interrupt latency. Copying the vector table to SRAM and remapping it to 0x0 allows fetchs to occur from low latency SRAM instead.

Copy Vector Table Contents to SRAM

The vector table can be copied from flash to SRAM manually or using the System Memory Management Unit (SMMU). To copy manually:

  1. Allocate a region of SRAM to hold the vector table.
  2. Copy vector table contents from flash to SRAM via memcpy or manually.
  3. Update vector addresses to point to SRAM copies of handler functions.

The SMMU can perform the copy automatically on bootup using its region attributes. A background region attribute will make the SMMU copy a flash region to SRAM transparently.

Remap SRAM to Address 0x0

To remap the SRAM region containing the vector table to address 0x0, memory remap registers need to be configured correctly:

  1. Setup the Memory Protection Unit (MPU) regions – one for flash and another for SRAM.
  2. Configure SRAM region to be privileged executable with read/write access.
  3. Map SRAM region to start at address 0x0.
  4. Enable MPU and memory remap controller.

This will remap SRAM to 0x0 while the flash remains mapped at its existing base address. The vector table copied to SRAM will now appear at address 0x0.

Configure Interrupt Handling

With the vector table now remapped to SRAM, some additional steps may be needed for interrupt handling:

  • Update linker scripts to handle function addresses in SRAM.
  • If SMMU used, configure interrupt handling to be consistent with SMMU behavior.
  • Invalidate flash cache after copying vector table to ensure coherency.
  • Configure interrupt priorities, if needed.

The processor should now fetch interrupt vectors from the vector table located in SRAM. This eliminates flash access latency during interrupt handling.

Advantages of Relocating Vector Table

Relocating the vector table to SRAM provides several benefits:

  • Faster interrupt handling due to reduced flash access latency.
  • Deterministic interrupt latency since SRAM has fixed read timing.
  • Makes flash storage available for other uses.
  • Allows flash to be powered down when not in use.
  • Facilitates optimizations like background flash writes.

Disadvantages and Considerations

There are also some downsides to be aware of:

  • Increased complexity in managing two memory maps (SRAM and flash).
  • SRAM usage overhead since memory allocated for vector table.
  • Slightly increased interrupt latency if vector fetch still misses cache.
  • Extra steps needed to maintain coherency between SRAM and flash copies.

So while performance benefits can be significant, the increased complexity may not be justified in some low power applications. Factors like SRAM size limits, interrupt latency requirements, ease of software development, etc should be evaluated.

Summary

Relocating ARM Cortex-M vector tables from flash to SRAM can optimize interrupt performance by reducing vector fetch latency. Key steps are copying the vector table to SRAM manually or via the SMMU, remapping SRAM to address 0x0, and handling coherence between memory maps. Benefits include faster interrupts, deterministic latency, and flexibility in managing flash. Drawbacks are increased complexity and SRAM overhead. Overall, it is a useful optimization when latency and flash access are concerns.

Newsletter Form (#3)

More ARM insights right in your inbox

 


Share This Article
Facebook Twitter Email Copy Link Print
Previous Article Does the Cortex-M0 always default to 0x0 when an interrupt triggers?
Next Article Cortex-M0+ hangs on return
Leave a comment Leave a comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

2k Followers Like
3k Followers Follow
10.1k Followers Pin
- Sponsored-
Ad image

You Might Also Like

What is DSP in ARM processor?

Digital Signal Processing (DSP) refers to processing digital signals using…

6 Min Read

How exceptions are handled in ARM processor?

Exceptions are events that disrupt the normal flow of instruction…

6 Min Read

Dangers of Using Bit Banding for Peripheral Register Access in ARM Cortex M3

Bit banding is a useful feature in ARM Cortex M3…

5 Min Read

What is the Cortex M0 Class Processor?

The Cortex-M0 is an ultra low power 32-bit ARM processor…

9 Min Read
SoCSoC
  • Looking for Something?
  • Privacy Policy
  • About Us
  • Sitemap
  • Contact Us
Welcome Back!

Sign in to your account