Blog

Customizing the Embedded Serial Interface

Customizing the Embedded Serial Interface

In the world of embedded systems, the ability to diagnose, debug, and interact with devices is paramount. Serial logging provides a real-time stream of insights into device operations. Command-line interfaces empower developers to execute commands and modify settings on the fly. Complementing this, logging capabilities allow for meticulous monitoring and troubleshooting of a device during operation.   

Many solutions provide these functionalities including ns_cmdline and mbed-trace both from the Mbed OS library. These portable libraries can be pulled into other non-Mbed OS projects with no RTOS support or with FreeRTOS support with minimal effort. There are many great software tools that exist that enable interacting with a serial port on your PC. This blog introduces a demo of a Web Serial-based tool as an alternative to some of these existing solutions.

Command-Line Interface

There are a variety of existing tools for embedded systems that cater to the needs of professional developers. One such tool is the ns_cmdline library, which provides a command-line interface functionality directly within Mbed OS applications. This library is particularly useful for devices that require configuration or interaction via a serial interface, often used in debugging, diagnostics, and setup procedures.

The ns_cmdline library streamlines the process of interpreting and executing user commands. Developers can define a set of supported commands along with associated callback functions that are executed when you enter a command. This turns a serial terminal into a powerful means of interacting with the system, providing immediate feedback and control. The inclusion of a command-line interface within an embedded system means that developers and other engineers can interact with the systems in a user-friendly and adaptable way.

The development of such an interface often requires a deep understanding of serial communication protocols and the intricacies of character encoding. However, tools like the ns_cmdline library abstract away much of this complexity allowing developers to focus on the high-level functionality of their applications. This not only accelerates the development process but also enhances the reliability and performance of the command-line interactions within embedded systems.

Advanced Logging

Visibility into a system's behavior is crucial, and logging is the key to gaining this insight. Mbed OS offers a comprehensive solution for this through its mbed-trace library, which is specifically designed to provide a robust serial logging mechanism. This library is a part of the Mbed OS ecosystem and is portable to other platforms. It serves as an invaluable tool for developers needing to debug and monitor their applications.

The mbed-trace library equips developers with a high-level tracing interface that allows for detailed logging of system events, data processing, and error reporting. With its fine-grained control over logging levels and modular tracing, developers can tailor the output to match the needs of their debugging session, focusing on critical issues without being overwhelmed by verbose logs. This functionality is especially beneficial in resource-constrained environments where traditional debugging methods may be intrusive or impractical.

Utilizing mbed-trace, developers can introduce trace macros into their code, specifying the importance level of each log entry. The library then handles the formatting and output of these entries to a serial terminal or other output stream. The modular nature of mbed-trace means that it can be easily integrated into existing projects, providing a seamless logging experience that can be as simple or as detailed as the situation requires.

Compatible Web Serial GUI

The debate between text-based interfaces and graphical interfaces in the mainstream has long been settled. So, when using these tools, it can be convenient to have this information nicely wrapped into a user-friendly GUI. 

A few months ago, I had a series of conversations with ChatGPT-4 to develop a demonstration user interface that utilizes Web Serial to interact with a serial device. I worked with ChatGPT-4 as effectively a pair-programmer to complete this application quickly. Web Serial is nice because the Chrome web browser supports it so anyone who has Chrome installed can utilize it out of the box. This makes the interface cross-platform out of the box.

The application provides a simple way to connect to and disconnect from devices. It gives you the option to refresh a command list which is what the Command-Line interface provides. Then, each command is rendered as an individual button with an arbitrary argument input field. Responses from commands are displayed to the right of the buttons. At the bottom of the page you can filter, display, and download live log messages.

Live Application

The demo Web Serial application and code is available on GitHub if you are interested in trying it out yourself.

Learn more about DMC's Embedded Development and Embedded Programming services and contact us for your next project.

Comments

There are currently no comments, be the first to post one.

Post a comment

Name (required)

Email (required)

CAPTCHA image
Enter the code shown above:

Related Blog Posts