2024-06-03 03:41 AM
Hi all,
I write to you because I would like to understand if it is really necessary to use an RTOS. I always develop projects with different ST processors (F4 and F7) without using RTOS. In those projects the F4/F7 processors communicate with many hardware components using SPI, I2C, RS232, GPIO and PWM. Now I need to increase the communication speed on the RS232, because I need do send few mega bytes of data every second and for that reason I need to integrate the USB with Full Speed or High Speed. Then in another new project I have to handle also a small OLED display. For all these reasons I'm thinking about the possibility to use Azure RTOS that seems well integrated with CubeMX, but I do not know which benefits I could obtain and if I could have some side effects both from performance point of view and also from developing time point of view.
In this situation is it really necessary a RTOS?
Which advantages and disadvantages could I have using a RTOS?
Let me know!
Thank you very much for the support.
Solved! Go to Solution.
2024-06-03 10:54 AM
The rules of thumb that I (and other people in the embedded community) use is, if you have some sort of communications protocol going, use an RTOS. If you're doing graphics, use an RTOS.
Once you get a bunch of experience, you'll think "this customer really has no idea of the scope of this project and it's going to balloon in scope really soon now", use an RTOS.
But you could also not use an RTOS, add a feature here, another device there, rebalance the timing due to coupling that wasn't intended, decide that you need just a little bit of a kind of a scheduler looking thing, and suddenly you've written a feature poor RTOS and you say "I should have used an RTOS".
I tend to use an RTOS unless I can see that the project is going to be well bounded, small, and heavily constrained.
The amount of effort that goes into writing code goes exponential with complexity. So if you can break up your code into multiple simple cooperating tasks, you avoid complexity and avoid having your system have exponential effort growth. I've done this by using multiple processors, each running small simple programs. But you get the same effect from using an RTOS. Each task/thread/process is simple, well defined, and small, avoiding ballooning complexity.
Recently I read an article about the software architectures that actually work for multi-processor, high scalability, high performance systems. It pretty much came down to small processes and message passing. Lots and lots of message passing.
So, you can get experience in non-embedded best practices and avoid driving yourself crazy by using RTOS'
2024-06-03 03:59 AM
Using RTOS is a matter of preference, not necessity.
You can manage multiple jobs without using RTOS using interrupts etc.
The advantage of RTOS is that it allows you to develop the application in smaller parts. I think it's a trade-off worth spending some processor power and RAM on.
There are a lot of new concepts to learn in RTOS, such as semaphore, mutex etc. Once learned you will tend to use it on very simple projects as well.
2024-06-03 04:01 AM
No, an RTOS is not needed.
You can achieve the same thing with a polling loop + interrupts + DMA. Poll for events in a main loop and handle them there. Handle high priority events in an interrupt (to prevent RX fifo from filling up) and use the DMA to reduce number of interrupts and CPU load.
However this often requires you to write Finite State Machines since no "process" is allowed to be blocking too long.
Sometimes that requires you to rewrite third party code or library code.
Using an RTOS basically converts every single function into a statemachine since every thread can be interrupted at any point and return where it left off. So an RTOS can be convenient.
An RTOS does add overhead in time since task switching takes time and processing tick event takes time too. Furthermore an RTOS needs a lot more memory since every thread has its own stack. This also increases the risks of a stackoverflow. Even a simple printf can consume a lot of memory and lead to a stack overflow.
I have used FreeRTOS and I have done many projects with just a loop + interrupts + DMA. Using a loop is the best in most cases in my opinion, but it may take more time in planning things.
In either case I recommend you draw timing diagrams on a piece of paper of all the processes. And set some GPIO-pins at certain events so you can see the actual timing with a logic analyzer and compare it with your design.
2024-06-03 06:27 AM
@ennioaloisini wrote:Hi all,
I write to you because I would like to understand if it is really necessary to use an RTOS. I always develop projects with different ST processors (F4 and F7) without using RTOS.
Surely, you've answered your own question there - you yourself have demonstrated in your own projects that it is not necessary to use an RTOS!
The benefits of an RTOS come as projects get more complex, so it gets more difficult to manually manage all the different parts - especially when adding more complex peripherals like USB and graphic displays.
2024-06-03 07:39 AM
Hi @Muhammed Güler ,
thank you very much for the answer.
What do you mean that RTOS allows to develop the application in smaller parts?
In case of use of a GUI application on a small LCD, does RTOS became a must?
Regarding Azure RTOS or Free RTOS, is there a good guide, or video, or turorial that explain step by step how to create a project?
Let me know!
thank you very much for the support!
2024-06-03 07:42 AM
thank you very much for the feedback.
In one project I just need to change the RS232 with USB and maybe it could be more conveient to do not use an RTOS, but in another one I will have to handle a small OLED with a TouchGFX application and in that case I think that it could be better to use an RTOS. Is it correct?
Let me know!
Thank you very much for the support.
2024-06-03 07:44 AM
Hi @Andrew Neil ,
thank you very much for the answer.
Now I have to add USB in one application and in another one both USB and graphic display. Do you think that it is better to switch to an RTOS?
I saw that ST pushes a lot Azure RTOS. It is easy to use and robust / safe like SafeRTOS?
Let me know!
Thank you very much for the support!
2024-06-03 08:17 AM
@ennioaloisini wrote:Now I have to add USB in one application and in another one both USB and graphic display. Do you think that it is better to switch to an RTOS?
Can you clearly see how you'd manage the full app (both USB and graphics) without an RTOS ?
If you feel that's getting "too complicated", then it's probably time to switch.
If you are going to switch, it's probably a good idea to just switch your existing project first, with no other changes - don't complicate the issue with knew & unknown code!
Then I would suggest that you just add the USB.
Finally, add the graphics to the USB.
It's always good to move in small steps - keep the number of unknowns to a minimum!
2024-06-03 08:19 AM
Thank you very much for the good advices.
2024-06-03 08:22 AM - edited 2024-06-03 08:22 AM
@ennioaloisini wrote:What do you mean that RTOS allows to develop the application in smaller parts?
One of the key features of an RTOS is to isolate the various parts of the application into separate Tasks.
This makes it easier to focus on just the issues within a Task - rather than having to juggle all the functionality of the whole app at once.
In other words, it makes your code more modular; it reduces coupling between different parts of your code:
https://en.wikipedia.org/wiki/Coupling_(computer_programming)
and, hopefully, allows you to increase cohesion within your Tasks: