cancel
Showing results for 
Search instead for 
Did you mean: 

STM32WL DMA transfer error | UART Overrun error when receiving

STMGuitartune68
Associate II

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.

4 REPLIES 4
Issamos
Lead II

Hello @STMGuitartune68 

I suggest you to:

  • Take a look at this example of UART DMA (communication between 2 boards)for STM32WL 
  • Debug your code. That will help you to find where the issue is.
  • Post your code her so our community members can help you if there's an issue in the code.

Best regards.

II

Bob S
Principal

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 "</>".

STMGuitartune68
Associate II
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)
	  {
	  }
Bob S
Principal

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.