Right now, I'm attempting to read a sizable amount of data from UART0. I can read all the data as expected in simple polling mode, directly on the UART data + flag registers. But the DMA engine copies extra zeroes for every byte when I try to use it to achieve the same result. As an illustration, suppose I get the bytes
Code: Select All
when the values in memory are 0x12, 0x34, 0x56, 0x78, etc.
Code: Select all
120000000, 340000000, 560000000,0x78000000, etc.
if the DMA transfer lasts long enough (I assume this is because it copies the extra zeroes, as it appears to truncate the entire transmitted bytes). Upon closer inspection, it appears that these additional zeroes result from copying the whole 32-bit data register from the UART rather than just the low byte containing the data. Right now, my transfers are configured to move N bytes from the data register address of the UART peripheral to a memory buffer, with destination increment enabled, source DREQ enabled, and source increment disabled. Is it possible to make the DMA engine read one byte at a time in fixed-source mode ?
Using DMA to read UART0 in problems
To make the DMA engine read one byte at a time from the UART data register, you need to configure the DMA transfer to use byte-sized transactions instead of word-sized transactions.
This involves setting the data width for the source (UART data register) and the destination (memory buffer) to 8 bits.
Here is the general way I follow.
DMA Configuration
1. Source Data Width: Set to 8 bits (1 byte)
2. Destination Data Width: Set to 8 bits (1 byte)
3. Source Address: Fixed (the address of the UART data register)
4. Destination Address: Incrementing (the address of the memory buffer)
5. Transfer Size: Set to the number of bytes you want to transfer
Ensure that the control registers for the DMA are configured to transfer one byte at a time. And set the appropriate flags for byte-sized transfers.
But it would be best to keep a few things in mind: Ensure that the UART peripheral is properly configured and enabled to generate DMA requests when data is available.
This involves setting the data width for the source (UART data register) and the destination (memory buffer) to 8 bits.
Here is the general way I follow.
DMA Configuration
1. Source Data Width: Set to 8 bits (1 byte)
2. Destination Data Width: Set to 8 bits (1 byte)
3. Source Address: Fixed (the address of the UART data register)
4. Destination Address: Incrementing (the address of the memory buffer)
5. Transfer Size: Set to the number of bytes you want to transfer
Ensure that the control registers for the DMA are configured to transfer one byte at a time. And set the appropriate flags for byte-sized transfers.
But it would be best to keep a few things in mind: Ensure that the UART peripheral is properly configured and enabled to generate DMA requests when data is available.