ARM Cortex M processor reset sequence

ARM Cortex M processor reset sequence


 

ARM Cortex M processor

 

In this post let’s understand the RESET sequence of the Cortex M3/M4 processor. It will answer the question, what happens when you reset the processor. Remember, the addressable memory space of the processor always starts with zero i.e 0x00000000.

The beginning of the memory space starting from zero, actually contains the “vector table”.

Vector table is nothing but a table of information about the initial stack pointer value and various exception handler addresses. We will talk a lot about vector tables and its contents in the later videos of the course. So don’t worry about vector table as of now.

 

What I wanted, you to understand here is that, the sequences after you reset your processor or say your board.

1) After reset, PC is loaded with the address 0x00000000

 

2) Then the processor fetches the value at 0x00000000 in to the MSP. i.e., Main Stack Pointer.

that’s the initial value of the MSP.

So , processor basically first initializes the main stack pointer.

Now the question is,  who puts the valid value into address location 0x00000000.

Yes , it’s the programmer’s responsibility to put the valid value at the location 0x00000000 ( Usually taken care by the startup code )

 

3) Next the processor reads the address of the reset handler from the location 0x00000004 in to the Program Counter.

So , It is very important to store the address of your reset handler in the location 0x00000004

 

4) Then the processor jumps to your reset handler and start executing the first instruction which you wrote there .

If you are wondering what’s the RESET handler. Let me explain to you .

Reset handler is nothing but a normal function written in assembly or C language, which you want to get called whenever processor resets. Remember that RESET is also a processor system exception, so when you hit the reset button , it raises RESET exception, as a result your reset handler will run.

In the reset handler usually we do  initial device specific initialization such as configuring clocks, configuring hardware block, re-initializing the stack space, before calling main function of your application source code.

Application writer guy may not be knowing how to Configure the clock, so “Resent handler” may take care of that before calling the main function.

Here is a small code segment which you can see in the startup code of the STM32 related MCUs.

;Reset handler
Reset_Handler         PROC
                                     EXPORT Reset_Handler [WEAK]
IMPORT            SystemInit
IMPORT            __main
LDR R0,           =SystemInit  /* First calls for the SystemInit , which does MCU Clock init */
BLX R0
LDR R0,           =__main  /* then call main() */
BX R0
END

 

5) After the required initialization, you can then call your main() from Reset Handler ,that’s how the control comes to your main() function in your Application .

Watch the below video for detailed explanation .

 

I hope you understood the reset sequence of the processor. Any questions ? please leave a comment and share this article.

 

FastBit Embedded Brain Academy Courses,

Click here: https://fastbitlab.com/course1

FastBitLab

The FastBit Embedded Brain Academy uses the power of internet to bring the online courses related to the field of embedded system programming, Real time operating system, Embedded Linux systems, etc at your finger tip with very low cost. Backed with strong experience of industry, we have produced lots of courses with the customer enrolment over 3000+ across 100+ countries.