2017-10-25 02:53 AM
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?
2018-08-10 09:32 AM
Sorry, bumping old zombie unanswered threads off my feed
2018-08-28 07:31 AM
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.
2018-09-16 12:31 PM
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.
2018-09-16 01:35 PM
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.
2018-09-17 09:21 AM
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
2019-09-11 04:05 AM
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.
2021-02-08 01:46 AM
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.
2021-12-02 07:55 AM
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