Skip to content

Exercises related to RTOS

Startup code

Exercice 1

Based on the following ARM application note, explain the startup code, the __main() function. In particular, explain how the application main() is eventually called.

Solution

At startup, any Cortex-M processor will load the main stack pointer (MSP) from the first word in the program image. It will then call the function whose address is stored in the second word of the program image, usually the Reset_Handler function. The Reset_Handler function is usually defined in the “startup_<device.s>” file. It calls the SystemInit() function and then the __main() function.

The __main() function is the entry point in the C library. Its implementation thus also depends on the toolchain. For the ARM toolchain, it first calls the __scatterload() function that initializes the various code and data regions. It then calls the __rt_entry() function that performs some initializations (stack, heap, fpu) and eventually calls the main() application function.