Benjamin Cabé

Zephyr Weekly Update – C11 threads, Enhanced logging, and more

Zephyr Weekly Update - November 17, 2023

Zephyr Weekly Update - November 17, 2023

This has been a very busy week for the community, with an above average amount of new drivers and boards getting merged. Speaking of recently added boards, I am very excited to include one, the super tiny M5Stack AtomS3, in my Zephyr Tech Talk presentation next Wednesday! 🙂

I hope many of you will join, as I will be covering how I ended up migrating my now pretty old, and frankly quite hackish, Artificial Nose project to Zephyr in a matter of hours. I used this opportunity to deep more into some Zephyr features that I hadn’t add a chance to touch before, like Zbus, and I can’t wait to share my experience with y’all.

You should register to make sure you don’t miss the live stream, and of course feel free to also share the event with your network!

Support for C11 threads

The C11 standard introduced a native multi-threading API that aims at establishing a portable API for all things threads.

POSIX is of course a very popular programming model for manipulating threads, but being part of the language itself, the API introduced in the 2011 version of the C standard is effectively (or should be at least!) supported on *any* platform that supports the C11 standard.

#include <stdio.h>
#include <threads.h>

// Thread function
int printHelloWorld(void *arg) {
    printf("Hello, World!\n");
    return 0;
}

int main() {
    thrd_t thread;

    // Create a new thread
    if (thrd_create(&thread, printHelloWorld, NULL) != thrd_success) {
        fprintf(stderr, "Error creating thread\n");
        return 1;
    }

    // Wait for the created thread to terminate
    thrd_join(thread, NULL);

    return 0;
}

Chris Friedt has been working on bringing C11 threads support to Zephyr and this materialized this week with PR #60759 being merged. Quite interestingly, since Zephyr already exposes a POSIX API, most of the threads.h APIs end up mapping mostly 1-to-1 to POSIX functions.

Logging to multiple UARTs

A new zephyr,log-uart chosen node can be used to indicate that log outputs may be sent to multiple UARTs.

Until now, the UART log backend would have been only logging to the zephyr,console chosen node, but with PR #64917 it’s now possible to have the following kind of node in your Devicetree to indicate the various UARTs where you’d like logs to show up:

/ {
	chosen {
		zephyr,log-uart = &log_uarts;
	};

	log_uarts: log_uarts {
		compatible = "zephyr,log-uart";
		uarts = <&uart0 &uart1>;
	};

    ...
};

New keyboard matrix GPIO driver

A new type of driver has been introduced to allow modeling a keyboard matrix out of any set of GPIOs. The gpio-kbd-matrix binding allows you to define your keyboard matrix configuration such as:

  kbd-matrix {
          compatible = "gpio-kbd-matrix";
          row-gpios = <&gpio0 0 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>,
                      <&gpio0 1 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
          col-gpios = <&gpio0 2 GPIO_ACTIVE_LOW>,
                      <&gpio0 3 GPIO_ACTIVE_LOW>,
                      <&gpio0 4 GPIO_ACTIVE_LOW>;
          no-ghostkey-check;
  };

More details in PR #65117.

Boards & SoCs

nRF9131 EK (Credit: Nordic Semiconductor)
https://blog.benjamin-cabe.com/wp-content/uploads/2023/11/278297211-d233b3cb-3746-4376-accc-271346083388.webm
LVGL Accelerometer Chart code sample running on the M5Stack AtomS3 board.

Drivers

Miscellaneous


A big thank you to the 11 individuals who had their first pull request accepted this week, 💙 🙌: @TimTTP, @GabrielHAFs, @LipinskiPNordicSemi, @michael-whg, @josuah, @CkovMk, @CharlesDias, @ndaneil, @xvigo, @KamilxPaszkiet, and @mpenate-ellenbytech.

As always, I very much welcome your thoughts and feedback in the comments below!

If you enjoyed this article, don’t forget to subscribe to this blog to be notified of upcoming publications! And of course, you can also always find me on Twitter and Mastodon.

Catch up on all previous issues of the Zephyr Weekly Update:

Exit mobile version