Skip to main content

IAR Embedded Workbench for Arm 9.70.x

System initialization

In this section:

It is likely that you need to adapt the system initialization. For example, your application might need to initialize memory-mapped special function registers (SFRs), or omit the default initialization of data sections performed by the system startup code.

You can do this by implementing your own version of the routine __low_level_init, which is called from the cmain.s file before the data sections are initialized. Modifying the cmain.s file directly should be avoided.

The code for handling system startup is located in the source files cstartup.s and low_level_init.c. cstartup.s is located in the arm\src\lib\arm, arm\src\lib\thumb (for Cortex-M), or arm\src\lib\a64 directory, and low_level_init.c is located in the arm\src\lib\runtime directory.

Note that normally, you do not need to customize either of the files cmain.s or cexit.s.

Note

Regardless of whether you implement your own version of __low_level_init or the file cstartup.s, you do not have to rebuild the library.

Customizing __low_level_init

A skeleton low-level initialization file is supplied with the product—low_level_init.c.

Note

Static initialized variables cannot be used within the file, because variable initialization has not been performed at this point.

The value returned by __low_level_init determines whether or not data sections should be initialized by the system startup code. If the function returns 0, the data sections will not be initialized.

Modifying the cstartup file

As noted earlier, you should not modify the cstartup.s file if implementing your own version of __low_level_init is enough for your needs. However, if you do need to modify the cstartup.s file, we recommend that you follow the general procedure for creating a modified copy of the file and adding it to your project, see Overriding library modules.

Note

You must make sure that the linker uses the start label used in your version of cstartup.s. For information about how to change the start label used by the linker, see ‑‑entry.

For Cortex-M, you must create a modified copy of cstartup_M.s or cstartup_M.c to use interrupts or other exception handlers.