Where to set STM32 UART priority?
On STM32 the UART itself doesn’t have a “priority” setting — the NVIC interrupt that serves the UART does. So you always set UART priority…
Where to set STM32 UART priority?
On STM32 the UART itself doesn’t have a “priority” setting — the NVIC interrupt that serves the UART does. So you always set UART priority in the NVIC, not in the UART registers.

1. If you’re using STM32CubeMX + HAL
You have two main places:
a) In CubeMX GUI
- Open your
.iocin CubeMX. - Click “System Core → NVIC” (or the “NVIC” tab in some CubeMX versions).
- Find the line for your UART interrupt, e.g.
USART1 global interrupt→USART1_IRQnUSART2 global interrupt→USART2_IRQn
- Tick “Enabled” and set:
- Preemption Priority
- Sub Priority
CubeMX will then generate code like this in usart.c (inside MX_USART1_UART_Init() or MX_USART2_UART_Init()):
HAL_NVIC_SetPriority(USART1_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(USART1_IRQn);
You can change those numbers in CubeMX so they regenerate correctly.
b) Manually in code (HAL)
If you don’t want to touch CubeMX, you can set it yourself, typically after clock/peripheral init but before you enable the UART IRQ:
// For USART1 example
HAL_NVIC_SetPriority(USART1_IRQn, 5, 0); // (preempt priority = 5, subpriority = 0)
HAL_NVIC_EnableIRQ(USART1_IRQn);
Put this in main.c after MX_USART1_UART_Init() or into your own init function (but outside the /* USER CODE BEGIN */ can be overwritten, so better inside USER CODE blocks).
2. If you’re using UART with DMA
Then you also have DMA interrupt priorities, separate from the UART’s:
DMAx_Channelx_IRQnorDMAx_Streamx_IRQnfor the RX/TX DMA channel/stream.
Set them the same way:
HAL_NVIC_SetPriority(DMA1_Channel5_IRQn, 6, 0); // example
HAL_NVIC_EnableIRQ(DMA1_Channel5_IRQn);
Often you give DMA slightly higher or lower priority than the UART IRQ depending on your design.
3. Bare-metal (no HAL)
If you’re not using HAL at all and writing registers directly, you still set priority in the NVIC priority registers (NVIC->IP[]) and enable the IRQ in NVIC->ISER[]:
NVIC_SetPriority(USART1_IRQn, 5);
NVIC_EnableIRQ(USART1_IRQn);
(CMSIS helper functions.)
So the short answer:
You set STM32 UART priority in the NVIC, either via CubeMX’s NVIC configuration or with
HAL_NVIC_SetPriority(USARTx_IRQn, preempt, sub)in your code – not in the UART peripheral config itself.
메타데이터
- post_id
- 9d62b76fd32b
- slug
- where-to-set-stm32-uart-priority-9d62b76fd32b
- url
- https://medium.com/@pqshedy33/where-to-set-stm32-uart-priority-9d62b76fd32b
- canonical_url
- https://medium.com/@pqshedy33/where-to-set-stm32-uart-priority-9d62b76fd32b
- author_url
- https://medium.com/@pqshedy33
- status
- ok
- fetched_at
- 2026-06-15 20:49:13