cancel
Showing results for 
Search instead for 
Did you mean: 

UART with DMA RX/TX

Davood_Kesha
Associate II

Dear ST's experts,

I want to send/receive data through UART between STM32 and PC. The data must be sent to PC every 500ms and then STM32 receive data from PC. I have configured UART2 with DMA in circular mode. I am using the function HAL_UART_TxCpltCallback to pause the UART (HAL_UART_DMAPause(&huart2);) to send data every 500ms. My problem is that when I use the above function, receiving data does not work properly.
How I can solve the problem?
Should I use DMA in normal mode for TX? 

2 REPLIES 2
Saket_Om
ST Employee

Hello @Davood_Kesha 

Please refer to the example below: 

STM32CubeH7/Projects/STM32H735G-DK/Examples/UART/UART_Printf at master · STMicroelectronics/STM32CubeH7 · GitHub

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
Saket_Om

USART Rx/Tx DMA can occur concurrently.

Don't pause or block in interrupt handlers, or callbacks generated from interrupts, ie within interrupt context.

Blocking in interrupt context is very bad form.

If you want to initiate transfers on a periodic basis, start them in TIM callbacks, or count off time related to SysTick, ie initiate every 500 calls to SysTick_Handler()

Or pace within your main() loop

uint32_t start = HAL_GetTick();

while(1)
{
  if ((HAL_GetTick() - start) >= 500)
  {
    // Do 500ms Task
    start += 500;
  }
}
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..