Programming STM32-Discovery using GNU tools. Startup code

Startup code is executed just after microcontroller is reset before the main program. As linker script, startup code usually is implemented as universal code for all the same microcontroller type. So often you don’t need to write one from scratch. Anyway, it is good to know what happens there anyway. As we said, linker script has to go along with the startup code. This means that it will initialize MCU automatically according to data defined in the linker. Startup code initializes variables, copies defined variables from Flash to RAM, initializes stack and then gives resources to the main program. You will find that startup codes usually are written in assembly language, but this can also be done in C, which is easier to read and modify if necessary. First of all, in linker script we have pointed entry point to startup with the following command: So in startup code, this will be the first function called.

Continue reading