#RIOT_OS: A simple review and a periodic timer

I decided to experiment with an RTOS for my Nucleo STM32F411. I figured it was time to try out FreeRTOS for the STMCube IDE. For some reason the MX configurator kept freezing on me. I started out with cold feelings toward the IDE, started to warm to it, and now I’m cooling again.

So which SDK to use? Riot is looking good. I wanted to create some kind of timer with a variable period. I have in mind a noise generator with a variable cut-off frequency. As an experiment, I just wanted to keep it fixed for now. Here is the source code that I came up:

#include <xtimer.h>
#include <periph/gpio.h>

#if 0
#define INTERVAL 500000 // half a second
#else
#define INTERVAL 1000000/40000 // 40kHz
#endif

gpio_t pin = GPIO_PIN(PORT_C, 13);

char blink_thread_stack[THREAD_STACKSIZE_MAIN];

void *blink_thread(void *arg)
{
        (void) arg;
        xtimer_ticks32_t last_wakeup = xtimer_now();

        while(1) {
                gpio_toggle(pin);
                xtimer_periodic_wakeup(&last_wakeup, INTERVAL);
        }
        return NULL;
}


int main(void)
{
        xtimer_init();
        gpio_set(pin);
        gpio_init(pin, GPIO_OUT);
        thread_create(blink_thread_stack, sizeof(blink_thread_stack),
                        THREAD_PRIORITY_MAIN - 1, THREAD_CREATE_STACKTEST,
                        blink_thread, NULL, "blink_thread");
}

Seems nice and simple to me. The interval is fixed, but I intend to change it.The code can be optionally compiled to have small, or big intervals. The big intervals are of 0.5s each, so you can see a blinky light. The small interval is at 40kHz (25us interval), to see what would happen if I pushed things a little. 40kHz is plenty for me.

I attached the GPIO pin to my logic analyser, and discovered that it a 50% duty cycle PWM wave of 50us. That’s 2*25us, which is when the pin toggles. So it’s a correct figure. What’s more, it’s bang on for the timing. Sweet.

I have limited knowledge of RTOSs in general, but here’s my take on my overall first impressions of Riot:

  • Projects can be compiled using simple Makefiles. This is my preferred choice. Meh, I can sorta cope with Cmake files, but I’d rather have a Makefile if at all possible. Kudos go to Libopencm3, too, which uses simple Makefiles. Compare and contrast with other stuff I’ve seen in RT-Thread, ZephyrOS, the Espressif and their ilk. They use Python and/or other configuration tools. The build infrastructure is hideously complicated. They just feel bulky, convoluted and fragile to me. The fact that a project like Riot can get away with just Makefiles suggests to me that all that complex crud just isn’t necessary.
  • No bloated Java IDE to contend with. Vim works fine.
  • I was impressed that I could get 40kHz timings no problemo. I had done a little experimentation with mbed in the past, and came away with the conclusion that it was probably too bulky and inefficient to get decent performance out of it.
  • Riot seems to keep things simple. The code I wrote is short and sweet. RT-Thread seemed similarly simple, but I was put off as to the complexity of creating a project. Zephyr seems to have a steep learning curve.
  • Riot documentation is quite sparse, I think, and could do with some cookbook examples. For example, hints on setting the stack size and priority for a thread would be helpful. People might have different concepts as to what the function of a timer is, so some explanation would be useful.
  • I read that Riot recently obtained a port for the Raspberry Pi Pico RP2040, which has me excited. What I read suggested that it was only preliminary support, but it has certainly piqued my interest.

I hope this little review was useful to you. Code for the timer is available here.

About mcturra2000

Computer programmer living in Scotland.
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s