Overlay and manual initialization example

Technical Note 36546

Architectures:

ARM

Component:

linker

Updated:

5/31/2018 9:14 AM

Introduction

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.

Example

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

Description:

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.

NOTE!

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.

We do no longer support Internet Explorer. To get the best experience of iar.com, we recommend upgrading to a modern browser such as Chrome or Edge.