Is the main function of the microcontroller executed in the interrupt function?

Publisher:DelightfulGazeLatest update time:2023-09-12 Source: zhihu Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Recently I read something shared by Tough Guy: Why is the main function called directly in the reset interrupt service routine? Are all programs executed in the reset interrupt?




First of all, Reset_Handler is an interrupt of the microcontroller. Secondly, the main function is indeed called by the Reset_Handler interrupt. Isn't that right? The main function is executed in the interrupt?


Seeing this question, have you ever thought about it? Was our previous understanding wrong?


To be honest, I have never thought about this problem. I think most people have not thought about this problem. So, by the way, I would like to share the content of this question.


Microcontroller operating modes

The microcontroller here mainly refers to the ARM Cortex-M core microcontroller.


To answer the opening question, we need to mention the operating modes of the microcontroller. Here we take the Cortex-M3 microcontroller as an example. Cortex-M3 supports two modes and two privilege levels.


Two modes:

  • Handler pattern

  • Thread mode


Two levels:

  • privilege level

  • user level


There is this paragraph in the Cortex-M3 manual:


Among them, I have circled the answers to the opening questions.


The official online documentation also mentions relevant instructions:


address:

developer.arm.com/docum


Example analysis

The answer is circled above. Maybe you are still confused. Here is a simple comparison and analysis based on the engineering code of Keil MDK + STM32.


1. Enter Reset_Handler to interrupt our online debugging, reset the state, enter Reset_Handler to reset the interrupt:




At this time, it is mentioned in the document: after reset, the processor enters the privileged Thread mode.

2. Enter the SysTick_Handler interrupt. When we enter a normal interrupt, for example, enter the SysTick_Handler clock tick interrupt here:




At this point, we have entered the privileged Handler mode.

Seeing this, I think you should understand.


Summarize

The key point of this question is:

The operation modes of reset interrupt (Reset_Handler) and ordinary interrupt (SysTick_Handler) are different.


Other IDEs, such as Keil, GCC and other compilation environments, have similar principles. This problem mainly lies in the kernel, which is determined by the kernel.


Maybe you have never cared about this problem. Of course, we rarely encounter corresponding problems.


This is not a problem. It doesn’t matter if you don’t understand it. What you saw today can be regarded as a knowledge point that further understands the Cortex-M microcontroller core.


Reference address:Is the main function of the microcontroller executed in the interrupt function?

Previous article:Things like MCU reset and program startup
Next article:Microcontroller custom protocol FIFO efficient data sending method

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号