Implement UART Transmit in DMA mode correct way
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-11-29 4:38 AM
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
- Labels:
-
DMA
-
STM32F7 Series
-
UART-USART
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-11-29 5:06 AM
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)
{
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-11-29 5:15 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-11-29 5:55 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-11-29 6:20 AM
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().
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-11-30 12:01 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-12-01 9:50 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-12-01 9:51 PM
First transmission has data output as required.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-12-01 11:34 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-12-01 11:58 PM
