AnsweredAssumed Answered

stm32f767 and UART DMA IT (interrupts)

Question asked by Mikolaj Z on Jan 24, 2017
Latest reply on Jan 26, 2017 by Guenael Cadier

Hi,

How to use UART in DMA mode with interrupts IT.

 

I use the next code to transmit, and it works perfect. 

HAL_DMA_Start_IT(&hdma_usart3_tx, (uint32_t)msg, (uint32_t)&huart3.Instance->TDR, strlen(msg));
huart3.Instance->CR3 |= USART_CR3_DMAT; // DMAT: DMA enable transmitter

 

But receive Rx doesnt work

 

HAL_DMA_Start_IT(&hdma_usart3_rx, (uint32_t)&huart3.Instance->RDR, (uint32_t)uRxBuff, 8);
huart3.Instance->CR3 |= USART_CR3_DMAR; // DMA enable receiver

 

DMA config:

/* Peripheral DMA init*/

hdma_usart3_rx.Instance = DMA1_Stream1;
hdma_usart3_rx.Init.Channel = DMA_CHANNEL_4;
hdma_usart3_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;
hdma_usart3_rx.Init.PeriphInc = DMA_PINC_DISABLE;
hdma_usart3_rx.Init.MemInc = DMA_MINC_ENABLE;
hdma_usart3_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
hdma_usart3_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
hdma_usart3_rx.Init.Mode = DMA_NORMAL;
hdma_usart3_rx.Init.Priority = DMA_PRIORITY_LOW;
hdma_usart3_rx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;

hdma_usart3_rx.XferCpltCallback = &DMAReceiveComplete;

if (HAL_DMA_Init(&hdma_usart3_rx) != HAL_OK)
{
Error_Handler();
}

__HAL_LINKDMA(huart,hdmarx,hdma_usart3_rx);

hdma_usart3_tx.Instance = DMA1_Stream3;
hdma_usart3_tx.Init.Channel = DMA_CHANNEL_4;
hdma_usart3_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
hdma_usart3_tx.Init.PeriphInc = DMA_PINC_DISABLE;
hdma_usart3_tx.Init.MemInc = DMA_MINC_ENABLE;
hdma_usart3_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
hdma_usart3_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
hdma_usart3_tx.Init.Mode = DMA_NORMAL;
hdma_usart3_tx.Init.Priority = DMA_PRIORITY_LOW;
hdma_usart3_tx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;

hdma_usart3_tx.XferCpltCallback = &DMATransferComplete;

if (HAL_DMA_Init(&hdma_usart3_tx) != HAL_OK)
{
Error_Handler();
}

__HAL_LINKDMA(huart,hdmatx,hdma_usart3_tx);

Outcomes