Library 55- Extend USART with TX DMA

Here is a great feature for USART. I’ve made an extension library for USART (and for SPI will come soon) to use DMA for TX data using USART. This can be very handy to use if you have a lot of work and not so many time using your STM32F4 device.

I was thinking first about adding DMA RX functionality for USART too. But then I realize that my USART library by default uses RXNE (RX Not Empty) interrupt and that data is transfered to internal USART’s library buffers. Also, some additional logic and interrupt handlers would be required and this will make library very unefficient.



  • Extension library for TM USART library
  • Supports DMA TX functionality
  • Works with any USART from USART1 to UART8
  • Supports changeable stream and channel settings


    • STM32F4xx
    • STM32F4xx DMA
  • TM
    • TM USART
    • TM DMA
    • defines.h

Stream and channel settings

STM32F4xx devices have 2 DMA controllers. Each DMA controller has 8 DMA streams where each stream has 8 DMA channels for different peripherals available.

To get all available DMA peripherals, you should take a STM32F4xx Reference manual (1700+ pages) and take a look at DMA section. There are all available streams and channels for different peripheral.

This library uses only USART TX DMA. Default DMA streams and channels are in table below:

USART DMA DMA Stream  DMA Channel
USART1 DMA2 DMA Stream 7 DMA Channel 4
USART2 DMA1 DMA Stream 6 DMA Channel 4
USART3 DMA1 DMA Stream 3 DMA Channel 4
UART4 DMA1 DMA Stream 4 DMA Channel 4
UART5 DMA1 DMA Stream 7 DMA Channel 4
USART6 DMA2 DMA Stream 6 DMA Channel 5
UART7 DMA1 DMA Stream 1 DMA Channel 5
UART8 DMA1 DMA Stream 0 DMA Channel 5

Some USARTs allows different streams and channels. This can be handy if you have 2 peripherals on the same stream and DMA and you want to enable DMA for both. You can’t do that because only one channel on specific stream can be used at a time. For that purpose, someking of “remapping” was enabled which allows you to select custom Stream and Channel for specific USART if it is available. Always look for STM32F4xx Reference manual for that settings.



Below example works similar than example for my USART library except it uses DMA to return received string from terminal back to user.

STM32F4xx USART DMA TX functionality

STM32F4xx USART DMA TX functionality

Project is available on my Github account, download library below.


Owner of this site. Application engineer, currently employed by STMicroelectronics. Exploring latest technologies and owner of different libraries posted on Github.

You may also like...