I created an assembly language project in IAR EW for ARM. Then I added the source.c file to it with the source code in C, which contains a global variable. It is used by a function in C code, a function in C code is called in assembly code. When building I get a linker error:
Fatal Error[Lp049]: there was no reference to __iar_data_init3, but it is needed to initialize section .bss (source.o #8)
What needs to be done to fix this error?
Global (and other static storage duration) variables in RAM need to be initialized before
mainis called. Usually compiler inserts small code to which will zero RAM area or copy data from flash to RAM.With IAR, the program will typically start with
__iar_program_start, which calls__cmain, which calls__iar_data_init3, which calls__iar_zero_init3and__iar_copy_init3. (You should read the IAR C/C++ Development Guide for this information.) You have now changed something that these functions are no longer being included by the compiler in the final executable.Either make sure compiler includes these functions or implement them yourself. Alternatively you can declare all your static storage duration variables with
__no_init, but remember that you must then initialize them manually on each reset.