Zbotic Logo Zbotic Logo
  • Home
  • Shop
  • Sale
  • 3D Print Service
  • PCB Service
  • B2B
  • Blogs
  • Contact Us
0 0

View Wishlist Add all to cart

0 0
0 Shopping Cart
Shopping cart (0)
Subtotal: ₹0.00

View cartCheckout

  • Shop
  • About Us
  • Contact Us
  • Reseller
  • Blogs
020 69134444
1800 209 0998
[email protected]
Help Desk
Facebook Twitter Instagram Linkedin YouTube
Zbotic Logo Zbotic Logo
0 0

View Wishlist Add all to cart

0 0
0 Shopping Cart
Shopping cart (0)
Subtotal: ₹0.00

View cartCheckout

All departments
  • 3D Print Service
  • 3D Printer
  • Batteries & Chargers
  • Development Boards
  • Drone Parts
  • EBike parts
  • Sensor Modules
  • Electronic Components
  • Electronic Modules
  • IoT and Wireless
  • Mechanical Parts and Workbench Tools
  • Motors & Drivers & Pumps & Actuators
  • DIY and Robot Kits
  • Show more
  • Home
  • Shop
  • Sale
  • 3D Print Service
  • PCB Service
  • B2B
  • Blogs
  • Contact Us
Return to previous page
Home Development Boards & SBCs

Zephyr RTOS on STM32: Getting Started Tutorial for Beginners

Zephyr RTOS on STM32: Getting Started Tutorial for Beginners

March 11, 2026 /Posted byJayesh Jain / 0

If you’re looking to get started with Zephyr RTOS on STM32, you’ve chosen one of the most powerful combinations in embedded systems development. Zephyr RTOS is a scalable, open-source real-time operating system backed by the Linux Foundation, and STM32 microcontrollers from STMicroelectronics are among the most popular 32-bit MCUs used by hobbyists and engineers in India. This guide will walk you through everything you need to know to set up Zephyr RTOS on an STM32 board from scratch.

Table of Contents

  • What is Zephyr RTOS?
  • Why Use STM32 with Zephyr?
  • Setting Up the Development Environment
  • Your First Zephyr Project on STM32
  • Understanding Threads and Scheduling
  • Working with Peripherals (GPIO, UART, I2C)
  • Debugging and Flashing
  • Frequently Asked Questions

What is Zephyr RTOS?

Zephyr RTOS is a small, scalable real-time operating system designed for resource-constrained embedded systems. Unlike FreeRTOS or bare-metal programming, Zephyr provides a complete ecosystem including a device tree abstraction layer, Kconfig build system, and an extensive HAL (Hardware Abstraction Layer) for hundreds of boards.

Key features that make Zephyr attractive for Indian developers:

  • Multi-architecture support: ARM Cortex-M, RISC-V, x86, ARC and more
  • Device Tree: Hardware configuration separated from software — similar to Linux’s approach
  • Bluetooth 5.0, Thread, Matter, and WiFi stacks built-in
  • Active Linux Foundation backing — regular updates and long-term support
  • Free and open-source — no licensing costs, critical for student projects and startups

Zephyr RTOS is increasingly used in commercial IoT products, and learning it opens doors to professional embedded firmware development.

Why Use STM32 with Zephyr?

STM32 microcontrollers are widely supported in Zephyr, with dozens of official board definitions available. The STM32 family spans from entry-level Cortex-M0 chips (like STM32F030) all the way to powerful Cortex-M7 processors (like STM32H7). For getting started with Zephyr RTOS on STM32, the STM32F4 Discovery or STM32 Nucleo boards are ideal choices because of their built-in ST-LINK debugger.

In India, STM32 Nucleo boards are available for approximately ₹800–₹2500 depending on the variant, making them accessible for students and hobbyists. The integrated debugger means you don’t need a separate JTAG/SWD probe to flash and debug Zephyr firmware.

Recommended: Arduino UNO R3 Development Board — While learning Zephyr on STM32, this board is great for understanding RTOS concepts on a familiar Arduino-compatible platform first.
Recommended: Waveshare ESP32-S3-Nano Development Board — Zephyr also supports ESP32-S3, giving you WiFi/BT connectivity alongside RTOS features for IoT projects.

Setting Up the Development Environment

Zephyr uses the West meta-tool for project management and building. Here’s how to set up your environment on Ubuntu/Debian Linux (recommended for Indian developers learning Zephyr):

Step 1: Install Dependencies

# Install Python and pip
sudo apt update
sudo apt install --no-install-recommends git cmake ninja-build gperf   ccache dfu-util device-tree-compiler wget python3-dev python3-pip   python3-setuptools python3-tk python3-wheel xz-utils file make gcc   gcc-multilib g++-multilib libsdl2-dev libmagic1

# Install West
pip3 install --user -U west

Step 2: Get the Zephyr Source

west init ~/zephyrproject
cd ~/zephyrproject
west update
west zephyr-export

pip3 install --user -r ~/zephyrproject/zephyr/scripts/requirements.txt

Step 3: Install the ARM Toolchain

# Download the ARM GNU Toolchain (for Cortex-M)
cd ~
wget https://developer.arm.com/-/media/Files/downloads/gnu/13.2.rel1/binrel/arm-gnu-toolchain-13.2.rel1-x86_64-arm-none-eabi.tar.xz
tar xvf arm-gnu-toolchain-13.2.rel1-x86_64-arm-none-eabi.tar.xz

# Add to PATH in .bashrc
echo 'export PATH=$HOME/arm-gnu-toolchain-13.2.Rel1-x86_64-arm-none-eabi/bin:$PATH' >> ~/.bashrc
source ~/.bashrc

Your First Zephyr Project on STM32

The classic “Hello World” equivalent in embedded systems is blinking an LED. Here’s how to do it with Zephyr RTOS on STM32:

/* src/main.c */
#include <zephyr/kernel.h>
#include <zephyr/drivers/gpio.h>

/* Get LED from device tree - works for any STM32 Nucleo board */
#define LED0_NODE DT_ALIAS(led0)
static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED0_NODE, gpios);

int main(void)
{
    int ret;

    if (!gpio_is_ready_dt(&led)) {
        return 0;
    }

    ret = gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE);
    if (ret < 0) {
        return 0;
    }

    while (1) {
        gpio_pin_toggle_dt(&led);
        k_msleep(500); /* Sleep 500ms */
    }

    return 0;
}

Build and flash this to your STM32 Nucleo board:

cd ~/zephyrproject/zephyr
west build -p auto -b nucleo_f446re samples/basic/blinky
west flash

The -b nucleo_f446re flag specifies your target board. Change this to match your actual board (e.g., nucleo_l476rg, stm32f4_disco).

Understanding Threads and Scheduling

Zephyr RTOS is truly an RTOS — it supports preemptive multi-threading with configurable priority levels. Understanding this is what separates Zephyr from simple Arduino-style programming.

#include <zephyr/kernel.h>

/* Define two threads */
K_THREAD_DEFINE(thread_a_id, 1024, thread_a_entry, NULL, NULL, NULL, 5, 0, 0);
K_THREAD_DEFINE(thread_b_id, 1024, thread_b_entry, NULL, NULL, NULL, 7, 0, 0);

void thread_a_entry(void *p1, void *p2, void *p3)
{
    while (1) {
        printk("Thread A running at priority 5
");
        k_sleep(K_MSEC(1000));
    }
}

void thread_b_entry(void *p1, void *p2, void *p3)
{
    while (1) {
        printk("Thread B running at priority 7
");
        k_sleep(K_MSEC(500));
    }
}

Key concepts:

  • Priority: Lower number = higher priority in Zephyr. Priority 0 is the highest.
  • Stack size: Each thread gets its own stack (1024 bytes above is typical for simple tasks)
  • Preemption: Higher priority threads preempt lower priority ones when they become ready
  • Cooperative mode: Set priority to negative values for cooperative (non-preemptible) threads

Working with Peripherals (GPIO, UART, I2C)

Zephyr’s device tree abstraction makes peripheral access hardware-agnostic. The same code works on different STM32 variants:

UART Example

#include <zephyr/drivers/uart.h>

const struct device *uart_dev = DEVICE_DT_GET(DT_NODELABEL(usart2));

static void uart_cb(const struct device *dev, void *user_data)
{
    uint8_t c;
    if (!uart_irq_update(dev)) return;
    if (uart_irq_rx_ready(dev)) {
        uart_fifo_read(dev, &c, 1);
        /* Echo back */
        uart_fifo_fill(dev, &c, 1);
    }
}

int main(void)
{
    uart_irq_callback_set(uart_dev, uart_cb);
    uart_irq_rx_enable(uart_dev);
    while (1) { k_sleep(K_FOREVER); }
}
Recommended: Arduino UNO R3 Development Board ATMEGA16U2 — Use alongside STM32 boards to compare UART communication between different MCU architectures.

Debugging and Flashing

Zephyr supports multiple debug interfaces. For STM32 Nucleo boards with built-in ST-LINK, West handles flashing automatically:

# Flash the compiled firmware
west flash

# Start a GDB debug session
west debug

# Use OpenOCD for more control
west debugserver --runner openocd

For serial monitor output (printk statements), use any serial terminal at 115200 baud:

# On Linux/macOS
minicom -D /dev/ttyACM0 -b 115200

# Or use screen
screen /dev/ttyACM0 115200

Important Zephyr Kconfig options for debugging:

# In prj.conf
CONFIG_LOG=y
CONFIG_LOG_DEFAULT_LEVEL=4
CONFIG_SERIAL=y
CONFIG_CONSOLE=y
CONFIG_UART_CONSOLE=y
CONFIG_PRINTK=y
Recommended: Arduino Uno R3 Beginners Kit — Build foundational embedded programming skills before tackling Zephyr RTOS on STM32.

Frequently Asked Questions

Can I use Zephyr RTOS for commercial products in India?

Yes, Zephyr RTOS is licensed under Apache 2.0, which allows commercial use without royalties. This makes it ideal for Indian startups and product companies building IoT devices.

Which STM32 board is best for learning Zephyr in India?

The STM32 Nucleo-64 family (F411RE, L476RG, G071RB) is recommended. They cost ₹1000–₹2000, have built-in debuggers, and are fully supported by Zephyr with ready-made board definitions.

How does Zephyr compare to FreeRTOS for STM32?

Zephyr is more comprehensive — it includes networking stacks, USB, Bluetooth, and a device tree. FreeRTOS is simpler and lighter. For IoT applications, Zephyr is generally more powerful. For deeply resource-constrained projects, FreeRTOS may be preferred.

Does Zephyr work with STM32CubeMX HAL drivers?

Zephyr has its own HAL that wraps STM32 HAL libraries. You don’t use CubeMX directly, but Zephyr’s STM32 drivers are mature and cover most peripherals. The hal_stm32 module is automatically included when targeting STM32.

Where can I find Zephyr examples for STM32 in India?

The official Zephyr repository contains extensive samples in zephyr/samples/. The Zephyr Discord server and GitHub issues are active communities. Indian maker groups on Telegram and Facebook also have active embedded systems discussions.

Shop Development Boards at Zbotic →

Tags: ARM Cortex-M, embedded systems, RTOS tutorial, STM32, Zephyr RTOS
Share Post
  • Facebook
  • Linkedin
  • Whatsapp
Mini Hydro Power System for Ru...
blog mini hydro power system for rural india pelton wheel guide 597944
blog buying electronics components for school projects in india 597948
Buying Electronics Components ...

Related posts

Svg%3E
Read more

Battery Charger Module TP4056: LiPo and 18650 Charging Guide

April 1, 2026 0
The TP4056 battery charger module is one of the most essential components for any battery-powered electronics project. Costing under ₹30,... Continue reading
Svg%3E
Read more

Buck Converter vs Boost Converter: Voltage Regulation Guide

April 1, 2026 0
Understanding buck converters vs boost converters is essential for every electronics project involving power management. Whether you are stepping down... Continue reading
Svg%3E
Read more

Google Coral TPU: Accelerating AI Projects on Raspberry Pi

April 1, 2026 0
The Google Coral TPU (Tensor Processing Unit) transforms a Raspberry Pi from a sluggish AI hobbyist tool into a real-time... Continue reading
Svg%3E
Read more

NVIDIA Jetson Nano Projects India: Getting Started Guide

April 1, 2026 0
The NVIDIA Jetson Nano is the most accessible GPU-accelerated AI computer for developers in India. With 128 CUDA cores, a... Continue reading
Svg%3E
Read more

ATtiny85 Projects: Tiny Microcontroller for Space-Constrained Builds

April 1, 2026 0
The ATtiny85 is the Swiss Army knife of tiny microcontrollers — just 8 pins, 8 KB of flash, and a... Continue reading

Add comment Cancel reply

Your email address will not be published. Required fields are marked

Facebook Twitter Instagram Pinterest Linkedin Youtube

Get the latest deals and more.

Download on Google Play Download on the App Store

Call us: 020 69134444 / 1800 209 0998

Monday - Saturday 09:30 AM - 06:00 PM
For Technical Supports Email: [email protected]
For Sales / Enquiries Email: [email protected]

  • My Account

    • Cart

    • Wishlist

    • Checkout

    • My Orders

    • Track Order

    • My Account

  • Information

    • FAQs

    • Blogs

    • Career

    • About Us

    • Contact Us

    • Payment Options

  • Policies

    • Privacy Policy

    • Terms & Conditions

    • GST Input Tax Credit

    • Shipping Return Policy

    • E-Waste Collection Points

    • Our Sitemap

© Zbotic.in is registered trademark of Moxie Supply Pvt Ltd – All Rights Reserved
Login
Use Phone Number
Use Email Address
Not a member yet? Register Now
Reset Password
Use Phone Number
Use Email Address
Register
Already a member? Login Now