Skip to main content
Francesco Sfragara
Associate
June 4, 2018
Solved

__main in startup assembly

  • June 4, 2018
  • 3 replies
  • 3069 views
Posted on June 04, 2018 at 10:30

Hi.

I'm using keil for programming a stm32 board. In the start up file .s there is a call to __main after the call to SystemInit. Where is the definition of __main? What's the difference between main and __main?
    This topic has been closed for replies.
    Best answer by Nesrine M_O
    Posted on June 04, 2018 at 10:37

    Hi

    IMPORT __main�?

    This line refers to the __main in the C library which eventually calls the main() function defined elsewhere in your project.

    -Nesrine-

    3 replies

    Nesrine M_O
    Nesrine M_OBest answer
    Associate
    June 4, 2018
    Posted on June 04, 2018 at 10:37

    Hi

    IMPORT __main�?

    This line refers to the __main in the C library which eventually calls the main() function defined elsewhere in your project.

    -Nesrine-

    ST Employee
    June 4, 2018
    Posted on June 04, 2018 at 10:40

    Hello,

    main is your main procedure form main.c file, once __main is an internal procedure created by Keil toolchain which is calling at the end your main, but before it is initializing all variables (copying variables from FLASH to proper positions in RAM). In gcc it is seen explicitly, in Keil you can see it within debug process.

    Best Regards,

    Artur

    Francesco Sfragara
    Associate
    June 4, 2018
    Posted on June 04, 2018 at 11:47

    Thank you