Advantages and Disadvantages of RTOS
Advantages and Disadvantages of RTOS
Luckily these days, there are much nimbler, modular open-source RTOS,
including Zephyr and Apache Mynewt. There are many other open-source and
commercial RTOS available. (list of all RTOS’s available)
Some RTOS have Sensor Frameworks that will make sensor programming
simple. With a Sensor Framework, you only need a few lines of code to do
this: “Look for the BME280 sensor, schedule the sensor to be polled every 10
seconds, and call my function with the sensor data”.
Here’s a tip: Even if you’re not using an RTOS, you can use its drivers! Apache
Mynewt didn’t have a driver for the ESP8266 wifi module, so we ported the open-
source driver from another RTOS (Arm Mbed OS), and it worked beautifully. So if
you ever get stuck, consider borrowing bits of code from an open-source RTOS that
works!
2. MULTITASKING IN RTOS
Most devices will need some form of multitasking, like reading a sensor while
transmitting the data over a network (Bluetooth, wifi, NB-IoT LoRa, …). An RTOS
lets you specify the priority of each task and schedule them accordingly, making the
best use of the available CPU processing time.
Writing secure code is hard… so better leave that to the professionals. An RTOS
contains cryptographic functions, network stacks (like TCP/IP), and firmware
distribution methods that have been reviewed by professionals. When you program
your device firmware with these peer-reviewed functions, you can be sure that your
firmware is safe from attacks. And you’ll get timely alerts when any security
vulnerabilities are found in these functions.
Coding these functions yourself is risky. Unless you have security experts in your
team, you may inadvertently create security holes and make your firmware
vulnerable to attacks. If you decide not to use an RTOS, then we recommend using
a trusted security library instead of coding it yourself.
For large projects, with many coders, perhaps even from different firmware design
firms, this ensures that all vendors will follow the same standard for coding your
device firmware. Without an RTOS, you would have to define your coding guidelines,
your own base libraries, your conventions for multitasking, memory allocation, and
so on. This increases the time to create the first version of the device firmware.
Discover new ways of solving problems by mixing and matching different sensors:
motion, sound, light, touch, … Explore ways to reduce power consumption by
switching networks: Bluetooth, ZigBee, wifi, NB-IoT, Sigfox, LoRa, …
RTOS DOWNSIDE 1
An RTOS requires RAM to keep track of its operational state. It also requires Flash
ROM space for the RTOS code, and it needs CPU power to run it.
Here’s a peek into an STM32 Blue Pill development board with 20 KB RAM and 64
KB ROM. Even a modular, lightweight RTOS (Apache Mynewt) still occupies 9 KB
of RAM and 22 KB of ROM. That’s nearly half of Blue Pill’s RAM and one-third of
Blue Pill’s ROM.
This may well mean that the RTOS forces you to use a higher-end MCU than without
it. This increases the unit cost, and every dollar is essential when you realize many
electronic devices retail at 3 times BOM cost.
The energy needed to run the RTOS also means that battery life will be reduced.
So if you want a fully optimized device, it is still better to code with Bare Metal
RTOS DOWNSIDE 2
CONCLUSION
Microcontrollers are complex beasts that can be tamed by an RTOS, and if you are
prepared to invest the time to thoroughly learn and understand the RTOS, an RTOS
allows you to write simpler firmware code that will exploit all the capabilities that the
microcontroller can provide.
There are now RTOS’s which are much smaller and modular. With and with higher-
powered MCU’s such as STM32 very affordable, you may well have the headroom
needed to afford an RTOS without any extra cost.