2023-09-19 09:29 AM
I am trying to receive data from one device and transfer it to another via UART DMA. I created a function for this using hal dma receive, waiting for the uart state becomes ready and then Hal dma transmit, then waiting for the uart state to be ready.
which works when calling the function the first time. However, a DMA transfer error or a UART overrun error is asserted the second time I call it during the receive part. Any ideas?
What I have tried:
I had tried to see if a regular receive would work, but I experience a timeout on the second call.
I had tried putting the UART init() for the device I am receiving from in my function. This allows me to receive the data when calling the function multiple times and fixes the problem. However, I do not think that reinitializing the UART every time is good practice.
So I am not sure what the problem is for the UART involving the device I am receiving from.
2023-09-19 09:36 AM - edited 2023-09-19 10:02 AM
Hello @STMGuitartune68
I suggest you to:
Best regards.
II
2023-09-19 09:45 AM - edited 2023-09-19 11:19 AM
Ignoring the obvious and non-helpful comment above,[EDIT: He edited his post above to be more helpful] post your relevant code (make sure to use the code tags when pasting your code - the button looks like "</>".
2023-09-19 10:10 AM
if(HAL_UART_Transmit_DMA(&huart2, (uint8_t*)aTxStartMessage, TXSTARTMESSAGESIZE)!= HAL_OK)
{
Error_Handler();
}
while (HAL_UART_GetState(&huart2) != HAL_UART_STATE_READY)
{
}
if (HAL_UART_Receive_DMA(&huart1, aRxBuffer, RXBUFFERSIZE) != HAL_OK)
{
Error_Handler();
}
while (HAL_UART_GetState(&huart1) != HAL_UART_STATE_READY)
{
}
if (HAL_UART_Transmit_DMA(&huart2, (uint8_t *)aRxBuffer, RXBUFFERSIZE) != HAL_OK)
{
Error_Handler();
}
while (HAL_UART_GetState(&huart2) != HAL_UART_STATE_READY)
{
}
2023-09-19 11:25 AM
Is the incoming data really discrete packets/groups of bytes (RXBUFFERSIZE), with pauses between them? If there are no pauses between incoming data, your scheme will not work.
In general it is better (more robust) to run the receive DMA in circular mode and leave it always running (with a "big" buffer, at least twice the largest packet you expect to receive. Then periodically see how full that buffer is and transmit that chunk of data out the other UART. See https://github.com/MaJerle/stm32-usart-uart-dma-rx-tx for good examples of using DMA and circular buffers.