Disable IRQ on STM32
Asked Answered
C

2

6

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

Cabot answered 6/3, 2018 at 16:8 Comment(0)
E
10

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.

enter image description here

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.

Ember answered 6/3, 2018 at 20:15 Comment(4)
FYI: You do not shift by 4 when the cpu is a CM4.Islas
@FelipeLavratti ST implements only bits 7-4, i.e. 16 priority levels on its Cortex-M4 MCUs (F3, F4, L3). Other manufacturers might do it differently.Ember
My friend, not really. This is ARM implementation, not manufacturer. And CM4 spec says that the bits are 0-7 instead 4-7 on CM4. infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0553a/…Islas
The question is about STM32, and the ST manual says only bits 7-4 are implemented.Ember
M
4

Other than by disabling all the enabled interrupts you don't want, no.

__disable_irq() is implemented as CPSID I, which turns off all exceptions which can have a priority set (those configured in the NVIC), it achieves this by changing the PRIMASK register (setting bit 0) within the CPU. There is no way to tell this to only enable a specific interrupt.

Mountaintop answered 6/3, 2018 at 16:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.