startup files in Keil

Can You explain me something. Why in ARM microcontrollers each IDE use startup files?
Where from the compiler knows that the first think is to execude the code from startup. Each C language programms should start from main() funcion and here the program starts from startup?
If the startup does not exists it works fine too but we have to make Heap, stack and other by ourself but in main()?
If I add different startup called whatever i want and add it to group in project in will be done the as first too so it means that the name of the startupp file is not important.

Can you explain me how does it work? (for example in Keil)

Parents
  • The IDE does not use any startup file.

    It's the programs you develop that are using startup files.

    When you write programs for a PC, there are also startup files. But since the tools then knows the target is a PC, the startup file can have a fixed contents. So it is hidden inside the language runtime library. And some of that "startup file" is actually moved all the way to the BIOS when the computer boots. Every single motherboard have a custom "startup file"/BIOS explicitly adapted to the available hardware. An to that, you also have a custom hardware driver layer used by the OS.

    For embedded projects, each target hardware is so different that only you, the developer, can know what is needed to prepare the hardware in a way that the C runtime library can then be used.

    Each C program should start from main() - that is a bit of a simplification. If you look at the C language standard, you will see that there are numbe of rules that must be fulfilled before the program reaches main(). For example - all global variables should be zero-initialized. And main() must be directly able to call other functions, so some magic must have set up the stack.

    A C program is linked with a C RTL - C Runtime Library. And it must have been properly initialized before the program reaches main().

    The linker configuration file contains information about what object files that should be linked first.

    And the startup file (normally in assembler, but could be in C for Cortex-class processors) contains information like:

                    AREA    RESET, CODE, READONLY
    


    to inform the linker that a generated code block should match the requirements for the linker configuration file.

Reply
  • The IDE does not use any startup file.

    It's the programs you develop that are using startup files.

    When you write programs for a PC, there are also startup files. But since the tools then knows the target is a PC, the startup file can have a fixed contents. So it is hidden inside the language runtime library. And some of that "startup file" is actually moved all the way to the BIOS when the computer boots. Every single motherboard have a custom "startup file"/BIOS explicitly adapted to the available hardware. An to that, you also have a custom hardware driver layer used by the OS.

    For embedded projects, each target hardware is so different that only you, the developer, can know what is needed to prepare the hardware in a way that the C runtime library can then be used.

    Each C program should start from main() - that is a bit of a simplification. If you look at the C language standard, you will see that there are numbe of rules that must be fulfilled before the program reaches main(). For example - all global variables should be zero-initialized. And main() must be directly able to call other functions, so some magic must have set up the stack.

    A C program is linked with a C RTL - C Runtime Library. And it must have been properly initialized before the program reaches main().

    The linker configuration file contains information about what object files that should be linked first.

    And the startup file (normally in assembler, but could be in C for Cortex-class processors) contains information like:

                    AREA    RESET, CODE, READONLY
    


    to inform the linker that a generated code block should match the requirements for the linker configuration file.

Children
More questions in this forum