Download and run whole application in RAM (Cortex-M3)
Technical Note 73964
Architectures:
ARM
Component:
general
Updated:
11/6/2015 1:48 PM
Introduction
You have a need to run a complete application in RAM.
Limitation
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.
Discussion
Background:
These are the steps needed to get the whole application placed in RAM, and to get it to run as expected in RAM.
- Change so that data (read/write and constant) and code are 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 make a solution, 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 page "memory regions"
- copy the value in
RAM/start
and paste that value inROM/start
- then copy the value in
RAM/end
and paste it asROM/end
.
- copy the value in
Check that CODE, DATA and Vector table 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 to2^7
. - If needed to change go to page Project > Options > Linker > Config > Vector table.
- There change to an address in RAM that is aligned to 2^7 (a suggestion is to use address
0x20000000
)
- There change to an address in RAM that is aligned to 2^7 (a suggestion is to use address
Set VTOR RAM
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. (That is to get a reference to the header (.h
) holding the definition of the registerVTOR
.) - Add a declaration for ...
extern int __vector_table
[]; ...the Vector Table - In the function
__low_level_init
setVTOR
to the address of__vector_table
, which can be done as:
VTOR = (unsigned int) & __vector_table;
Test that VTOR is correctly set.
- Build the modified project.
- Download into the Simulator.
- Check that
VTOR
is set to the address of the Vector Table in RAM.
- Check that
- 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.