cancel
Showing results for 
Search instead for 
Did you mean: 

__disable_irq() and __enable_irq() has no effect

SimonEMBERGER
Associate II

Hello,

I am working on a project with an STM32f446 and I need to disable all interrupts while executing a specific critical function.

I put in my code the following lines :

__disable_irq();

Critical_function();

__enable_irq();

But I still get interrupt while critical_function is executed.

I have tried to find where __disable_irq and __enable_irq are in my project (with both "ctr F" and "Go to definition" fonctionalities) I only found them commented in cmsis_armcc.h file.

/**

 \brief  Disable IRQ Interrupts

 \details Disables IRQ interrupts by setting the I-bit in the CPSR.

          Can only be executed in Privileged modes.

 */

/* intrinsic void __disable_irq();   */

I do not have any error or warning at the compilation due to these function calls, and in debug mode both of them seem not to do anything.

Would anyone have any idea about why it is not working ?

Is there a better way to disable interrupt ?

I am working on Keil v5.28.

Regards

Simon

8 REPLIES 8
TDK
Guru

Using an RTOS? Are you in privileged mode?

If you feel a post has answered your question, please click "Accept as Solution".
SimonEMBERGER
Associate II

Thanks for your quick answer,

I am using Keil RTX os.

And I am not sure about privileged mode, I need to check that, I did not change this paramters on purpose at least.

Is there a quick way to know (register reading in debug or...) if I am or not in privileged mode ?

TDK
Guru

This explains it fairly well:

https://www.programmersought.com/article/15702654463/

This explains how to check:

https://stackoverflow.com/questions/26758569/arm-cortex-m4-test-from-unpriviledged-mode-if-inside-interrupt

if (__get_IPSR() || !(__get_CONTROL() & 0x1)) 
{
   /* Privilged code */
}
else
{
   /* Unprivileged code */
}

Sounds like you may be in user mode in which case you can't disable interrupts. Your RTOS should be able to configure this.

If you feel a post has answered your question, please click "Accept as Solution".
SimonEMBERGER
Associate II

Thanks a lot,

I have managed to find where to set the privileged mode on RTX.

I did the test with your code line and that's ok.

SimonEMBERGER
Associate II

Does the DMA still work if interrupt are disable with __disable_irq ?

My critical function must not be interrupted but I have an assynchrone input on UART which is manage with DMA.

But it seems that I do not get the full uart frame if the reception occurs during the critical function.

SimonEMBERGER
Associate II

And if interrupt occurs diring before the __enable_irq, do they still rise an interrupt flag in order to be executed after __enable_irq ?

Yes, DMA works independent of interrupts.
If you feel a post has answered your question, please click "Accept as Solution".

> And if interrupt occurs diring before the __enable_irq, do they still rise an interrupt flag in order to be executed after __enable_irq ?

Yes. The pending interrupt bits in NVIC will wait and interrupt later,