Skip to main content
HanCheng Liu
Visitor II
Oct 22, 2017 2:13 PM UTC
Question

HAL_UART_Transmit_DMA() only work one time

Posted on October 22, 2017 at 16:13

I want to use  ' HAL_UART_Transmit_DMA(); ' to send data in DMA mode like this :

    char str_Hello[]='Hello\n';

    HAL_UART_Transmit_DMA(&huart1,(unsigned char *)str_Hello,strlen(str_Hello));

    HAL_Delay(500);

But transimit function only work one time(DMA is working under normal mode).

I found these in the definition of function 'HAL_UART_Transmit_DMA()' in 'stm32f1xx_hal_uart.c'

HAL_StatusTypeDef HAL_UART_Transmit_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)

{

  uint32_t *tmp;

  /* Check that a Tx process is not already ongoing */

  if(huart->gState == HAL_UART_STATE_READY)

{

......

huart->gState = HAL_UART_STATE_BUSY_TX;

.....

}

}

So, I try to manually set 'huart->gState' in my while loop like this

  char str_Hello[]='Hello\n';

  HAL_UART_Transmit_DMA(&huart1,(unsigned char *)str_Hello,strlen(str_Hello));

  HAL_Delay(500);

  huart1.gState = HAL_UART_STATE_READY

Although the problem was solved , but i think that it may not the correct way to solve this issue.

Anyone know how to handle it?

Thanks.

#uart #dma #hal #stm32f1
This topic has been closed for replies.

3 replies

Tesla DeLorean
Guru
Aug 10, 2018 4:32 PM UTC

Sorry, bumping old zombie unanswered threads off my feed

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
gilramon
Associate II
Jan 11, 2024 1:52 PM UTC

It's because you forgot to enable the interrupt of the UART that you work with in Cubemx.

Karl Yamashita
Super User
Jan 11, 2024 8:00 PM UTC

Did you assign a DMA channel to the Tx? 

 

Edit: Dang this is an old thread, lol.

If a reply has proven helpful, click on Accept as Solution so that it'll show at top of the post.CAN Jammer an open source CAN bus hacking toolCANableV3 Open Source