Alex Tech: post #151 — TG.ME

Hi 👋
There’s something I ran into a while ago that wasted a lot of my time, so I thought it might be useful to share here.
When working with STM32 + Interrupts + FreeRTOS, or even in pure bare-metal projects, you might hit a really annoying bug:
- The code runs
- Interrupts are enabled
- Everything looks fine
- But suddenly the system “freezes” or some interrupts just stop firing 😐
First instinct is usually:
NVIC configuration
Clock setup
Interrupt handlers
Or even hardware issues
But there’s something we often overlook:
────────── ✦ ──────────
⚠️ Wrong NVIC Priority Grouping
STM32 has a setting called:
HAL_NVIC_SetPriorityGrouping()

or directly in the register:
SCB->AIRCR

The problem starts when:
You think you’re configuring preemption priorities correctly
But the actual priority grouping is different from what you assumed
Result?
- A low-priority interrupt can block a higher-priority one
- Or some interrupts never preempt as expected
- Or nesting simply doesn’t behave the way you think
────────── ✦ ──────────
A real-world example
I had a project with:
UART interrupt for incoming data
Timer interrupt for real-time control
A FreeRTOS task running in parallel
Everything looked fine at first…
But randomly, UART would just stop receiving data
After hours of debugging, the issue was:
- CubeMX default priority grouping was not what I assumed
- And the Timer interrupt was blocking UART due to incorrect preemption setup
────────── ✦ ──────────
🔧 Simple but important fix
Always explicitly set this at the start of your project:
HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);

Then define priorities clearly, not randomly:
HAL_NVIC_SetPriority(USART1_IRQn, 5, 0);
HAL_NVIC_SetPriority(TIM2_IRQn, 6, 0);

────────── ✦ ──────────
💡 Key takeaway
If your system shows:
- Random freezes
- Intermittent interrupt behavior
- Or unpredictable timing issues

Check NVIC priority grouping before anything else
Not RAM
Not clock
Not even hardware 😄
This is one of those things that:
you don’t take seriously until it breaks your project

#EmbeddedSystems #STM32 #FreeRTOS #RTOS #Interrupts #Firmware #EmbeddedDebugging #Microcontrollers #IoT #TechInsights
✍2👍2❤‍🔥1🦄1
June 28, 2026 295