cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H7+DMA+UART – which stream ?

TMA1of3
Associate III

Hi there,

can anyone assist in understanding how to choose the correct ‘stream’ for an STM32H7 + DMA + UART setup, please ?

I’m continuing work on a previous colleague’s firmware where UART1 was programmed to operate in DMA mode. This needs to change to UART2 now and while I can see from the documentation which channel should be assigned I’m not so sure about how to select the correct ‘stream’.

For the existing UART1 code I see values set for “COM1_TX_DMA_CHANNEL�? = 42 and “COM1_RX_DMA_CHANNEL�? = 41, and these correctly correspond to the DMA request MUX input values from Table 121 of ST’s document RM0433 (the reference manual for this STM32H743 microprocessor). Changing these to the corresponding COM2, or UART2, values is simple as the information is in the same table.

Other STM microprocessor datasheets include a table specifically listing peripheral request channel v stream number, but not this microprocessor (as far as I can tell although it might be in a different format ?).

The existing code then also defines “COM1_TX_DMA_STREAM�? = DMA2_Stream7 and “COM1_RX_DMA_STREAM�? = DMA2_Stream5 (albeit there is no actual definition of DMA2_Stream7 and DMA2_Stream5 as far as I can tell, but I assume these are correct based on the performance). Do you know how to determine the correct ‘streams’ whether it be for UART1 or for UART2 ? As mentioned the reference manual doesn’t seem to include this information, so this is what I require assistance with, please – thank-you.

Also, the existing code stipulates the following as part of the uart1/dma setup:

RCC_PeriphClkInit.Usart16ClockSelection = RCC_USART1CLKSOURCE_D2PCLK2;

Is “RCC_USART1CLKSOURCE_D2PCLK2�? also valid for UART2 ? I can’t find a “RCC_USART2CLKSOURCE_D2PCLK2�? in file stm32h7xx_hal_rcc_ex.h, so am wondering about this also.

3 REPLIES 3

> Other STM microprocessor datasheets include a table specifically listing peripheral request channel v stream number, but not this microprocessor (as far as I can tell although it might be in a different format ?).

Those "other STM32" have a fixed relationship between the DMA request signals coming from individual peripherals, to individual DMA streams(*) (given by how the hardware was wired when the chip was designed). 'H7 (and some other newer STM32) have a DMAMUX unit instead, allowing to assign *any* of the dozens of DMA request sources to one of the few DMA streams freely. So, then there's a fixed DMAMUX-channel->DMA-stream relationship, but a wide-input multiplexer in each DMAMUX-channel, so that then you can arbitrarily choose, which DMA-stream are you going to use and set its respective DMAMUX-channel as per your requirement. Read the DMAMUX chapter in RM, it's enough to read its beginning, later on it gets a bit advanced and confusing for beginners.

> in file stm32h7xx_hal_rcc_ex.h

Cube/HAL is by no means authoritative or free of bugs. Fix it,, or just don't use it.

JW

---

(*) confusingly called channels when it comes to the simpler single-port DMA (in lower-end STM32, and in 'H7 as BDMA)

TMA1of3
Associate III

Thank-you very much for your feedback, Jan – much appreciated.

Ok, so I now understand that any stream can be chosen for this STM32H743 micro. The existing Uart1 Tx implementation is using DMA2_Stream7 while the associated Rx implementation takes DMA2_Stream5. I can’t see any other DMA2 Streams used in the code, so for this new Uart2 Tx/Rx implementation I believe I can choose DMA2_Stream3 and DMA2_Stream4.

As mentioned I don’t see anywhere in the code where these “DMA2_StreamX�? values are defined, but I guess it doesn’t matter.

As for my last question I understand about fixing it or just not using it, but … for the existing Uart1/Dma setup the code has RCC_PeriphClkInit.Usart16ClockSelection = RCC_USART1CLKSOURCE_D2PCLK2 (this value can be found in a hal file) but I don’t know if this same clock source is valid for the Uart2 in the same type of Dma application ? Do you know (or anyone else reading this), please ?

There’s no RCC_USART2CLKSOURCE_D2PCLK2 in the any of the hal files, but there is a RCC_USART2CLKSOURCE_D2PCLK1 which I’m guessing could be the correct choice, but where is this confirmed in the datasheet/reference manual ?

Cube among other things presents a useless intermediate layer between your program and the authoritative documentation in RM. It is open source, so you can look up how do the haphazardly defined Cube symbols map into the relatively systematic CMSIS-mandated-device-header symbols and then those into the values given in RM.

JW