🚦 NVIC Priority Calculator

Preempt / subpriority split from PRIGROUP, for Cortex-M NVIC interrupt priorities.

__NVIC_PRIO_BITS for your MCU.
AIRCR[10:8] priority grouping field.
0 = highest urgency.
Breaks ties between equal preempt priorities.

How it works

Cortex-M splits each interrupt's implemented priority bits into a preempt group (can interrupt a lower preempt priority mid-handler) and a subpriority (only orders pending interrupts of equal preempt priority). PRIGROUP (in SCB->AIRCR) decides the split:

preempt bits = min(7 − PRIGROUP, N)     sub bits = N − preempt bits

where N is the number of priority bits the silicon actually implements (__NVIC_PRIO_BITS, 4 on most STM32 parts). The priority value passed to NVIC_SetPriority() occupies the top N bits of the 8-bit priority register field, so it is left-shifted by 8 − N.