历史上的今天
今天是:2024年10月12日(星期六)
2021年10月12日 | stm32中断服务函数的机制
2021-10-12 来源:eefocus
简述:当中断触发时,会保存当前运行状态,然后跳转到中断向量处执行(可嵌套),中断完成后再返回保存的运行状态执行。
中断服务函数并非用户(写程序的人)调用,而是预先写入中断向量(相应中断执行首地址),中断发生后自动执行,所以源码中只需定义实现自己的中断服务函数而不需要考虑在mian中调用的时。
那么问题的关键便是一个普通的c函数是如何实现写入中断向量。mcu的地址最低区是用作中断向量表的,即中断触发后,将执行相应中断向量(字)处的指令(一般为跳转指令)然后跳转到相应的中断服务函数执行,那么中断向量是如何跳转到中断服务函数的地址的呢。
首先我们要看中断服务函数的声明,库文件中唯一的中断服务函数标示符只存在startup.s中,废话少说上代码:
;******************** (C) COPYRIGHT 2014 STMicroelectronics ********************
;* File Name : startup_stm32f051.s
;* Author : MCD Application Team
;* Version : V1.4.0
;* Date : 24-July-2014
;* Description : STM32F051 devices vector table for MDK-ARM toolchain.
;* This module performs:
;* - Set the initial SP
;* - Set the initial PC == Reset_Handler
;* - Set the vector table entries with the exceptions ISR address
;* - Configure the system clock
;* - Branches to __main in the C library (which eventually
;* calls main()).
;* After Reset the CortexM0 processor is in Thread mode,
;* priority is Privileged, and the Stack is set to Main.
;* <<< Use Configuration Wizard in Context Menu >>>
;*******************************************************************************
; @attention
;
; Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
; You may not use this file except in compliance with the License.
; You may obtain a copy of the License at:
;
; http://www.st.com/software_license_agreement_liberty_v2
;
; Unless required by applicable law or agreed to in writing, software
; distributed under the License is distributed on an "AS IS" BASIS,
; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
; See the License for the specific language governing permissions and
; limitations under the License.
;
;*******************************************************************************
;
; Amount of memory (in bytes) allocated for Stack
; Tailor this value to your application needs
; ; ;
Stack_Size EQU 0x00000400
AREA STACK, NOINIT, READWRITE, ALIGN=3
Stack_Mem SPACE Stack_Size
__initial_sp
; ; ;
Heap_Size EQU 0x00000200
AREA HEAP, NOINIT, READWRITE, ALIGN=3
__heap_base
Heap_Mem SPACE Heap_Size
__heap_limit
PRESERVE8
THUMB
; Vector Table Mapped to Address 0 at Reset
AREA RESET, DATA, READONLY
EXPORT __Vectors
EXPORT __Vectors_End
EXPORT __Vectors_Size
__Vectors DCD __initial_sp ; Top of Stack
DCD Reset_Handler ; Reset Handler
DCD NMI_Handler ; NMI Handler
DCD HardFault_Handler ; Hard Fault Handler
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD SVC_Handler ; SVCall Handler
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD PendSV_Handler ; PendSV Handler
DCD SysTick_Handler ; SysTick Handler
; External Interrupts
DCD WWDG_IRQHandler ; Window Watchdog
DCD PVD_IRQHandler ; PVD through EXTI Line detect
DCD RTC_IRQHandler ; RTC through EXTI Line
DCD FLASH_IRQHandler ; FLASH
DCD RCC_IRQHandler ; RCC
DCD EXTI0_1_IRQHandler ; EXTI Line 0 and 1
DCD EXTI2_3_IRQHandler ; EXTI Line 2 and 3
DCD EXTI4_15_IRQHandler ; EXTI Line 4 to 15
DCD TS_IRQHandler ; TS
DCD DMA1_Channel1_IRQHandler ; DMA1 Channel 1
DCD DMA1_Channel2_3_IRQHandler ; DMA1 Channel 2 and Channel 3
DCD DMA1_Channel4_5_IRQHandler ; DMA1 Channel 4 and Channel 5
DCD ADC1_COMP_IRQHandler ; ADC1, COMP1 and COMP2
DCD TIM1_BRK_UP_TRG_COM_IRQHandler ; TIM1 Break, Update, Trigger and Commutation
DCD TIM1_CC_IRQHandler ; TIM1 Capture Compare
DCD TIM2_IRQHandler ; TIM2
DCD TIM3_IRQHandler ; TIM3
DCD TIM6_DAC_IRQHandler ; TIM6 and DAC
上一篇:STM32中断函数名
史海拾趣
|
在WinXP下,调用正常,但是在Wince下执行WSAWaitForMultipleEvents返回错误 87参数不正确。 请教一下,错误在什么地方? 已下代码在线程中执行,pClientSocket->m_hClientEvent是与连接Socket对应的事件, WSAWaitForMultipleEvents等待1000.. ...… 查看全部问答> |
|
R3中微软的Silverlight的例子XAMLPERF中的FRM_START,FRM_STOP,FRM_GET_FRAMES_PER_SECOND什么意思? 这三个东西在main.cpp中定义的: class FrameRateManager { enum FrameRateMonitorMessage { FRM_START = 0, FRM_S ...… 查看全部问答> |
|
STM32的SDIO读写SD卡,使用4bit模式时,连续读写多块总是提示SD_START_BIT_ERR,从论坛上看到有大虾可以实现4bit多块读写,能不能帮忙指点一二,非常感谢啊。。。 1bit模式连续读写多块是正确的,是2G的SD卡。 我用的是万利的开发板,程序是V ...… 查看全部问答> |
|
为自己写了2个。c文件但是没法链接哦 源文件没问题编译K的 Target not created gpio.axf: Error: L6218E: Undefined symbol SystemInit (referred from startup_stm32f10x_cl.o).gpio.axf: Error: L6218E: Undefined symbol RCC_APB2PeriphResetC ...… 查看全部问答> |
|
关于ATMEGA88V驱动SD卡在1.8寸彩屏H018IN01 V8上显示图片思路 本帖最后由 gh131413 于 2014-2-28 10:04 编辑 这款板子已经到手了,由于源程序是GCC的,而本人用的ICCAVR,根据教程所提供的HEX文件编译后图片切换显示正常,但看源程序有太多不明白的地方: TFT彩屏的技术规格书是全英文的且不详细,如何知道现 ...… 查看全部问答> |
|
大家一起学算法精品书籍推荐(十一)嵌入式系统软件设计中的常用算法 为什么要推荐这些资料? 软件行业里一直有一种说法:程序=算法+数据结构。可见如果想要掌握程序设计的精髓,算法是必不可少的。 ...… 查看全部问答> |




