You are on page 1of 4

RESET SEQUENCE OF MICRO-CONTROLLER

In this article, you will learn

1. When you power on micro-controller how does control reach to main() function.

2. Why main() function is required.

3. Why uninitialized global variables have default value ?

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

hard-wired address. This address is generally 0x00000000 in 32bit system.

Consider a example of Cortex M4 architecture (NXP S32K144 Series) :


1. When micro-controller resets PC is loaded with value 0x00000000. At address 0x00000000 vector

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

0x20008000. Fig. 2 Shows the Vector table of cortex M4 architecture

(startup_S32K144.S) , _isr_vector: is start of vector table, and __StackTop is value of stack pointer

stored at memory location 0x00000000. __StackTop value is defined in linker file

(S32K144_100_flash.dld)

Fig.1 Startup Sequence of ARM Cortex M3


Fig.2 Vector Table

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

stack pointer. Will call init_data_bss routine (Refer fig.3)


Fig.3 Reset Handler

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

section .i.e uninitialized global variables will get initialized to 0 (fig.4).