cancel
Showing results for 
Search instead for 
Did you mean: 

Implement UART Transmit in DMA mode correct way

phenom
Associate II

I am using stm32f779I eval kit. I am using example UART_HyperTerminal_DMA by en.stm32cubef7.

I am trying to implement UART in DMA mode to transmit a simple string.

So I have used CubeMX to generate the code and I have configured UART1 TX DMA in normal mode.

Whenever I run the code in debugging mode, I see the first time I attemp to send the string, it works ok and sends the string.

But I couldn't send a second transmission.

Can any one please suggest the correct way to use Uart Tx in DMA mode? How can I send successive strings one after another?

E.g. :

i used

 if(HAL_UART_Transmit_DMA(&UartHandle, (uint8_t*)aTxStartMessage, TXSTARTMESSAGESIZE-10)!= HAL_OK)

 {

  /* Transfer error in transmission process */

  Error_Handler();

 }

 if(HAL_UART_Transmit_DMA(&UartHandle, (uint8_t*)aTxStartMessage, TXSTARTMESSAGESIZE-10)!= HAL_OK)

 {

  /* Transfer error in transmission process */

  Error_Handler();

 }

2 times HAL_UART_Transmit_DMA() API. 2nd time API has huart->gState == HAL_UART_STATE_BUSY_TX

14 REPLIES 14
Jame DEV
Associate III

Check this one.

https://community.st.com/s/question/0D50X0000BcPXk2SQG/32f746-usart-dma-with-stemwin-not-working

and maybe you forget to wait for uart DMA working. If uart DMA is not finished the first message. the huart is in busy state so the second message will not work. try add this code before next transmit.

 while (HAL_UART_GetState(&UartHandle) != HAL_UART_STATE_READY)

 {

 }

phenom
Associate II

My issue is same as

https://community.st.com/s/question/0D50X00009XkgtY/dma-uart-with-hal-remain-busy-bug

but solution provided in this link is not working for me.

Already  HAL_UART_IRQHandler()  enabled.

Hi,

I have added code as suggested by you:

Print()

{

HAL_UART_Transmit_DMA(&UartHandle, (uint8_t *)ch, len);

  while (HAL_UART_GetState(&UartHandle) != HAL_UART_STATE_READY)

  {

  }

}

 But after HAL_UART_Transmit_DMA() execution pointer goes to

 void DMA2_Stream7_IRQHandler(void)

{

  HAL_DMA_IRQHandler(UartHandle.hdmatx);

};

in stm32f7xx_it.c and then comes back to 

  while (HAL_UART_GetState(&UartHandle) != HAL_UART_STATE_READY)

  {

  }

Here while loop never ends.

Did you check the first signal transmission . Do it have data output? if it's not.

Please check MX_DMA_Init() function. you have to call this function before MX_USARTx_UART_Init().

Do you observe the Tx pin using an oscilloscope/LA? Is there any activity related to the second "batch" of data?

Read out and check the USART and relevant DMA registers content.

JW

Hi,

I have added code as suggested by you:

Print()

{

HAL_UART_Transmit_DMA(&UartHandle, (uint8_t *)ch, len);

  while (HAL_UART_GetState(&UartHandle) != HAL_UART_STATE_READY)

  {

  }

}

 But after HAL_UART_Transmit_DMA() execution pointer goes to

 void DMA2_Stream7_IRQHandler(void)

{

  HAL_DMA_IRQHandler(UartHandle.hdmatx);

};

in stm32f7xx_it.c and then comes back to 

  while (HAL_UART_GetState(&UartHandle) != HAL_UART_STATE_READY)

  {

  }

Here while loop never ends.

First transmission has data output as required.

Then try polling UART (HAL_UART_Transmit) if it's work then try HAL_UART_Transmit_IT.

If both are works. Then you do something wrong with DMA configuration.

Try to start a new project and using cudeMX to gen the code.

Try this.