2016-11-08 02:23 AM
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.2016-11-08 03:11 AM
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. JW2016-11-08 10:23 AM