2021-06-30 05:04 AM
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
2021-06-30 06:17 AM
Using an RTOS? Are you in privileged mode?
2021-06-30 06:42 AM
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 ?
2021-06-30 06:51 AM
This explains it fairly well:
https://www.programmersought.com/article/15702654463/
This explains how to check:
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.
2021-07-02 01:10 AM
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.
2021-07-02 07:20 AM
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.
2021-07-02 07:26 AM
And if interrupt occurs diring before the __enable_irq, do they still rise an interrupt flag in order to be executed after __enable_irq ?
2021-07-02 07:28 AM
2021-07-03 01:51 PM
> 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,