Back to top

Learn to Build a Clean and Simple CLI for Embedded System in an RTOS Environment

23 July 2024

Introduction to CLI Design

In the fast-paced world of embedded systems, efficient and maintainable software design is crucial for success. One key component in this design is the command line interface (CLI), which facilitates interaction with the system. On May 3, 2024, Peifang Zhou, a Senior Embedded Software Designer with 30 years of experience, conducted an insightful webinar on this topic. This blog provides a comprehensive overview of the key concepts and takeaways from the webinar, focusing on the architectural design and practical implementation of a clean and simple CLI in an RTOS environment for embedded systems.

RTOS Environment

Peifang Zhou’s presentation, which was also featured at the Embedded Online Conference 2024, dives deep into transitioning from traditional character-based CLI design to an object-oriented approach specifically tailored for embedded systems. By treating each console command as an immutable object, developers can achieve a cleaner and simpler design. This methodology not only enhances maintainability but also reduces errors, making it easier to manage complex embedded systems.

Importance of CLI in Embedded Systems

Command line interfaces (CLIs) play a crucial role in embedded systems. They allow developers to interact with the system through text-based commands, enabling configuration, diagnosis, and monitoring of system behavior. A well-designed CLI significantly enhances the usability and maintainability of an embedded application, making it easier for developers to control and debug the system.

Architectural Design for CLI

The webinar emphasizes a novel approach to CLI design that moves away from traditional character-based thinking. Instead, it treats each console command as an immutable object. This object-oriented methodology encapsulates the entire command as a single entity, improving maintainability and reducing the potential for errors. By focusing on objects rather than individual characters, the design becomes cleaner and more intuitive for embedded systems.

Learn more about embedded software and enhance your designs with expert insights.

Functional Blocks in CLI Design

A key aspect of the proposed design is breaking down CLI functionalities into distinct functional blocks. This modular approach enhances scalability and maintainability in embedded systems. The three main functional blocks discussed in the webinar are:

Terminal Utility Program (Termite)

The terminal utility program plays a crucial role in building command objects. Termite is chosen for its ability to support command line auto-completion and history, which significantly enhances the usability of the CLI in embedded systems. Termite ensures that no character is sent out until the command object is fully assembled, acting much like a constructor in object-oriented programming. This approach prevents incomplete commands from being processed, thereby reducing errors.

UART ISR

The UART Interrupt Service Routine (ISR) functions as a de-serializer. Its primary role is to reassemble command objects from the serialized data received over the console interface. Once a command object is reassembled, the UART ISR uses a semaphore to notify the console task of the command object’s availability. This process ensures that command objects are fully formed before being passed on for further processing.

Console Task

The console task acts as a dispatcher. It receives the command objects from the UART ISR and finds the appropriate handler function to process the command. The console task is responsible for parsing the command object and delegating the processing to the respective worker task. This modular approach ensures that each functional block has a clear responsibility, promoting a clean and maintainable design in embedded systems.

Implementation Walkthrough of CLI on an STM32 Nucleo board

Peifang Zhou provides a step-by-step guide to implementing the CLI on an STM32 Nucleo board, a popular platform in embedded systems development. The practical demonstration includes:

  • Step 1: Setting up LED, UART, FreeRTOS, and printf() for initial testing. This step ensures that the basic components of the system are functioning correctly before moving on to more complex tasks.
  • Step 2: Configuring the UART ISR as a de-serializer and adding a console task with simple echo-back functionality. This step helps in verifying the communication between the terminal utility program and the embedded system.
  • Step 3: Implementing command object parsing in the console task. This step involves converting the command object into a format that the handler functions can process.
  • Step 4: Setting up the command handler functionality in the console task and an LED task to handle specific commands. This step demonstrates how to process commands and perform actions based on the parsed command objects.

The live coding examples illustrate the practical aspects of the design, showing how the clean and simple CLI design can be achieved with less than a dozen lines of C code for each functional block. This hands-on approach helps developers understand the implementation details and apply them to their real-world embedded projects.

Key Design Principles for Clear and Simple Designs

Several key design principles are highlighted throughout the webinar:

  • Object-Oriented Approach: Treating each console command as an immutable object leads to a cleaner and simpler design and implementation. This approach encapsulates the entire command as a single entity, improving maintainability and reducing errors.
  • Unidirectional Data Flow: Ensuring data flows in a single direction simplifies the design and avoids the complexity of bidirectional data flow. This approach enhances clarity and predictability, making it easier to manage and debug the system.
  • Single Responsibility Principle: Assigning clear, single responsibilities to each functional block or class prevents convoluted implementations and promotes clean design. Each block performs a specific function: building command objects, de-serializing them, and dispatching commands, which simplifies the overall system architecture.

Practical Implementation for CLI

The practical implementation demonstration on an STM32 Nucleo board showcases the simplicity and effectiveness of the proposed design. The step-by-step guide includes setting up LED, UART, FreeRTOS, and printf() for initial testing, configuring the UART ISR and console task, implementing command object parsing, and setting up the command handler functionality.

The live coding examples provide a hands-on approach, illustrating how the clean and simple CLI design can be achieved with concise and efficient code. This demonstration helps developers understand the implementation details and apply the concepts to their own embedded projects.

Key Takeaways for Embedded Systems Developers

The webinar provides several key takeaways for developers looking to implement a clean and simple CLI in an RTOS environment for embedded systems:

  • Object-Oriented CLI Design: Transitioning from traditional character-based CLI design to treating each console command as an immutable object improves maintainability and reduces errors. This shift leads to a cleaner, simpler design and implementation.
  • Modular Functional Blocks: Breaking down CLI functionalities into distinct blocks—terminal utility program, UART ISR, and console task—enhances scalability and maintainability. This modular approach ensures that each block has a clear responsibility, promoting a clean design.
  • Simplified Data Flow: Ensuring unidirectional data flow simplifies the design and enhances clarity and predictability. This approach makes it easier to manage and debug the system.
  • Single Responsibility Principle: Assigning clear, single responsibilities to each functional block prevents convoluted implementations and promotes clean design. Each block performs a specific function: building command objects, de-serializing them, and dispatching commands, which simplifies the overall system architecture.
  • Practical Implementation: The step-by-step implementation guide on an STM32 Nucleo board demonstrates how the clean and simple CLI design can be achieved with concise and efficient code. The live coding examples provide a hands-on approach, helping developers understand the implementation details and apply the concepts to their own projects.

Conclusion: Elevate Your Embedded Systems Development

In conclusion, as we navigate the evolving landscape of embedded systems design, Fidus Systems stands at the forefront, offering innovative solutions that address complex challenges in embedded software and CLI development. With our advanced expertise in object-oriented design, modular functional blocks, and practical implementation strategies, Fidus is uniquely positioned to enhance the performance and reliability of your embedded systems. Join us in leveraging these cutting-edge methodologies to achieve cleaner, simpler, and more maintainable designs for your next embedded project.

Reach out to Fidus Systems today to access specialized expertise in embedded systems and take your projects to the next level.

Don’t miss out on the full webinar!

Related articles

Back to News
Outsourcing Electronic design services image.
Achieving 3D Visualization with Low-Latency, High-Bandwidth Data Acquisition, Transfer, and Storage

High-bandwidth, low-latency solutions come with tradeoffs. To find the right solution for 3D visualization, consider the following requirements:

Read now
Data Scientists Reduce POC development timeline by 75% with Fidus Sidewinder

Today’s analysis and emulation of genetic sequences demands a low-latency, high-bandwidth solution to transfer massive amounts of data between processors.

Read now
How Determinism and Heterogeneous Computing Impact Ultra Low-Latency Applications

Creating a differentiated product takes a thoughtful approach to heterogeneous computing.

Read now

Experience has taught us how to solve problems on any scale

Trust us to deliver on time. That’s why 95% of our customers come back.

Contact us