Skip to main content
Visitor II
June 30, 2021
Question

__disable_irq() and __enable_irq() has no effect

  • June 30, 2021
  • 6 replies
  • 13677 views

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

    This topic has been closed for replies.

    6 replies

    Super User
    June 30, 2021

    Using an RTOS? Are you in privileged mode?

    Visitor II
    June 30, 2021

    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 ?

    Super User
    June 30, 2021

    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.

    Visitor II
    July 2, 2021

    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.

    Visitor II
    July 2, 2021

    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.

    Super User
    July 2, 2021
    Yes, DMA works independent of interrupts.
    Visitor II
    July 2, 2021

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

    Super User
    July 3, 2021

    > 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,