Skip to main content
Associate II
August 14, 2026
Solved

STM32H563 use DMA for RX and IT for TX on a UART

  • August 14, 2026
  • 5 replies
  • 51 views

I’m just starting a new project using the STM32H563. It has 16 channels of DMA, 8 in GPDMA1 and 8 in GPDMA2. I have at least 11 peripherals I’d like to use DMA for, UARTs, I2C and CAN. That means 22 channels of DMA if I want to use DMA for RX and TX. Does it make sense, or will it even work to use DMA for the RX side of a UART (for example) and IT for the TX side?

My goal is to eliminate or at least minimize blocking in my program. I care more about DMA on the RX side since I often don’t know how many bytes will be in the message from the peripheral. I’ve used character match on the STM32H7A3 to deal with that in the past and the H563 is supposed to support character match also. TX is easier since I always know how many bytes I’m sending. I understand I’m still using CPU cycles to TX in IT mode but I don’t think that will cause any significant issues (I hope).

Best answer by TDK

Hi ​@geneM, hope you are well.

Does it make sense, or will it even work to use DMA for the RX side of a UART (for example) and IT for the TX side?

It will work. The HAL UART code is written in such a way that this will work. Write to registers and updates of relevant state variables are done in an atomic fashion.

I’m still curious if anyone has an opinion about if using DMA for the RX side and IT for TX side of a UART xfer in order to save DMA channels is just another one of my dumb ideas.

Do you need to save DMA channels or do you prefer that way to do it? Then do it. Else, don’t. There is no best here. IT is conceptually and programming-wise easier but comes at the cost of (typically negligible) CPU cycles.

5 replies

waclawek.jan
Super User
August 14, 2026

I care more about DMA on the RX side since I often don’t know how many bytes will be in the message from the peripheral.

 

This is exactly the case *against* using DMA.

OTOH, Tx-ing using DMA is almost trivial, as you know beforehand how many characters are going to be transferred.

JW

Andrew Neil
Super User
August 14, 2026

My goal is to eliminate or at least minimize blocking in my program

You can do that with interrupts - you don’t need DMA just for that ...

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Senior III
August 14, 2026

Be aware that DMA is not available for the CAN peripheral.

You must use interrupts to read the FIFO contents.

You can of course use any DMA channel from the CAN Rx ISR to copy the FIFO content to another memory place, or use the DMA to copy a CAN Tx frame to the Tx FIFO, but you will have to start the frame transmission by yourself.

geneMAuthor
Associate II
August 14, 2026

@waclawek.jan - I agree, it’s the character match functionality that some (many?) of the STM32 microcontrollers offer that makes DMA with UARTs so useful for me. Using CM, I just set up a DMA xfer for more than the maximum number of bytes I expect in the message and the DMA controller ends the xfer whenever the usual LF terminating character arrives.

@Andrew Neil - I agree. I use IT for UARTs when I run out of DMA channels. I just check for the usual LF terminating character in the IRQ handler. But I have to IT one byte at a time. So, DMA should save CPU cycles and and a lot of interrupt operations. If there’s another way to do this, I’d be happy to hear about it.

I’m still curious if anyone has an opinion about if using DMA for the RX side and IT for TX side of a UART xfer in order to save DMA channels is just another one of my dumb ideas.

 

TDK
TDKBest answer
August 14, 2026

Hi ​@geneM, hope you are well.

Does it make sense, or will it even work to use DMA for the RX side of a UART (for example) and IT for the TX side?

It will work. The HAL UART code is written in such a way that this will work. Write to registers and updates of relevant state variables are done in an atomic fashion.

I’m still curious if anyone has an opinion about if using DMA for the RX side and IT for TX side of a UART xfer in order to save DMA channels is just another one of my dumb ideas.

Do you need to save DMA channels or do you prefer that way to do it? Then do it. Else, don’t. There is no best here. IT is conceptually and programming-wise easier but comes at the cost of (typically negligible) CPU cycles.

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