在STM32上禁用IRQ [英] Disable IRQ on STM32

查看:158
本文介绍了在STM32上禁用IRQ的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么办法可以禁用除其中一个以外的所有Cortex M3 MCU的irq?

Is there any way to disable all irq from Cortex M3 MCU except one ?

我的问题是,我有一个系统运行多种具有不同优先级的irq,并且我想禁用所有irq(在特定状态下除外).

My issue is that I have a system running several kinds of irq with various priority levels and I want to disable all irq except one in a particular state.

我知道我可以通过使用"__disable_irq()"指令来禁用所有irq,但是如果我之前没有调用过"__enable_irq()",那么在调用此指令后我将无法启用一个irq.

I know I can disable all irq by using "__disable_irq()" instruction but I can't enable one irq after calling this instruction if I didn't call "__enable_irq()" before.

感谢您的帮助,

致谢

推荐答案

使用BASEPRI寄存器禁用所有低于指定优先级的中断.

Use the BASEPRI register to disable all interrupts below the specified priority level.

这是一个核心寄存器,在 Cortex-M3编程手册.

This is a core register, described in the Cortex-M3 Programming Manual.

CMSIS提供了__get_BASEPRI()__set_BASEPRI()函数来操纵其值.

CMSIS provides the __get_BASEPRI() and __set_BASEPRI() functions to manipulate its value.

请注意,使用的是7-4位,必须将优先级值左移4.要禁用所有优先级为1或更低的中断,请使用

Note that bits 7-4 are used, the priority value must be shifted left by 4. To disable all interrupts with priority 1 or lower, use

__set_BASEPRI(1 << 4);

并启用所有功能,将其设置为0

and to enable all, set it to 0

__set_BASEPRI(0);

您当然应该相应地设置中断优先级,确保没有其他中断具有优先级0.

You should of course set interrupt priorities accordingly, ensuring that no other interrupt has priority 0.

这篇关于在STM32上禁用IRQ的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆