Skip to main content
DavePfz
Senior
Oct 26, 2026 9:10 PM UTC
Solved

When/where are interrupts enabled?

I have built up a project using FreeRTOS and STM32_WPAN on an STM32WB55M. It also implements the VBAT for the RTC and uses the EXTI0 and EXTI1 interrupts.

The problem I’m having is that as soon as MX_GPIO_Init() completes an interrupt is generated, but the supporting FreeRTOS queues have not yet been defined and the program just hangs.

My presumption was that on a reset (restart in the debugger) interrupts were disabled, but what I’m seeing doesn’t support this.

What have I missed?

TDK
TDKBest answer
Oct 26, 2026 11:33 PM UTC

However, my question was more about where and when the global interrupts are enabled - usually via the __enable_irq() macro.

Globally, interrupts are enabled after reset in the sense that __enable_irq() is active. It is not called explicitly--that is the default as-reset state.

However, no interrupts will fire until they are individually enabled. Put a __disable_irq() before MX_GPIO_Init if that’s what you want and then __enable_irq when you are ready to handle them.

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

7 replies

TDK
Oct 26, 2026 10:02 PM UTC

When/where are interuots enabled?

The problem I’m having is that as soon as MX_GPIO_Init() completes an interrupt is generated

Interrupts are disabled on startup.

They are enabled in HAL_GPIO_Init which is called within MX_GPIO_Init.

Lots of solutions here. Disable interrupts until you’re ready to receive them. Don’t call MX_GPIO_Init during startup until you are ready.

"If you feel a post has answered your question, please click ""Accept as Solution""."
DavePfz
DavePfzAuthor
Senior
Oct 26, 2026 10:25 PM UTC

I think you misunderstood my question. I fully understand that the EXTI0 and EXTI1 interrupts are enabled in MX_GPIO_Init(). Using STM32CubeMX, it will not allow me to reorder the first three initializations of which MX_GPIO_Init() is the second one. So, your suggestion is not in the normal realm.

However, my question was more about where and when the global interrupts are enabled - usually via the __enable_irq() macro. If the global interrupts are disabled, then the interrupts I’m seeing now will not happen.

I would expect the global interrupts to be enabled at the start of the FreeRTOS kernel. However, the program is never getting that far.

TDK
TDKBest answer
Oct 26, 2026 11:33 PM UTC

However, my question was more about where and when the global interrupts are enabled - usually via the __enable_irq() macro.

Globally, interrupts are enabled after reset in the sense that __enable_irq() is active. It is not called explicitly--that is the default as-reset state.

However, no interrupts will fire until they are individually enabled. Put a __disable_irq() before MX_GPIO_Init if that’s what you want and then __enable_irq when you are ready to handle them.

"If you feel a post has answered your question, please click ""Accept as Solution""."
DavePfz
DavePfzAuthor
Senior
Oct 28, 2026 4:51 PM UTC

I found your statement very interesting in light of my past experiences where a hardware reset turns off the global interrupt enable. However, a review of the reference manual supports your statement. In light of the deep sleep and wake capabilities of this processor, I can understand the reasoning.

I tried putting the disable/enable instructions as you suggested. It did help some, but did not fully resolve my problems. What I eventually did was to remove the enable interrupt options in STM32CubeMX and enabled them in my code once it was started by FreeRTOS. Again that fixed the immediate problem and to me is the better solution.

Thanks.

TDK
Oct 28, 2026 5:23 PM UTC

Just for additional background info:

__enable_irq() and __disable_irq() affect the PRIMASK bit. This is a Cortex thing, not something under ST control, which means it’s governed by the ARM standard. Its default 0, which is interrupts are enabled.

You have to dig a bit in documentation to find this, but it’s there.

 

"If you feel a post has answered your question, please click ""Accept as Solution""."
DavePfz
DavePfzAuthor
Senior
Oct 28, 2026 6:09 PM UTC

Thanks for the pointer. I find this processor is much more than I’m used to. Sort of reminds me of the days when I was first learning the PDP-11/70. That was a long time ago! Since then most of my work has been PIC18 or M0 oriented. It’s nice to have the boundaries expanded, but it does require more of the gray matter.

Many thanks for your kind support.

Pavel A.
Oct 28, 2026 11:40 PM UTC

​@DavePfz If you know PDP-11, you’ll find the IPL exactly same as BASEPRI of Cortex-M  - except that interrupts of priority 0 cannot be masked by BASEPRI and can be only masked by PRIMASK, a.k.a. __disable_irq().  (and that priorities in Cortex-M go from highest=0 to lowest = some configurable number).

Memory-mapped I/O of Cortex-M also is similar to the PDP.