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

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

问题描述

有什么办法可以禁用 Cortex M3 MCU 的所有 irq,除了一个?

我的问题是我的系统运行了多种具有不同优先级的 irq,我想禁用所有 irq,除了处于特定状态的 irq.

我知道我可以通过使用__disable_irq()"指令来禁用所有的irq,但是如果我之前没有调用过__enable_irq()"的话,我在调用这个指令之后就不能启用一个irq.

感谢您的帮助,

问候

解决方案

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

这是一个核心寄存器,在

CMSIS 提供了 __get_BASEPRI()__set_BASEPRI() 函数来操作它的值.

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

__set_BASEPRI(1 << 4);

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

__set_BASEPRI(0);

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

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

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.

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.

Thanks for your help,

Regards

解决方案

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

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

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

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);

and to enable all, set it to 0

__set_BASEPRI(0);

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

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

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