cancel
Showing results for 
Search instead for 
Did you mean: 

UART DMA Rx/Tx

DJ1
Associate III

I am working on STM32F401RE, transmitting data via UART using DMA 1(channel 6) , also i want to receive data using DMA 1 (channel 5). I want to use the DMA in single byte transfers in direct mode. Can you help me how to do so correctly because i tried following single byte transfers from the reference manual but it didn't work. I am getting output for the same in Circular mode. Can any share proper procedure for the same.

11 REPLIES 11
	// MSIZE 1 byte
	DMA1->DMA_S6CR &= ~(3 << 13);
	// PSIZE 1 byte
	DMA1->DMA_S6CR &= ~(3 << 12);

@DJ​ Watch out. PSIZE runs from 11 to 12 - not 12 to 13.

There are lots of useful #defines in e.g. #include <stm32f4xx.h> so the sort of thing I do is:

DMA1->DMA_S6CR = (channel_number * DMA_SxCR_CHSEL_0) | DMA_SxCR_PL_1 | DMA_SxCR_MINC | DMA_SxCR_DIR_0 | DMA_SxCR_TCIE;

It's possible you've made other errors in your register accesses, so please re-code making use of those #defines to see if it makes a difference.

I don't bother with the DMA FIFO at all. There might be some saving in terms of number of bus accesses, but UARTs are generally so slow that a few extra bus accesses won't have significant impact on the performance of your system.

Piranha
Chief II

The transmit with DMA is simple. When you have the data in the buffer, just set up a single DMA transfer. When that finishes, check the state of the buffer and, if necessary, set up another transfer. When the buffer overlaps, set the transfer to the end of the buffer and let the beginning of the buffer be handled by the next transfer.

DMA1->DMA_S6CR

You've made it worse. The DMA streams are effectively a separate peripheral instances. With the original definitions those can be swapped easily, but not possible with your implementation. I hope you do understand that unused definitions have no impact on the generated code. And, if still doing it, I would just cut out the unnecessary parts so that it can be easily reviewed and maintained later with merge tools.