cancel
Showing results for 
Search instead for 
Did you mean: 

BUG report: HAL STM32F1xx UART DMA never call TX complete call back

dandan91
Associate
Posted on June 22, 2016 at 14:34

I found this with the latest HAL come with the cubemx 15.1

STM32F1 1.4.0

UART_DMATransmitCplt never call 

HAL_UART_TxCpltCallback, it also did not change the

uart->State cause the following uart transmit return with error

as busy.

It does not make sense that only circular mode will receive

DMA complete callback.

I use this patch to fix it.

diff --git a/cubef1/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_uart.c b/cubef1/Drivers/STM32F1xx_HAL_Dr

iver/Src/stm32f1xx_hal_uart.c

index 600d936..9ab9a6e 100644

--- a/cubef1/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_uart.c

+++ b/cubef1/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_uart.c

@@ -1563,12 +1563,20 @@ static void UART_DMATransmitCplt(DMA_HandleTypeDef *hdma)

 

     /* Enable the UART Transmit Complete Interrupt */    

     __HAL_UART_ENABLE_IT(huart, UART_IT_TC);

+^M

+    /* Check if a transmit process is ongoing or not */^M

+    if(huart->State == HAL_UART_STATE_BUSY_TX_RX) ^M

+    {^M

+      huart->State = HAL_UART_STATE_BUSY_RX;^M

+    }^M

+    else^M

+    {^M

+      huart->State = HAL_UART_STATE_READY;^M

+    }^M

+^M

   }

   /* DMA Circular mode */

-  else

-  {

-    HAL_UART_TxCpltCallback(huart);

-  }

+  HAL_UART_TxCpltCallback(huart);^M

 }

 

 /**

2 REPLIES 2
slimen
Senior
Posted on June 23, 2016 at 10:56

Hi

This is not a bug, adding the USARTx_ IRQHandler inside the stm32f1xx_it.c file should resolve this issue:

void USARTx_IRQHandler(void)

{

  HAL_UART_IRQHandler(&UartHandle);

}

I suggest you refer to USART example using DMA under this path, it may be helpful:

 STM32Cube_FW_F1_V1.4.0\Projects\STM32VL-Discovery\Examples\UART\UART_TwoBoards_ComDMA

For more details , you can refer to the

http://www.st.com/content/ccc/resource/technical/document/reference_manual/9b/53/39/1c/f7/01/4a/79/DM00119316.pdf/files/DM00119316.pdf/jcr:content/translations/en.DM00119316.pdf

in (19.3.13 Continuous communication using DMA) paragraph.

Regards
dandan91
Associate
Posted on June 23, 2016 at 18:25

Thanks. That seems work when I enable UART interrupt in CubeMX.

However, it means that I can't not use UART DMA mode without enable

UART interrupt handler. It is a CubeMX bug then.

Because I generated the code from CubeMX. CubeMX automatically

enable DMA interrupt if I select DMA. Base on your feed back,

the HAL layer will need UART interrupt handler to make the DMA work.

The correct behavior for CubeMX should automatically enable UART

interrupt as well.

Does that make sense?