Skip to main content

IAR Embedded Workbench for Arm 9.70.x

Remapping memory

In this section:

A common feature of many Arm-based processors is the ability to remap memory. After a reset, the memory controller typically maps address zero to non-volatile memory, such as flash. By configuring the memory controller, the system memory can be remapped to place RAM at zero and non-volatile memory higher up in the address map. By doing this, the exception table will reside in RAM and can be easily modified when you download code to the target hardware.

You must configure the memory controller before you download your application code. You can do this best by using a C-SPY macro function that is executed before the code download takes place—execUserPreload. The macro function __writeMemory32 will perform the necessary initialization of the memory controller.

The following example illustrates a macro used for remapping memory on the Microchip AT91SAM7S256 chip, similar mechanisms exist in processors from other Arm vendors.

execUserPreload()
{
  // REMAP command
  // Writing 1 to MC_RCR (MC Remap Control Register)
  // will toggle remap bit.
  __writeMemory32(0x00000001, 0xFFFFFF00, "Memory");
}

Note

The setup macro execUserReset might have to be defined in the same way to reinitialize the memory mapping after a C-SPY reset. This can be needed if you have set up your hardware debugger system to do a hardware reset on C-SPY reset, for example by adding __hwReset to the execUserReset macro.

For instructions on how to install a macro file in C-SPY, see Registering and executing using setup macros and setup files. For information about the macro functions used, see Reference information on C-SPY system macros.