cancel
Showing results for 
Search instead for 
Did you mean: 

Problems with UART transfer using DMA on STM32L471RGT6

rwils.1
Associate III

Hi ,

I am using DMA/serial port transfer with RTS /CTS handshaking to transfer between 490 and 506 bytes from variable dma_buffer. The byte stream is terminated with \r\n\0 . the code is below :

 while (transmit_complete_flag !=1 ){;}  // wait here until previous DMA transfer is complete
HAL_UART_Transmit_DMA(&huart4,(uint8_t*)dma_buffer, strlen(dma_buffer));

Before calling the function I am waiting for transmit complete to make sure that the previous DMA transmission has completed. transmit_complete is set in the HAL_UART_TxCpltCallback function.

void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
{
    if (huart->Instance == UART4)  // change USART instance
    {
       transmit_complete_flag=1;// Transmit complete 
    }
}

The code works for the majority of the time but occasionally - say once in 10,000 bytes transferred, the last 2 or 3 bytes (varies) are not transmitted. I assumed that there was some problem with dma_buffer not including the last three characters so I replaced the DMA transfer with the regular serial function:

	HAL_UART_Transmit(&huart4,(uint8_t*)dma_buffer, strlen(dma_buffer),HAL_MAX_DELAY);

This never fails, which leads me to think that it is the DMA transfer that is interrupted on occasion and not a failure to populate dma_buffer correctly.

I am certain that the transfer is not completing correctly as I am monitoring and logging the serial port output using Terraterm.

My question to the group is what mechanisms might cause early termination of the DMA transfer? given the random and rare event it makes me suspect some interference from an interrupt function but I can't think of what function that would be. I am also using DMA transfers to write to an SD card while the serial port transfer is taking place, is it possible that these two DMA calls / processes are interfering with each other?

Thanks in advance.

Richard

1 REPLY 1
rwils.1
Associate III

There was a very simple bug in the higher level code that caused this issue. It is nothing to do with the DMA process. Problem solved.