Beruflich Dokumente
Kultur Dokumente
1. When you power on micro-controller how does control reach to main() function.
1. INTRODUCTION :
What happens when micro-controller resets. when you reset micro-controller, it will start
performing some initialization and starts executing from the main() function. Do you want to know
how this all happens, then you are reading right article.
2. STARTUP SEQUENCE :
Have you ever thought how does micro-controller start execution from the main() function, when
powered on? If yes then you are reading right article. Let's get started.
I assume you all are aware of the Program Counter of micro-controller. PC is a register which stores
the address of an instruction which is being executed at the current time. PC is hard-wired at specific
address location. So when micro-controller starts from power up, PC fetches the 1st instruction from
table is located. In case of cortex M4, it reads first two words from vector table. Consider Fig.1 at
address 0x00000000, value stored is 0x20008000, which is value of top of stack i.e MSP is pointing to
(startup_S32K144.S) , _isr_vector: is start of vector table, and __StackTop is value of stack pointer
(S32K144_100_flash.dld)
2. Then from address 0x00000004 PC get loaded with the address of Reset handler. Reset handler is
defined in startup file(startup_S32K144.S). Reset handler will initialize registers i.e. r0 to r13 and
3. init_data_bss routine is defined in startup.c file. This routine will copy initialized data (.data
section) and functions (.txt section) from rom to ram and zero initializes the .bss