Jboud
Jboud

Reputation: 21

What’s the difference between the startup code and reset handler

Hello stackoverflow community,

Can someone, please, help me to understand the difference between the startup code and the reset handler? When start our microcontroller which one is called? And when we reset our microcontroller which one is called?

I know that the startup code can be found inside the startup.s file bit where can we find the reset handler?

Thank you!

Upvotes: 1

Views: 1990

Answers (3)

dhokar.w
dhokar.w

Reputation: 470

Startup code and reset Handler are almost the same for example for Cortex-M core.

reset Handler is just a function most of the time implemented in assembly but it can be implemented in C as well used as the first function or routine to be executed before jumping to main application entry point (main()).

Startup code consist of mainly assembly code (but can be written in c as well) that will be executed as first routine before jumping as well to main entry (main()).

Nevertheless the Startup code consist beside the reset handler routine of a vector table where the interrupts/exception entries address located and on top of that we may decide to locate as well default routine of each interrupt/exception handler , but in general if we do so we need to make sure that those default handler are marked with weak attribute to allow overwriting those default routine with our own proper implementation.

Upvotes: 1

Igor Skochinsky
Igor Skochinsky

Reputation: 25318

Some microcontrollers allow you to differentiate between different kinds of reset (e.g. power-on reset, software reset, brown-out reset and possibly others). In such situation your reset handler could check the reset reason and only execute the startup code to initialize the hardware and start the main task when really necessary.

Upvotes: 1

Flexz
Flexz

Reputation: 706

Startup code and reset handler are just two names of the same thing.

Reset hander is like an interrupt, it's called by the mcu at boot. MCU loads reset handler address from the interrupt vector table. Reset handler usualy just callst the startup or consists of it.

Startup is usualy written in assember, but sometimes in C. To find the reset handler - look at the interrupt vector table, for Cortex-M core it's the second item, first is the top of stack initial value.

Upvotes: 2

Related Questions