2023-02-07 07:07 AM
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
2023-02-07 10:38 AM
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.