Hi. I am using uVersion2 IDE. Here after reset, MPU will execute code from reset vector located in Startup.A51 file and after some initialization, it will jump to label named as ?C_START which is defined in Init.A51, where it does some other initialization. If we dont include the Init.A51 in project, then will it automatically include for project ? If we dont want to use this Init.A51 file and instead of jumping to ?C_START from Startup.A51, we modify this to jump to Main direclt then will it create any proble ? Thanks.
If we dont want to use this Init.A51 file and instead of jumping to ?C_START from Startup.A51, we modify this to jump to Main direclt then will it create any proble ? Of course not. Keil add all kinds of code just to make sure their competitors can make things more efficient and drive them out of business. When you buy a car, do you remove some of the bolts before you drive it? Erik
Eric thanks for the reply. If we buy a car and if it has unnecessary bolts as per ones point of view that dont require at all, then one will definately remove them. Thanks again.
"If we dont include the Init.A51 in project, then will it automatically include for project ?" Yes. "If we dont want to use this Init.A51 file and instead of jumping to ?C_START from Startup.A51, we modify this to jump to Main direclt then will it create any proble ?" I'm not certain, but I suspect it should be ok provided, of course, you don't have any explicitly initialised static data.
I build my project without INIT.A51. It works fine. Be sure all the project programmers -- including the future ones that might replace you -- know that due to the lack of INIT.A51, source code cannot use static C initializers. It would be even better if you could force lint (or the compiler) to produce an error on encountering initializers. (The compiler will compile such, but the code won't run correctly if it expects the variable to initialized. That's what INIT.A51 does, after all.)
Hi stefan and davis. Thank you very much for providing the information. Here, if we dont have any static variable then there will not be nay problem. But if we dont have then we have to initialize it ? is it ? What about global variables initialization which are not static ?
Again: Here, if we dont have any static variable then there will not be any problem. But if we have then we have to initialize it if we dont want to use INIT.A51. is it ? What about global variables initialization which are not static ?
The C standard specifies that any global variable which does not have an initializer is initialized to zero. There are several loops, one for each memory space (idata, pdata, xdata, etc), in the STARTUP.A51 file that zero out all of the memory. This code implements the requirement of the C spec that uninitialized variables are zero. The compiler takes all of the explicit static initializers and puts them into the code (ROM) area. INIT.A51 copies this region of initialized data to RAM. INIT.A51 implements the C standard feature for initializing global variables. If you omit INIT.A51 from your build, then any program which relies on static initializers will not work correctly. You will have to write code that explicitly initiazes variables the way you want them. For example, this code will fail miserably if you omit INIT.A51
U8 lookup[8] = { 7, 6, 5, 4, 3, 2, 1, 0 }; void main (void) { ... translated = lookup[input]; ... }
U8 lookup[8]; ... void LookupInit (void) { U8 data i; for (i = 0; i < 8; ++i) { lookup[i] = 7 - i; } } // LookupInit ... void main (void) { LookupInit(); translated = lookup[input]; // works only after call to LookupInit(); }
"What about global variables initialization which are not static ?" Yes, they need the INIT.A51 code.
I just come to think of the following: if INIT.A51 is not "needed" will it not be "empty? If no variables need initialization, what will INIT.A51 look like? just "jmp main" I guess. If the above is correct this whole thread is moot Erik
If no variables need initialization, what will INIT.A51 look like? just "jmp main" I guess. INIT.A51 is not a compiler-generated file, so no, it won't change its shape depending on what the actual program uses, and what it doesn't. The startup sequence is: STARTUP.A51 --> defines ?C_STARTUP at boot address (usually 0), does all initialization independent of the program; finishes by jumping to ?C_START INIT.A51: defines ?C_START, carries out static initializations by going through data in segment ?C_INITSEG; finishes by jumping to MAIN. If the project doesn't define ?C_STARTUP in a module of its own (e.g. a modified copy of STARTUP.A51), then a pre-compiled version from the C library is pulled in automatically by the linker. Similarly, if that file references ?C_START, but no object in the project defines it, the linker pulls a pre-compiled INIT.A51 from the library.