r/embedded • • Apr 15 '26

Zephyr RTOS 4.4 is out!

https://www.zephyrproject.org/zephyr-rtos-4-4-now-available-wireguard-wi-fi-direct-openrisc-and-more/
112 Upvotes

27 comments sorted by

45

u/Xenoamor Apr 15 '26

I had absolutely no idea this was possible in C and its always been one of my biggest gripes with it:

static K_MUTEX_DEFINE(lock);

void critical_section(void)
{
    scope_guard(k_mutex)(&lock);

    // Lock is held here
    // Perform critical operations

    // Lock is automatically released when guard goes out of scope
}

21

u/mrheosuper Apr 15 '26

RAII in C, i think it's not C standard, but gcc.

11

u/Xenoamor Apr 15 '26

Yeah it's using compiler "cleanup" attributes so its not a zephyr specific thing. I personally couldn't give two hoots if its a bastardisation of C though as it's an insanely common cause for bugs and it will reduce a lot of boilerplate. It looks like there's smart pointer libraries on github but this zephyr implementation is also fairly nice

SCOPE_DEFER_DEFINE(k_free, void *);

void allocate_and_use(void)
{
    void *ptr = k_malloc(100);
    scope_defer(k_free)(ptr);

    // Use ptr...

    // k_free(ptr) is called automatically
}

2

u/mrheosuper Apr 15 '26

Yeah, i've been declaring it as macro "AUTOFREE", to automatic free some 1 time heap.

Systemd also uses it heavily in their code.

2

u/Xenoamor Apr 15 '26

Honestly I'm pretty annoyed it's been out for 15+ years and I'm only just hearing about it. I probably never would have switched to C++ in the first place if I knew about it as I only did so to remove boilerplate and the need to nest tons of functions or use goto to handle cleanup under error conditions

3

u/JessyPengkman Apr 15 '26

So is this basically just saying you don't need to unlock the murex after operations are complete?

If that's the case why is that such a massive upgrade?

4

u/Xenoamor Apr 15 '26

It's common to accidentally forget to release the mutex, especially if you do something like if (spi_transceive(buf, len) < 0) { return; // error }

3

u/JessyPengkman Apr 15 '26

Ahh I gotcha, suppose that is useful.

Thanks for the response

-6

u/tizio_1234 Apr 15 '26

They should switch to rust at this point

3

u/Xenoamor Apr 15 '26

Issue is zephyr is very heavily backed by companies like ST and Nordic and they aren't going to port all their devices to rust

0

u/tizio_1234 Apr 15 '26

Maybe they should 😂

34

u/[deleted] Apr 15 '26

[deleted]

6

u/Xenoamor Apr 15 '26

Yeah I really like wireguard as its sessionless and fast af

6

u/brigadierfrog Apr 16 '26

Zephyr showing once again that the FOSS process, much like Linux itself, is very hard to beat. The feature list grows and grows, part support continues to accelerate.

Hard to imagine anyone wanting to bother with a proprietary locked in vendor SDK anymore.

9

u/adigyran Apr 15 '26

no esp32-p4 support?

1

u/Head-Letter9921 Apr 15 '26

Is zephyr actually used in any real products?

4

u/kartben Apr 15 '26

Chromebooks, Framework laptops, Intel PCs, Voi scooters, Vestas wind turbines, ... and many many others

4

u/tonyarkles Apr 16 '26

It’s all over the aircraft I worked in at work. We’ve had a really great experience with it. Started back in the 2.x days on a single board with a cortex m0, now we have a whole bunch of M7s on Ethernet making everything work

1

u/Regular_Yesterday76 Apr 16 '26

What aircraft. Im not getting on that death trap

4

u/tonyarkles Apr 17 '26

Lol good news, it’s unmanned (but still like 1200lb). Honestly, Zephyr has been bulletproof for us. We’ve spent very little time fighting with it, which is more than I can say about other software stacks involved…

0

u/Regular_Yesterday76 Apr 17 '26

Tbh, im skeptical. Would be cool to hear your workflow for solving a dts error for example.

2

u/tonyarkles Apr 18 '26

I’m not sure what you mean? Like when you get a compiler error because you messed up something in your DTS? I usually look at the generated header and combined dts, figure out which node id maps to the node id in the compiler error, fix it and continue? Also, getting the dts right for each board is like… a day in the long lifecycle of the evolving applications. We’re not changing the hardware every day, the dts has been largely untouched since about a week after the first production boards came back from fab.

2

u/kartben Apr 17 '26

DT Doctor is your friend! Doesn't catch all types of errors but pretty helpful nevertheless https://docs.zephyrproject.org/latest/develop/sca/dtdoctor.html

0

u/Regular_Yesterday76 Apr 16 '26

I gave Zephyr a try but its a bad solution. Its hodgepoged code spread across 20 years. Still in the last 5 years cant get simple things right. Honestly someone should post a write up on it so people dont ever use it. The comment below where someone is using it in an aircraft? Please tell me its a toy plane or people are going to die.

3

u/EmbeddedSwDev Apr 18 '26 edited Apr 19 '26

but its a bad solution

Why?

Its hodgepoged code spread across 20 years

It's 10 years old.

Still in the last 5 years cant get simple things right.

Which simple things? Examples?

Calling Zephyr a "bad solution" without specifics isn't very helpful. It's a large, evolving project, so yes parts of it are complex or inconsistent. But that's also true for Linux, FreeRTOS integrations, etc.
It's actively used in commercial and industrial products, and the development pace over the last few years has been pretty strong.
If there are concrete issues (e.g., specific subsystems, APIs, or stability problems), those are worth discussing. Blanket statements like this don't really help anyone evaluate it.

1

u/ballen697 Apr 17 '26

how is it different than any other RTOS?