cancel
Showing results for 
Search instead for 
Did you mean: 

DMA_MDATAALIGN_HALFWORD for stm32f407 usart seems not working (porting from stm32f103)

tmtlib
Associate II
Posted on November 08, 2016 at 11:23

I have code which is working on STM32F103:

    hdma_usart1_rx.Instance = DMA1_Channel5;

    hdma_usart1_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;

    hdma_usart1_rx.Init.PeriphInc = DMA_PINC_DISABLE;

    hdma_usart1_rx.Init.MemInc = DMA_MINC_ENABLE;

    hdma_usart1_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;

    hdma_usart1_rx.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;

    hdma_usart1_rx.Init.Mode = DMA_CIRCULAR;

    hdma_usart1_rx.Init.Priority = DMA_PRIORITY_LOW;

    HAL_DMA_Init(&hdma_usart1_rx);

I use HALFWORD to fill TWO bytes in memory if ONE byte is received on USART.

Unused part is automatically filled with zeroes by STM32F103 hardware.

I am doing it for special purpose and it works well.

Now I am porting my code to STM32F407 (usart2, becaue usar1 have capacitor on discovery board). First problem is that i can't choose HALFWORD in CubeMX for f407. There are some dma fifo settings i am not familiar with, not sure I need it.

Here is ported code:

    hdma_usart2_rx.Instance = DMA1_Stream5;

    hdma_usart2_rx.Init.Channel = DMA_CHANNEL_4;

    hdma_usart2_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;

    hdma_usart2_rx.Init.PeriphInc = DMA_PINC_DISABLE;

    hdma_usart2_rx.Init.MemInc = DMA_MINC_ENABLE;

    hdma_usart2_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;

    hdma_usart2_rx.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;

    hdma_usart2_rx.Init.Mode = DMA_CIRCULAR;

    hdma_usart2_rx.Init.Priority = DMA_PRIORITY_LOW;

    hdma_usart2_rx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;

It behaves not as I expected.

2 REPLIES 2
Posted on November 08, 2016 at 12:11

The DMA module in 'F4 is different from that in 'F1 and does not perform the ''zero stuffing''.

What you can try to do is to set both peripheral and memory to halfword, relying on USART->DR returning zeros in MSB.

JW

tmtlib
Associate II
Posted on November 08, 2016 at 19:23

Thank you! I changed both to halfword and it works now on stm32f407 as well!