Skip to main content
serdar onart
Visitor II
October 25, 2017
Question

HAL Library does not support UART Rx Timeout RTOR

  • October 25, 2017
  • 7 replies
  • 2785 views
Posted on October 25, 2017 at 11:53

Hi all,

I am using STM32L433, and checked the manual that it supports rx timout for the uart. I am using cubeMX v4.22.1 with Cube L4 firmware Package v1.9.0. I try to receive unknown sized data from UART3 but i do not want to get interrupt for every byte I receive. Therefore i searched for the issue, and i found USART_RTOR, which is perfect for my needs. İ try to use it but unfortunatel HAL library does not support this timeout register duties. I try to add these lines to the init part of uart

WRITE_REG

(huart3.

Instance

->RTOR,

3

);

SET_BIT

(huart3.

Instance

->CR1, USART_CR1_RTOIE);

SET_BIT

(huart3.

Instance

->CR2, UART_RECEIVER_TIMEOUT_ENABLE);

then i observe that RTOF flag is set, good news. But i can not find any IRQ triggered when this flag is set. Therefore i can not get interrupt when the receiver timeout occurs. Does anybody have the same issue? Or am i missing something. Furthermore, does the HAL developmend tem planning to add RTOR to the library?

    This topic has been closed for replies.

    7 replies

    Tesla DeLorean
    Guru
    August 10, 2018

    Sorry, bumping old zombie unanswered threads off my feed

    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
    myang.18
    Visitor II
    August 28, 2018

    SET_BIT(ModbusHandle.Instance->CR2, USART_CR2_RTOEN);

    SET_BIT(ModbusHandle.Instance->CR1, USART_CR1_RTOIE);

    WRITE_REG(ModbusHandle.Instance->RTOR,24/*3*/);

    Serdar bunu dene.

    Birde isterrupta girince bayragı sıfırla.

    Georg Doza
    Associate
    September 16, 2018

    Is this issue stil unsolved?

    Faced with this error when I tried to port software written for stm324F HAL.

    Tried zakayangin's solution but it doesn't work because HAL over writes USART_CR1_RTOIE somewhere else in the code and desired interrupt remains disabled.

    Tesla DeLorean
    Guru
    September 16, 2018

    Not really gained any traction in best part of a year, and we're several versions of HAL and CubeMX away on a different family of parts.

    The library source is provided in its entirety, if it doesn't work as desired, fix it, or replace it with a more elegant solution.

    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
    Georg Doza
    Associate
    September 17, 2018

    At the end I figure out how to solve this issue. The changes was necessary in the CMSIS driver too.

    Are there a public place where I can put my version in order to share it with others and to get a chance to discuss about it?

    Georg

    wuio
    Associate III
    September 11, 2019

    ST when will you add the option of handling interrupts from idle state and configurable timeout (RTOR) in HAL? This feature would be very useful.

    Jack3
    Senior
    February 8, 2021

    It's an old post already, but maybe sombody will hit this.

    Example with USART2:

    Configure RTO

    void USART2_Init_RTO_IRQ(void)
    {
     /* Enable receive timeout function, set CR2.RTOE */
     SET_BIT(huart2.Instance->CR2, USART_CR2_RTOEN);
     /* Enable receive timeout interrupt, set CR1.RTOIE */
     SET_BIT(huart2.Instance->CR1, USART_CR1_RTOIE);
     /* 
     * Fill the RTOR register with the length of timeout required,
     * in units of bit times:
     * Modbus-RTU uses 3.5 characters:
     * 3.5 bytes * 11 bits = 39
     */
     WRITE_REG(huart2.Instance->RTOR, 39); 
     /* Reset RTOF flag: */
     SET_BIT(huart2.Instance->ICR, USART_ICR_RTOCF);
    }

    In stm32..xx_it.c

    void USART2_IRQHandler(void)
    {
     if((__HAL_UART_GET_FLAG(&huart2, UART_FLAG_RXNE) != RESET) &&
     (__HAL_UART_GET_IT_SOURCE(&huart2, UART_IT_RXNE) != RESET))
     {
     /* Triggers after each byte received */
     }
     if((__HAL_UART_GET_FLAG(&huart2, UART_FLAG_TXE) != RESET) &&
     (__HAL_UART_GET_IT_SOURCE(&huart2, UART_IT_TXE) != RESET))
     {
     /* Triggers after each byte send */
     }
     if (__HAL_UART_GET_FLAG(&huart2, UART_FLAG_RTOF) != RESET)
     {
     /* Triggers after receive timeout (3.5 characters) */
     /* Reset RTOF flag: */
     SET_BIT(USART2->ICR, USART_ICR_RTOCF);
     }
     HAL_UART_IRQHandler(&huart2);
    }

    Jack.

    NSing.5
    Associate III
    December 2, 2021

    Thanks jack,

    your solution has helped me to solve my problem, i was struggling for RTOR interrupt from 3 days. just to clarify my doubt:

    1. which one is best to use for interrupt handling

    void USARTx_IRQHandler(void) or callback functions

    how they are different.

    once again thanks