r/embedded • • 3d 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?

Edit 1 : For better understanding of the situation, other products in my company are totally based on a mainboard with Yocto build and MCU for signal processing. Now the plan is to come up with a small portable version and the decision is to be made whether to go forward with an MCU based mainboard or the Yocto option.

20 Upvotes

34 comments sorted by

5

u/kisielk 3d ago

What about all the other factors? Cost? Availability? Power consumption? Latency?

4

u/faizalwho 3d ago

Cost would be about the same for the finished product, power consumption is of course a good point. RTOS would win in boot time any day. The issue is about long term support and scalability.

6

u/zydeco100 3d ago

Your LCD backlight will draw way more power than the CPU and probably go obsolete first.

6

u/grobblebar 3d ago

Speed of development is another: applications built on top of the O/S are faster to develop on a fully-fledged linux system. Performance will suffer, but maybe time-to-market is more important to you.

2

u/NoBulletsLeft 3d ago

IME, developers tend to not think of this. If you're building 5 of something vs 5,000 development cost makes a huge difference because it's amortized over a smaller number of units.

1

u/kisielk 3d ago

That depends on what the capabilities of the application are. I don't think it can generally be said that apps on a full-fledged Linux system are just faster to develop.

1

u/Kommenos ARM and AVR 3d ago

I wouldn’t say a Linux based embedded system is faster to develop. An individual user space service, sure. So there’s merit to picking an existing platform like a Raspberry Pi or any number of embedded SoMs.

But the development time for a Linux board isn’t exactly short if it’s not off the shelf. The moment you’re talking about Linux you’re potentially implying adding a lot more components like RAM, mass storage, and all the time that takes on both the hardware and software side. Not to mention the larger attack surface you might have.

Obviously all this depends on the use case.

35

u/oleivas 3d ago edited 3d 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.

6

u/5show 3d ago

RT patch is now just a config

8

u/Well-WhatHadHappened 25+ Years 3d ago

And still not real time

3

u/jemandvoelliganderes 3d ago

which would be ignorant to the fact that there is no single definition of realtime. if you need realtime and which flavour of it needs to be determent on an application by application basis.

And for many applications linux can be and is used for realtime, both hard and soft. you have loads of IPCs running a soft or virtual PLCs using linux. They most likely need a coprocessor like an EL6900 for safety, but for most oft the other stuff they are capable of what most fields would describe as realtime.

3

u/oleivas 2d ago

There is a definition of Realtime: a realtime system can guarantee a request will be processed inside a deadline.

That's what the industry got used to call hard realtime. A soft realtime is just a OS that runs so much faster than your system's time constant that it will most likely meet the deadline quotas.

I have worked in projects where Linux preemption, even using PREEMPT_RT, was problematic. I had to throttle down every other thread so my cirtical could meet it's timings.

If you have a memory constrain on top of the time one. Using Linux will eventually mean data loss. IMHO, there are requirements that will require a RTOS.

1

u/jemandvoelliganderes 2d ago

A soft realtime is just a OS that runs so much faster than your system's time constant that it will most likely meet the deadline quotas.

Do you maybe know where you read or heared this definition?

4

u/oleivas 2d ago

The definition of soft realtime came from talking to colleagues. The one for yard realtime from classes in universities. Wikipedia has a page on RT and defines it the same way (referencing a textbook):

Wikipedia - Real time

1

u/jemandvoelliganderes 2d ago

Can you please cite the specific definition of soft realtime wikipedia uses that matches yours. couse yours is referencing the exact opposite of one of the widely known expert in this field.

Also wikipedia states:

the usefulness of a result degrades after its deadline, thereby degrading the system's quality of service.

compared to you:

A soft realtime is just a OS that runs so much faster than your system's time constant that it will most likely meet the deadline quotas.

This is not the same its not even close. you statet an approach to achieve soft realtime. The definition of hard is close enough but a guarantee is not in there.

If you wanna refresh your memory, Buttazzo and Stankovic are gread and often cited sources on this toppic.

1

u/oleivas 2d ago

Hm....a fair point. I think I always defined soft realtime more from the OS point of view. Hereas, realtime quotas are met because the control software is fast enough to always preempt before deadline, even though not strictly enforced.

I think the wikipedia definition makes more sense.

19

u/EmbeddedSwDev 3d ago

First and most important: Your use case

14

u/AngryFker 3d ago

I'd prefer FreeRTOS any day to Linux if software support for RTOS is complete.

5

u/EmperorOfCanada 3d ago edited 3d 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.

8

u/StarJaded 3d ago

Boot time?

1

u/_Mad_Engineer_ 3d ago

It isn't blazing fast like uC, but I bet you can get linux to boot in a second or less through some customization.

4

u/PseudoFrequency 3d ago

I chose Linux once there is networking, models, TLS, that kind of thing. Otherwise I like to use the RTOS.

4

u/RogerLeigh 3d 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.

3

u/voskomm 3d 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.

3

u/wiggle_room1337 3d 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.

4

u/2Sovereign4You 3d ago

And RAM price?

1

u/_Mad_Engineer_ 3d ago

I don't think he needs much of a RAM transforming from this uC. There are cheap options with integrated SiP RAM of about 64-256MB.

1

u/Amped_Byte 3d ago

I think it depends on the scope of your project, the less resources used within the required scope, the better

1

u/DirkDozer 3d 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 3d 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 3d 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_ 3d ago

What chips are you considering for embedded linux?

1

u/Separate-Choice 3d 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….

-2

u/5show 3d ago edited 3d 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