USD

Accelerate IoT Product Development Using Mbed Ecosystem

By Jacob Beningo

Contributed By Digi-Key's North American Editors

Embedded and Internet of Things (IoT) development teams are under pressure to finish and ship their design as quickly as possible. To move fast, they need to use proven components and software frameworks that have a strong ecosystem around them. They also need to look at how their systems will be maintained and scaled in the future, which means that solutions also need to be portable and able to work across multiple hardware platforms if need be.

Microcontroller vendors, however, often tie developers into their own ecosystem, which limits how easy it can be to switch between microcontrollers. In addition, the software tools for microcontroller ecosystems are often inadequate, being mostly based in C, which can also hinder development teams.

Considering these requirements, this article will introduce the Arm Mbed platform and operating system. It will show how developers can leverage the Mbed ecosystem to accelerate their embedded product development and use it to scale beyond the microcontroller vendor’s ecosystem.

What is Arm Mbed?

Mbed is an online collaboration headed by Arm for developers interested in building IoT devices1. Mbed provides developers with a wide selection of resources designed to accelerate development, ranging from the Mbed OS and Mbed TLS all the way through development boards and individual hardware components that are supported by the Mbed libraries.

The premise behind Mbed is to enable developers to leverage a large ecosystem supported by 200,000 developers in online communities along with major microcontroller vendors such as Cypress Semiconductor, NXP Semiconductors, and STMicroelectronics to accelerate their development by using existing components, development tools, and libraries. There are many advantages to using the Mbed ecosystem:

  • The libraries and examples are written in C++, a modern object-oriented language that by design makes code scalable and reusable.
  • The ability to leverage an existing hardware platform to rapidly prototype an embedded product to prove that it is viable.
  • Access to the Mbed online and offline compiler along with the Mbed command line interface (CLI), which makes developing software tests easy (and is even included in many examples and libraries).
  • Built-in tools for developing IoT devices, such as the cloud Connector service that makes it easy to not just connect a device to the cloud, but also manage it through other cloud-based services.

The general architectural model for Mbed makes it extremely flexible and scalable for embedded developers. For example, the architectural model is generally broken up into three separate layers (Figure 1):

  • A low-level hardware abstraction layer (HAL)
  • Mbed OS API, which acts as middleware that provides capabilities such as storage, RTOS, secure connectivity, and communication stacks
  • A high-level IoT layer that includes the developer’s application code, Mbed OS libraries, and connectivity client(s)

Diagram of Mbed architecture consisting of three primary layers (click to enlarge)Figure 1: The Mbed architecture consists of three primary layers that can be scaled and extended as needed: a low-level hardware interface that is abstracted through a HAL, an Mbed OS API layer that abstracts middleware, and a high-level layer for writing the application code and leveraging libraries and clients like Pelion. (Image source: Arm Mbed)

The way the architecture is designed allows a developer to pull in the pieces that they need for their application while leaving out the rest. This makes the architecture scalable, flexible, and easy for developers to leverage to quickly develop prototypes, and take their product from prototype to production in a shorter time period.

Mbed starts with the hardware

While Mbed provides a great software foundation, it offers more than just the software and the tools needed to develop that software. The quickest way that a team can develop a product is to also leverage the Mbed hardware ecosystem, which comprises three distinct areas:

  • Modules
  • Boards
  • Components

Modules are essentially IoT centric connectivity devices that come in a certified and ready-to-go package. For example, a developer working on a product that supports LoRaWAN might select Multi-Tech SystemsMTMDK-XDOT-NA1-A00 xDot module development kit (Figure 2). The xDot module can provide bi-directional communication up to 10 miles in line-of-sight applications and one to three miles into buildings at data rates ranging from 293 bits per second (bits/s) to 20 kilobits per second (kbits/s). The module uses a low-power STMicroelectronics STM32L151CCU6 processor that runs at 32 megahertz (MHz) and can be controlled using an AT messaging scheme through SPI, UART, or I2C interfaces.

Diagram of Multi-Tech Systems xDot moduleFigure 2: The xDot module provides developers with a certified LoRaWAN module that is supported by the Mbed software stacks and can help a developer get up and running in significantly less time. (Image source: Multi-Tech Systems Inc.)

Mbed boards are essentially development boards for different microcontroller families that are all supported by Mbed. Each development board has unique features and capabilities that are provided by the microcontroller vendor. For example, a developer interested in working with a board that supports Bluetooth Low Energy (BLE) might be interested in Cypress Semiconductor’s CY8CKIT-062-BLE (Figure 3).

Image of Cypress CY8CKIT-062-BLE development boardFigure 3: The CY8CKIT-062-BLE development board contains multiple features for developing an IoT connected device, including an E-Ink display, capacitive touch buttons and slider, BLE module, and KitProg2 debugger. (Image source: Cypress Semiconductor)

The CY8CKIT is unique in that it features a multi-core PSoC 62 secure microcontroller. One core is an Arm® Cortex®-M4 processor while the second core is a low-power Arm Cortex-M0+. This allows developers to either partition their application code, such as having one processor handle the BLE communication, or lock down the application by using the Cortex-M0+ core as a security processor. All the I/O expansion available on the boards makes it a lot easier for developers to prototype their system by connecting Mbed components to them.

An Mbed component is a hardware component that has Mbed supported libraries and middleware associated with it that act as building blocks for creating a product. For example, a developer working on an IoT project may decide that they want to include a temperature sensor. A developer can search Mbed components for supported temperature sensors and they would come across, for example, Maxim Integrated’s MAX31723PMB1, which comes in a peripheral module that can be used for rapid prototyping (Figure 4).

What’s great about such Mbed components is that they nearly always come as a development board with schematics available. This allows a developer to not only see the hardware configuration required to make the sensor work, but have the software library available to get the sensor up and running.

Schematic of Maxim MAX31723PMB1 digital thermometer and thermostat peripheral moduleFigure 4: The MAX31723PMB1 digital thermometer and thermostat peripheral module (schematic shown) can be easily plugged into an Mbed development board and then the associated Mbed component library can be used to quickly interface and interact with the temperature sensor. (Image source: Maxim Integrated)

Simple sensors like those measuring temperature and humidity aren’t the only types of sensors that are available through Mbed. For example, developers working on a medical device will find that the Maxim Integrated MAXREFDES220# module provides them with a reference design for a finger-based heart rate and SpO2 blood oxygen sensor (Figure 5).

Image of Maxim MAXREFDES220# moduleFigure 5: The MAXREFDES220# module provides developers with a development board that can provide finger-based heart rate and SpO2 monitoring. (Image source: Maxim Integrated)

There are also components like Seeed Technology's 114991252 VL53L0X Flow breakout board that can be used in applications such as light sensing and 3D time-of-flight (ToF) distance measurements (Figure 6). A developer might be interested in this sensor if, for example, they are trying to develop gesture-based technologies at the edge.

Diagram of Seeed Technologies 114991252 Flow breakout sensor boardFigure 6: The Seeed Technologies 114991252 Flow breakout sensor board can be easily integrated into an Mbed development board and used in applications that require light sensing or 3D time-of-flight applications such as gesture detection. (Image source: Seeed Technology)

Once a developer has selected their development board and components, they can start developing with Mbed by creating a “Hello World” LEDBlinky application to test that they can program their board successfully and blink an LED.

Writing a “Hello World” LEDBlinky application with Mbed

There are several different ways to develop an Mbed application: through the online compiler; the offline compiler; or by using the command line interface (CLI) tool. Personal experience suggests using the CLI because it provides more control over the development process and makes it easier to integrate into development processes, such as test harnesses and continuous integration servers.

The CLI provides command line interface capabilities so a developer working on Windows can use the command prompt to compile their code. The first step in creating the LEDBlinky application is to use the pre-made example provided with Mbed. This can be done by entering the following command into the command prompt:

mbed import mbed-os-example-blinky

It will take a few minutes to download the example as this also brings in supporting Mbed OS and other components that may be used in the application. Once the download is complete, a developer can navigate to the mbed-os-example-blinky folder where they will find a main.cpp file. This module can be opened in a developer’s favorite editor and will look something like the following:

Copy
#include "mbed.h"
#include "platform/mbed_thread.h"
#include "stats_report.h"
 
DigitalOut led1(LED1);
 
#define SLEEP_TIME                  500 // (msec)
#define PRINT_AFTER_N_LOOPS         20
 
// main() runs in its own thread in the OS
int main()
{
    SystemReport sys_state( SLEEP_TIME * PRINT_AFTER_N_LOOPS /* Loop delay time in ms */);
 
    int count = 0;
    while (true) {
        // Blink LED and wait 0.5 seconds
        led1 = !led1;
        thread_sleep_for(SLEEP_TIME);
 
        if ((0 == count) || (PRINT_AFTER_N_LOOPS == count)) {
            // Following the main thread wait, report on the current system status
            sys_state.report_state();
            count = 0;
        }
        ++count;
    }
}

A developer could make modifications here, but for the purposes of this article, the defaults are fine. Of more interest is compiling and deploying the code. The exact command for compiling and deploying the code will vary based on the hardware. Below is an example showing how to compile and program the board in a single command for a Cypress CY8CKIT-062-BLE development board:

mbed compile -m CY8CKIT_062_BLE -t GCC_ARM -f

Compiling the project for the first time can take several minutes since the toolchain will have to build all the associated files that automatically come into an Mbed application. Once the compilation cycle is completed, the result should look something like Figure 7 below.

Image of Mbed compiler output when the LEDBlinky project has been compiled successfullyFigure 7: The Mbed compiler output when the LEDBlinky project has been compiled successfully. (Image source: Jacob Beningo)

The -f option in the command line will automatically take the compiled hex file and copy it onto the development board, which appears as a DAPLink mass storage device. At this point an LED should be blinking, and the developer can start to develop their primary application.

Tips and tricks for working with Mbed

Getting started with Mbed is straight forward, but there can be challenges for developers. Below are a few “tips and tricks” for starting to develop a product using Mbed:

  • Avoid using the online compiler. This is fine for hobbyists, but for professionals, having source code on someone else’s servers can be a problem. Also, the back and forth to the cloud can slow down debugging. A local compiler such as the Mbed IDE or the Mbed CLI are better options.
  • Mbed supports multi-threading, but by default, the main function runs in its own thread.
  • Start with Mbed example projects and review them to understand how to more efficiently work with Mbed applications.
  • Leverage the Mbed test harness to ensure that application development has not inadvertently broken anything in the Mbed framework.
  • Use the Mbed hardware site to search for development boards, components, and modules that can be quickly integrated together to develop a product.

Following these tips will help ensure that developers minimize the time they spend developing their embedded product.

Conclusion

Embedded and IoT developers need a well-supported ecosystem that provides them with modern tools, processes, and software to help them accelerate their development efforts and minimize development costs. As shown, the Mbed platform and OS is one potential option that developers can leverage.

Mbed provides a scalable and flexible software architecture with many components that have already been integrated and tested together. The large support for various hardware modules, boards, and components makes it easy for developers to create a product prototype that can then be scaled into a production solution.

References

  1. https://www.mbed.com/en/about-mbed/what-mbed/

Disclaimer: The opinions, beliefs, and viewpoints expressed by the various authors and/or forum participants on this website do not necessarily reflect the opinions, beliefs, and viewpoints of Digi-Key Electronics or official policies of Digi-Key Electronics.

About this author

Jacob Beningo

Jacob Beningo is an embedded software consultant. He has published more than 200 articles on embedded software development techniques, is a sought-after speaker and technical trainer, and holds three degrees, including a Masters of Engineering from the University of Michigan.

About this publisher

Digi-Key's North American Editors