Overlay and manual initialization example

Technical Note 36546



10/28/2010 2:04 PM


The overlay functionality described in the “IAR C/C++ Development Guide for ARM”, chapter “Manual initialization” can be difficult to understand, so this Tech Note aims to describe it in more detail using a simple example.


Download and open the example project from the link: Overlay example project.zip.


Two functions, test1() and test2() are initialized manually from two sections in ROM (MYOVERLAY1_init and MYOVERLAY2_init). The ICF file contains the following:

define overlay MyOverlay { section MYOVERLAY1 };
define overlay MyOverlay { section MYOVERLAY2 };
initialize manually { section MYOVERLAY1, section MYOVERLAY2 };

The main function first initializes the MyOverlay section in RAM (by using memcpy) with data from MYOVERLAY1_init - i.e. the test1()-function. Then, main calls the function at address "MyOverlay". The test1() function returns the value 1.

After this, the main-function initializes the MyOverlay section in RAM with data from MYOVERLAY2_init - i.e. the test2()-function. Then main calls the test2() function (at the same address as where the function test1() did execute). The test2() function returns the value 2.

Notice that in the file “overlay_test.map”, you will find that both functions are linked to the same address.

The above example shows the basics of overlays, and can be executed using the C-SPY simulator.


When executing code from RAM, one must take care not to access ROM data and functions. As a contrast, when using the “__ramfunc” keyword, the compiler will check that all accesses are ok, and possibly issue this warning:

"Warning[Ta022]: Possible rom access (romvar) from within a __ramfunc function".

This checking is not possible when functions are manually put in RAM (for example when using the overlay method).

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

Related Tech Notes

© IAR Systems 1995-2016 - All rights reserved.