cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L412 USART transmit using DMA drops characters, must use HALFWORD alignment

GKerc.1
Associate II

I set up DMA for a USART transmit operation with an ST32L412. Settings are 115200 baud, 8 data bits, no parity. I thought everything was working until I noticed the third character in all my outbound data not showing up. It turns out the default BYTE memory alignment from the CUBE is the problem. BYTE alignment doesn't work with the UART. You have to use HALFWORD alignment for both the "PeriphDataAlignment" and "MemDataAlignment" fields in the UART MSP initialization routine. You can select this in the CUBE interface. You also have to copy your outbound string into an array of 16-bit (short int) and only use the lower 8 bits. Anyone else notice this? Is this documented anywhere?

rgds,

Gary

2 REPLIES 2
Guenael Cadier
ST Employee

Hell @GKerc.1​ 

In my opinion, in your configuration (8 data bits), it is expected to be working with DMA setting = byte alignment.

For reference, in L4 Firmware package, UART+DMA examples are provided using same configuration (8 data bits + DMA alignments set to Byte).

See for instance : Projects\NUCLEO-L476RG\Examples\UART\UART_TwoBoards_ComDMA

(example is not CubeMx generated, but is using same configuration).

If a bug exists, it is unknown, I think.

Regards

Guenael

GKerc.1
Associate II

Thank you for the reply Guenael. I agree that byte alignment should work. But I tried this at multiple baud rates and the result is always the same. The third character of the outbound payload is not transmitted. The only thing slightly different about my project vs. the example is that I'm using DMA controller number 2. DMA controller number 1 is assigned to SPI1 and SPI2 in my hardware. I am using STM32L412CBU, 48 pin package. You guys might want to test this as it could be a bug in either the HAL firmware or the silicon. For now, my HALFWORD solutions seems to work and is very easy to implement.

rgds,

Gary