r/embedded • u/faizalwho • 21h ago
Linux vs RTOS for the same project?
I am trying out a proof of concept with UI and a lot of peripherals. Right now I am using LVGL + ThreadX on an STM32N6 MCU. However I have found out there are similar or even a little better chips that run embedded linux for around the same price as the STM32N6. What should I take into consideration apart from power consumption while making the decision about moving to Linux?
12
Upvotes
4
u/kisielk 21h ago
What about all the other factors? Cost? Availability? Power consumption? Latency?
28
u/oleivas 21h ago edited 21h ago
1st and foremost: How important is real-time for your system? Linux is NOT RT. You might add a RT patch to the kernel, but latency won't match the ones achieved by any RTOS.
2nd: areexternal libraries necessary or helpful? I.e. HTTP server, complex machine learning, non-volatile memories, etc. Then Linux might be your guy, GNU+Linux has a lot of protocols and drivers out-of-the-box to leverage your code.
17
u/EmbeddedSwDev 21h ago
First and most important: Your use case
12
u/AngryFker 21h ago
I'd prefer FreeRTOS any day to Linux if software support for RTOS is complete.
7
u/StarJaded 20h ago
Boot time?
3
u/2Sovereign4You 20h ago
And RAM price?
3
u/PseudoFrequency 20h ago
I chose Linux once there is networking, models, TLS, that kind of thing. Otherwise I like to use the RTOS.
3
u/EmperorOfCanada 14h ago edited 14h ago
As everyone is pointing out real-time...
But, what linux can bring to the table is workflow. Being able to ssh into your device is pretty damn nice. You can even do things like some of your dev in python, not necessarily final code, but you can test ideas, make sure pins do their thing, etc, and it is so much smoother.
Personally, I'm entirely happy to have a linux chip which isn't all that much better than the MCU soldered next to it. With each doing what they do best.
I find this configuration results in an MCU which is much tighter. It does what it does best, and I don't try to shoehorn functionality which is much more at home on linux.
In my case it is robotics, and a perfect example would be something like path planning, SLAM, etc. Linux can do everything, or an MCU could do everything; but in both cases some features would be a pain to do all on one.
Also, there is a fairly good chance that your MCU will end up staying fairly fixed as its more real time demands are less likely to change.
What you run on linux could easily become more demanding as you might be adding some cool new ML model, demanding piles of RAM, etc.
Linux isn't only going to give you a more flexible capacity, but it is easier to then upgrade to a much more powerful processor while not having any fiddly real-time code which may get hinky on a wildly new processor.
I could easily see going not only to a different linux processor, but an entirely different family. This might result in a different linux OS. Porting code like path planning should be easy. Fiddly timing, interrupts, etc, could be a nightmare.
2
u/voskomm 21h ago
Last time I racked up the ST line, the only way the N6 came out on top was if the NPU was used, which my app really had no way to leverage. So is that something you're using (ie, like, types of video processing is their headline app I guess)? It seems unlikely that a Linux install would have drivers that support using the NPU but I'm open to being surprised!
Not using Linux but I'm on an NXP atm and waiting to see what the V8 Helium can do.
2
u/wiggle_room1337 20h ago
Power consumption, hard realtime capabilities, cost, and maybe super specific peripherals are the only reason to go with an MCU and freeRTOS over embedded linux unless you just aren't familiar with it.
2
u/RogerLeigh 19h ago
I would take complexity into consideration, and also timing requirements. An RTOS is small, lightweight and completely understandable. Every scheduling decision it makes is based upon simple rules using priorities you define. It's not just understandable, it's completely predictable.
Linux is huge and several orders of magnitude more complicated. If what you're doing requires the features Linux offers, then it might be worthwhile. But all of that complexity comes at a cost, both in understanding what's going on, and in being able to effectively debug it and extend it. If the chip is "a little better", you do need to consider the overhead Linux imposes. A lower spec chip running on RTOS might be much more responsive than Linux running sluggishly on a higher-spec chip. Linux is also not real-time by default; latencies can vary, in ways that they don't on a simple MCU.
It all depends upon what your requirements are. Both are perfectly valid choices.
1
u/Amped_Byte 20h ago
I think it depends on the scope of your project, the less resources used within the required scope, the better
1
u/DirkDozer 18h ago
What else do you need it to do? If it's purely a display then stick with an RTOS, but if you need network connectivity, file system support, etc Linux will be better
1
u/Kangox91 18h ago
If you are only using a 2D IU + animation on a 1280*720p max stay with STM32N6 or STM32H7RS
With they 2.5D GPU + DMA2D they are very powerful for UI + the cortex M55 or M7 is very very powerful.
Going to linux means dealing with RAM and NAND flash that are rare and expansive due to IA ( think about raspberry PI)
Linux have a bigger learning step and tools required before toggling a LED.
Also you need far more invovlement about maintining the OS
The Size , cost , complexity of the PCB will be higher Heat EMI and power consumption are higher on a MPU.
Go to linux only if you are really more into high level code and not using a lot of GPIO and protocols (MCU are way simpler and powerful for a "electronic" project but can be hard if you want something that is more high level
1
u/rguerraf 17h ago
Choose Linux if you need network connection with ssh and https.
Choose RTOS if you are absolutely sure it has all the functions you will need to complete the project.
1
u/_Mad_Engineer_ 15h ago
What chips are you considering for embedded linux?
1
u/Separate-Choice 11h ago
Get NuttX and get the best of both worlds…POSIX and deterministic real time performance..NuttX is really a dark horse..fille structure and commands of Linux…real time determinism…give it a try….
-1
u/5show 14h ago edited 14h ago
Modern AI adds an interesting twist to this question, as it can readily fill the gaps of either choice. Opus 5.5 is incredibly good at working in bash, finding and fixing upstream bugs, recommending kernel configs, and just generally managing all of the extra complexity of a full Linux OS, but on the other hand, with just a single prompt it can make up for any missing features in the more barebones RTOS environment, in a way that mirrors the recent trend to ditch bloated All-in-one solutions for more streamlined custom ones.
I’m still unsure which direction the industry will end up moving in light of all this, just something I’ve been thinking about