0
\$\begingroup\$
  1. Can someone explain in what situations is RTOS used?

  2. What are pros and cons of RTOS relative to simple MCU applications with no OS?

\$\endgroup\$
5
\$\begingroup\$

1) Can someone explain in what situations is RTOS used?

It is most often used in situations where you need (or think that you need) multithreading. Instead of a single main-loop you will have tasks executing concurrently, communicating with message passing.

2) What are pros and cons of RTOS relative to simple MCU applications with no OS?

The main advantage is the gain of abstraction and multi-threading. That often leads to code that is easier to run and test on a desktop OS. It can also mean easier re-use/porting of existing code from desktop platforms. It comes at a price, as the operating system itself takes up both time and space - where the space requirements are usually the most problematic for embedded development with a few kB RAM.

I personally shy away from RTOS-usage in low-end embedded designs, to avoid all the complexities that follow preemptive multi-tasking: reentrancy, locking discipline, priority inversion, non-determinism etc. etc.

Instead I write code that runs on the metal (without OS) and works as finite state machines, meaning everything is done asynchronously without blocking - and with static memory allocation only.

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.