STM32中的异常与中断(理论)

目录

目录

目录

一、中断的基本概念

二、异常与中断

(一)概述

(二)异常类型

(三)中断控制

(四)向量表(Vector table)


一、中断的基本概念

中断的定义以及中断工作方式

        中断,即CPU在正常执行程序的过程中,遇到外部(例如常见的按键防抖 / 内部(定时器中断)) 的紧急事件需要处理,暂时中断(中止)当前程序的执行,而转去位事件服务,待服务完毕,再返回到暂停处继续执行原来的程序。

二、异常与中断
(一)概述

《Cortex M3与M4权威指南》章节4.5 P104

Exceptions are events that cause changes to program flow. When one happens, the processor suspends the current executing task and executes a part of the program called the exception handler. After the execution of the exception handler is completed, the processor then resumes normal program execution. In the ARM architecture, interrupts are one type of exception. Interrupts are usually generated from peripheral or external inputs, and in some cases they can be triggered by software. The exception handlers for interrupts are also referred to as Interrupt Service Routines (ISR)。

Each exception source has an exception number. Exception numbers 1 to 15 as system exceptions, and exceptions 16 and above are for interrupts. The design of the NVIC in the Cortex-M3 and Cortex-M4 processors can support up to 240 interrupt inputs. However, in practice the number of interrupt inputs imple mented in the design is far less, typically in the range of 16 to 100. In this way the silicon size of the design can be reduced, which also reduces power consumption。

 

(二)异常类型

1.系统异常

 《Cortex M3与M4权威指南》章节7.2 P232

        1到15是系统异常,数值越小优先级越高。

2.中断 

(三)中断控制

《Cortex M3与M4权威指南》章节7.3 P235、

After reset, all interrupts are disabled and given a priority-level value of 0. Before using any interrupts, you need to:

  • Set up the priority level of the required interrupt (this step is optional)
  • Enable the interrupt generation control in the peripheral that triggers the interrupt
  • Enable the interrupt in the NVIC

In most typical applications, this is all you need to do. When the interrupt triggers, the corresponding Interrupt Service Routine (ISR) will execute (you might need to clear the interrupt request from the peripheral within the handler). The name of the ISR can be found inside the vector table inside the startup code, which is also provided by the microcontroller vendor. The name of the ISR needs to match the name used in the vector table so that the linker can place the starting address of the ISR into the vector table correctly.

(四)向量表(Vector table)

《Cortex M3与M4权威指南》章节4.5.3 P107

When an exception event takes place and is accepted by the processor core, the corresponding exception handler is executed. To determine the starting address of the exception handler, a vector table mechanism is used. The vector table is an array of word data inside the system memory, each representing the starting address of one exception type。

具体内容可在《Cortex M3与M4权威指南》中有

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

萌新小电阻

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值