How does STM32 enter the interrupt function xxx_IRQHandler, such as: void USART1_IRQHandler(void)
When I started to use STM32 some time ago, I encountered such a problem. When the interrupt settings are configured in the program, how does the program enter the interrupt function when it is running (of course, the interrupts mentioned here are all hardware interrupts), because when running a C program, my understanding is that you always have to have a "baton" or an "entrance" before it can enter the next function. Take
uart1 configuration as an example,
//Interrupt initialization
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/Serial port initialization
USART_StructInit(&USART_InitStructure); //Serial port 1 uses default configuration
USART_Init(USART1, &USART_InitStructure); //Initialize serial port
USART_Cmd(USART1, ENABLE); //Enable serial port
USART_ITConfig(USART1, USART_IT_TXE, DISABLE); //Disable send buffer empty interrupt
USART_ITConfig(USART1, USART_IT_TC , ENABLE); //Send complete interrupt
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); //Receive interrupt
USART_ITConfig(USART1, USART_IT_IDLE, ENABLE); //Receive idle interrupt
When an interrupt occurs, the program responds to the interrupt service function void USART1_IRQHandler(void) in stm32f10x_it.c
{
#if OS_CRITICAL_METHOD == 3 OS_CPU_SR cpu_sr = 0; #endif OS_ENTER_CRITICAL(); OSIntEnter(); OS_EXIT_CRITICAL(); UartISR(U1ART); OSIntExit();12345678910
}
So how does the program find it? In the startup file startup_stm32f10x_md.s, there is a piece of code that assembles
DCD USART1_IRQHandler
, where DCD is a data definition pseudo instruction, which is used to allocate a continuous word storage unit and initialize it with specified data.
There are also some such as PUBWEAK USART1_IRQHandler, etc., the specific meaning is not very clear.
The library defines #define USART1 ((USART_TypeDef *) USART1_BASE)
and #define USART1_BASE (APB2PERIPH_BASE + 0x3800).
My personal understanding is that when the control register interrupt enable of USART1 is configured, when an interrupt (exception) occurs, the exception is accepted by the Cortex-M3 core, and the corresponding exception Handler will be executed. And this response process is completed by hardware. Of course, in order to determine the entry address of the Handler, Cortex-M3 uses the "vector table lookup mechanism". The startup_stm32f10x_md.s startup file has assigned this address to USART1_IRQHandler. So after an exception occurs, the CPU enters the exception mode, and the program counter PC automatically points to the exception entry address, that is, USART1_IRQHandler, and then executes the application in the interrupt service function.
Previous article:Solution to the problem that the STM32 timer cannot exit after entering an interrupt
Next article:Debugging serial port interrupts in STM32
Recommended ReadingLatest update time:2024-11-16 19:36
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- GD32E23X Standard Library and GD32E230 Standard Library Manual
- CC3200 Kit OURS-SDK-WFB_Explore - by tinnu
- Chip Manufacturing 3-Semiconductor Slicing
- RISC-V IDE MRS Usage Notes (IV): Link-time Optimization
- Xunwei 3399 development board-PCIE 4G module test-compiler
- 【CH579M-R1】+DHT22 temperature and humidity detection
- 【BLE 5.3 wireless MCU CH582】13. Power consumption in BLE Peripheral mode
- CircuitPython Online Editor
- A must-read summary of drone principles (Part 3) Introduction to the appearance of drones
- Application design of MCU in blood analyzer