ACL Digital

Home / Blogs / Complete Step-by-Step Guide for Migrating from FreeRTOS to Zephyr
Migrating from FreeRTOS to Zephyr
March 3, 2025

7 Minutes read

Complete Step-by-Step Guide for Migrating from FreeRTOS to Zephyr

Migrating from FreeRTOS to Zephyr can unlock significant advantages, such as advanced connectivity features, an integrated CANopen stack, and robust tooling. This guide will walk you through the migration process, highlighting key steps and considerations to ensure a smooth transition.

Benefits of Migrating to Zephyr

  • Integrated Connectivity: Zephyr includes extensive connectivity options such as Bluetooth Low Energy, Wi-Fi, and cellular, seamlessly integrated into its configuration and build system.
  • CANopen Integration: Unlike FreeRTOS, Zephyr has a built-in CANopen stack, reducing development time and complexity.
  • Active Development: With around 200 commits weekly, Zephyr ensures continuous improvement and long-term support.
  • Robust Tooling: Zephyr’s SDK and west command-line tool simplify setup and development, while its built-in testing framework (ZTests) facilitates thorough testing.
  • Maintainability: Zephyr’s separation of hardware details from the kernel accelerates development time and improves maintainability.
  • Security: Zephyr’s rigorously tested codebase, regular updates, and OpenSSF(Open Source Security Foundation) Gold Badge certification underline its commitment to security.
  • Portability: With support for various hardware architectures and communication protocols, Zephyr can be easily ported to new platforms
  • Memory management: Zephyr can run on devices with as little as 8 KB of memory without compromising performance or security.
  • Board Support: The Zephyr community supports over 750 boards from multiple vendors and architectures.
  • Open Source: Zephyr’s open-source nature, governed by the Linux Foundation, ensures flexibility and a diverse contributor base.
  • Familiarity & Ecosystem: With Linux at its core, Zephyr offers a familiar ecosystem for developers with Linux experience.

Step-by-Step Migration Process

Migration Process from FreeRTOS to Zephyr

Initial Setup and Assessment

  • Install Zephyr SDK: Download and install the Zephyr SDK from the official website. Follow the steps here.
  • Set Up Development Environment: Use Zephyr’s west tool for configuration and management.
  • Ensure you can build any sample code without any errors.

Develop the required Zephyr Device Driver for your application

  • Check and verify if the necessary drivers exist in Zephyr’s SDK.
  • If unavailable, develop the device drivers required in your application as per Zephyr’s Device Driver Model, defined here.
  • Create device tree source (DTS) bindings for the device drivers and define their properties.
  • Integrate the driver into a sample code and ensure seamless operation.
  • Challenges: Limited references for DTS file errors may hinder debugging. Avoid using reserved names from the SDK.

Custom Board File Creation

  • Develop a custom DTS board file that fits your application’s requirements.
  • Challenges: Ensure unique node names and proper partitioning to avoid compilation errors.

Application Structure Design

  • Identify and select an application framework from the repository application, workspace application, or freestanding application as defined here.
  • Challenges: In workspace applications, if multiple projects are managed, they will share the libraries and SDK, so ensure you define all the projects without different use cases or needs. Workspace applications share libraries, so ensure compatibility across projects.

Libraries and Submodules

  • Identify required libraries or submodules for your application and include them in the west.yml file to ensure they are cloned into the project.

Customize the CMakeLists.txt

  • Update the CMakeLists as per your application needs.

Porting Threads and Synchronization

  • Thread Creation: Replace FreeRTOS thread creation functions with Zephyr’s k_thread_create.
  • Synchronization Primitives: Update semaphores and events using Zephyr’s synchronization primitives like k_sem and k_event.

Replacing Custom Ringbuffer/Inter Thread Communication

  • Identify Custom Implementations: Locate custom ring buffer implementations in your FreeRTOS code.
  • Leverage Zephyr Pipes: Replace the custom ring buffer code with Zephyr’s k_pipe, a unit-tested mechanism that supports thread synchronization.
  • Leverage Z-Bus: Consider using Zephyrs’s advanced inter-task communication mechanism, which enables efficient one-to-many communication.
  • Challenges: Assess memory and timing requirements to select appropriate IPC mechanisms.
Inter Thread Communication

Console Shell Integration

  • Transition CLI: Migrate from FreeRTOS+CLI to Zephyr’s Shell for command line interface (CLI) functionalities.
  • Configure UART: Set up UART via the device tree for console interaction.

External Flash Support

  • Adapt Flash Drivers: Replace FreeRTOS-specific flash drivers with Zephyr’s SPI flash drivers, ensuring compatibility with your hardware.
  • Adjust Memory Layout: Update memory layout configurations in the device tree as needed.

Testing and Validation

  • Unit Testing: Utilize Zephyr’s built-in testing framework, ZTests, to design and execute unit tests for your code, ensuring reliability, functionality, and overall performance.
  • Debugging: Leverage Zephyr’s integrated debugging tools to troubleshoot effectively.

Key Considerations

  • Learning Curve: Familiarize yourself with Zephyr’s device tree and Kconfig systems, which differ from FreeRTOS’s configuration methods.
  • Hardware Configuration: To avoid runtime issues, ensure accurate hardware configuration in device tree files.
  • Community and Support: Actively engage with the Zephyr community for support and updates and report any issues encountered during migration.

Unexpected Benefits

  • Developer Support: Zephyr’s active community and quick response to support requests can significantly aid in resolving issues.
  • Integrated Tooling: The west tool and Zephyr SDK streamline the development process.
  • Testing Framework: Zephyr’s ZTests framework enables comprehensive code testing, including OS primitives.

Migrating from FreeRTOS to Zephyr enhances your project’s connectivity, portability, and maintainability while leveraging a vibrant developer community. Follow this step-by-step guide to ensure a smooth transition and fully take advantage of Zephyr’s robust features and active development community.

About ACL Digital

ACL Digital has extensive expertise in Zephyr development, including RTOS migration and driver integration. We also actively contribute to the Zephyr community. For queries or assistance, contact us at business@acldigital.com.

Scroll to Top