Download and run whole application in RAM (Cortex-M3)

Technical Note 73964



4/26/2013 12:36 PM


You have a need to run a complete application in RAM.


This suggestion will only work when downloading with the C-SPY debugger.
If you need to run in RAM stand-alone, then go to Technical Note 11578.


These are the steps needed to get the whole application placed in RAM, and to get it to run as expected in RAM.

  • Get data (read/write and constant) and code linked to be placed in RAM.
  • Place the Vector Table in RAM (with at least the alignment forced by the Cortex-M design.)
  • During C-start-up, set VTOR to the address of the Vector Table.

Suggested solution:

There are different ways to solve the problem, (so these suggestions are just one possibility).

Place CODE and DATA in RAM.

  • Use the "edit"-button (or change directory in your .icf file) at Project > Options > Linker > Config to open the window "Linker configuration file editor"
  • Go to the tab "memory regions" - copy the value in RAM/start and paste that value in ROM/start - then copy the value in RAM/end and paste it as ROM/end.

Check that CODE, DATA and Vectors are placed in RAM

Build the project.

  • Check (in the .map file) that the Vector Table (symbolic name is __vector_table ) is placed in RAM and at an address that is aligned to 2^7.
  • If needed to change go to Project > Options > Linker > Config > tab "Vector table".
  • Change to an address in RAM that is aligned to 2^7 (a suggestion is to use address 0x20000000)


Change VTOR ("Vector Table Offset Register") to point to the location in RAM for the Vector Table (symbolic name __vector_table ).

  • Take a copy of the file \arm\src\lib\low_level_init.c and add the coppiced file to your project. (You might need to remove write protection from the file.)
  • Add an #include-statement for the device in use. (To get the definition of the register VTOR.)
  • Add a declaration for ... extern int __vector_table[]; ...the Vector Table
  • In the function __low_level_init set VTOR to the address of __vector_table, which can be done as:
    VTOR = (unsigned int) & __vector_table;


Build the project.

  • Download into the Simulator. Check that VTOR is set to the address of the Vector Table in RAM.
  • Change from Simulator to your hardware debugger driver.
  • Download to RAM and run the application there.

Example project

On the link below there is an example project for STM32F103ZE.



All product names are trademarks or registered trademarks of their respective owners.

Related Tech Notes

© IAR Systems 1995-2016 - All rights reserved.