Another USART question (modbus oriented)

Hello all.
It is my first time programming with an rtos, I alwyas programmed bare metal on small 8bit microprocessors, so please bear with me.
I need to develop the driver to communicate in modbus rtu with some other devices.
I already have the application layer that manages all the FCs and the data link layer, what is difficult to me is the pysical layer.
Modbus specs say that the end of frame is after a 3.5 char timeout.
Normally I would set up a software timer with overflow at 3.5 char duration, the USART interrupt to receive one byte and in the USART RX ISR handler I would save the byte in a buffer and reload the timer.
In the timer overflow ISR handler I would signal to the data link layer that the frame is complete and then the data link layer can grab the received buffer and use it.
Now, at the moment the data link layer I have is a function to which I need to pass a pointer to the received buffer and the application layer is a task.
How can I solve this using freeRTOS (or any rtos in general) and STM32 HAL?
I’m not asking to write the code, but I don’t know which “software architecture” I need to use, since it seems to me that rtos’s timers don’t work like that and I need some help.

Please correct any mistake I wrote and feel free to point me to some document I can read to educate myself.
I already read the freeRTOS manual and did some research on google.
Thanks.

I would (if the serial port doesn’t have a idle timeout function) receive data from the UART in an ISR into a received buffer, and have that kick a hardware timer that it programmed to generate an interrupt if it hasn’t been kicked for the 3.5 characters (it might need to be 4.5 if the 3.5 is the maximum gap from stop to start of the next character, as you are measuring stop to stop), and the timer interrupt is used to signal the reception task to get the data from the buffer.

Personally, I tend to bypass HAL libraries, and use them just as examples of the code needed to access the hardware, but I think they give you the ability to hook in a notification of receive data interrupt.

1 Like

That is what I usually would do, but I don’t understand how to do it with rtos timers…

I wouldn’t use the FreeRTOS timers, as they are likely too slow, measuring time in units of “Ticks”, which are going to be order of milliseconds, and a one tick “jitter” to them, so unless you are talking about Baud Rates of 9600 Baud or less, just not adequate (and 9600 Baud would be marginal and need 1ms Tick Rates). Most of the STM32 parts have a lot of internal hardware timers that are available for such purposes.

Ok, thanks for the info. I’ll look into it.