2026-01-04 1:35 AM
Can i use UART + DMA ( normal ) + RTO ? I try to add RTO but when activate RTOE bit the DMA buffer stops fills .
I take interrupt with active RTOF , stop DMA , but nothing in buffer !?
I use stm32H7 with hardware implemented RTO. Can some one to give working example ?
Solved! Go to Solution.
2026-01-08 5:30 AM
Hello @Brussl
I did not fully catch your issue.
Did you make sure to implement all the added code sequences?
USART3_IRQHandler.
/* USER CODE END USART3_IRQn 0 */
if ((huart3.Instance->ISR & USART_ISR_RTOF) != 0)
{
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_SET); // Set PB14 (LED ON)
HAL_UART_DMAStop(&huart3);
uint16_t received_len = RX_BUFFER_SIZE - __HAL_DMA_GET_COUNTER(huart3.hdmarx);
HAL_UART_Receive_DMA(&huart3, RxData, RX_BUFFER_SIZE);
}
else
{
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_RESET);
}
HAL_UART_IRQHandler(&huart3);
/* USER CODE BEGIN USART3_IRQn 1 */
in main.c
/* USER CODE BEGIN 2 */
HAL_UART_Receive_DMA(&huart3, RxData, RX_BUFFER_SIZE);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
int len = sprintf((char*)TxData, "%u ", txCounter++);
HAL_UART_Transmit_DMA(&huart3, TxData, len);
HAL_Delay(5000);
}
/* USER CODE END 3 */
in USART3_UART_Init(void) in main.c
/* USER CODE BEGIN USART3_Init 2 */
huart3.Instance->RTOR = 10;
__HAL_UART_ENABLE_IT(&huart3, UART_IT_RTO);
huart3.Instance->CR2 |= USART_CR2_RTOEN;
HAL_NVIC_SetPriority(USART3_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(USART3_IRQn);
/* USER CODE END USART3_Init 2 */
However, I recreated the project on the STM32H743, as you did, to determine if any problems occurred. The RTOF bit was set when the RTOR register reached 0, even without any activity on USART3.
I am going to attach the project so you can use it as a reference, if you want.
Hope this helps you find the solution.
Gyessine
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.
2026-01-05 7:10 AM
Hello @Brussl
For now, I suspect that there is a mistake in your configuration.
Check the RTOR register content.
You might be setting the RTO field to a value that is not reached.
I tried to replicate your issue on an STM32H745, as you did not specify the STM32H7 device you are using.
You can try this approach or use it as a reference. Porting it should not be difficult.
To test it, connect the PD8 pin to the PD9 pin to attach USART3 TX to USART3 RX.
When the RTOF bit is set, the PB14 pin (user LED3) is set.
Set a breakpoint at the following line of code to ensure you do not miss the RTOF bit being set:
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_SET);
You can visualize this using the SFR window.
The project is configured to transmit incrementing numbers every four seconds(you can see it using a serial monitor).
You can see that RX receives the number using the live expression buffer RXdata, and RTOF is 0.
After the RTO time elapses, user LED3 turns on, and the RTOF bit is set. This is especially visible if you set a breakpoint in the mentioned line in the USART3_IRQHandler function.
I attached the project in the reply
Hope this helps you find the solution, if yes please accept it so it becomes visible for other users
Gyessine
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.
2026-01-07 2:41 PM
Hello , Gyessine . I check your code on stm32h743 and stm32H503 (with GPDMA1 ) in both case in DMA buffer come only one char other are 0x00.
My be i miss something ?
Can you check this by you ?
2026-01-08 5:30 AM
Hello @Brussl
I did not fully catch your issue.
Did you make sure to implement all the added code sequences?
USART3_IRQHandler.
/* USER CODE END USART3_IRQn 0 */
if ((huart3.Instance->ISR & USART_ISR_RTOF) != 0)
{
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_SET); // Set PB14 (LED ON)
HAL_UART_DMAStop(&huart3);
uint16_t received_len = RX_BUFFER_SIZE - __HAL_DMA_GET_COUNTER(huart3.hdmarx);
HAL_UART_Receive_DMA(&huart3, RxData, RX_BUFFER_SIZE);
}
else
{
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_RESET);
}
HAL_UART_IRQHandler(&huart3);
/* USER CODE BEGIN USART3_IRQn 1 */
in main.c
/* USER CODE BEGIN 2 */
HAL_UART_Receive_DMA(&huart3, RxData, RX_BUFFER_SIZE);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
int len = sprintf((char*)TxData, "%u ", txCounter++);
HAL_UART_Transmit_DMA(&huart3, TxData, len);
HAL_Delay(5000);
}
/* USER CODE END 3 */
in USART3_UART_Init(void) in main.c
/* USER CODE BEGIN USART3_Init 2 */
huart3.Instance->RTOR = 10;
__HAL_UART_ENABLE_IT(&huart3, UART_IT_RTO);
huart3.Instance->CR2 |= USART_CR2_RTOEN;
HAL_NVIC_SetPriority(USART3_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(USART3_IRQn);
/* USER CODE END USART3_Init 2 */
However, I recreated the project on the STM32H743, as you did, to determine if any problems occurred. The RTOF bit was set when the RTOR register reached 0, even without any activity on USART3.
I am going to attach the project so you can use it as a reference, if you want.
Hope this helps you find the solution.
Gyessine
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.
2026-01-08 8:00 AM
Hello , Gyessine. Do you sure about DMA save date in buffer? I have very strange situation. The counter of received bytes is real, but buffer is empty. I send on other UART length and write two bytes in DMA buffer to see how change it DMA, but is not changed.
uint8_t txt[20];
void USART2_IRQHandler(void)
{
/* USER CODE BEGIN USART2_IRQn 0 */
if ((huart2.Instance->ISR & USART_ISR_RTOF) != 0)
{
HAL_UART_DMAStop(&huart2);
__HAL_UART_CLEAR_FLAG(&huart2, UART_CLEAR_RTOF);
uint16_t received_len = DMA_BUFFER_SIZE - __HAL_DMA_GET_COUNTER(huart2.hdmarx);
//memcpy (&rx_buf, &rx_dma_buf, received_len );
uint16_t len = sprintf((char*)txt , "%u ", received_len );
HAL_UART_Transmit( &huart1, txt, len, HAL_MAX_DELAY);
HAL_UART_Transmit( &huart1, dma_buf ,DMA_BUFFER_SIZE , HAL_MAX_DELAY);
dma_buf[0]=0x35;
dma_buf[1]=0x37;
HAL_UART_Receive_DMA(&huart2, dma_buf, DMA_BUFFER_SIZE);
}
else
{
HAL_UART_Transmit( &huart1,"TE",3,HAL_MAX_DELAY);
}
/* USER CODE END USART2_IRQn 0 */
HAL_UART_IRQHandler(&huart2);
/* USER CODE BEGIN USART2_IRQn 1 */
/* USER CODE END USART2_IRQn 1 */
}
I check and memory increment is OK.
this is from serial monitor:
79 is real data length , 57 are bytes that can be changed if DMA write something in buffer.
2026-01-09 12:32 AM
hello @Brussl
Did you make sure that you wired the USART TX(PD8) pin to USART RX(PD9) pin in your board
Also, can you check if the RTOF bit is being set? you can use the method I explained in the previous replies
because the Rx data buffer is being filled from my side using the project I attached it to you
if all of this is done and the buffer is still empty, can you provide more details about your problem or a screenshot of how you noticed that it is empty
BR
Gyessine
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.
2026-01-13 8:06 AM
Hello @Brussl
If I understood you correctly, you are encountering a new issue.
Your primary question was: "Can someone provide a working example?"
Your question now is: "If I set RTOEN, the buffer stops filling."
I really recommend posting your new issue in a new thread and mark one of the replies as the solution if a reply helps you solve your first question, so it can serve as a reference for other users.
BR
Gyessine
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.