mbed Rapid Prototyping for Microcontrollers

作者:Simon Ford

投稿人:Convergence Promotions LLC


ARM's mbed rapid prototyping solution pairs an NXP LPC1768 microcontroller, support components and smart USB interface with cloud-based tools to enable efficient evaluation of microcontroller capabilities and application prototyping. mbed looks for the technologies and tradeoffs that can optimize the time to get to a working prototype, enabling designers to quickly test, evaluate and demonstrate ideas early in the design cycle.

Microcontrollers are getting smaller, more powerful, lower power, and more connected, yet the prices keep coming down. This is a huge opportunity for new markets that can successfully adopt the technology. Key to this is identifying the new problems that microcontrollers can solve and building the proof-of-concept that carries an idea through to becoming a potential product.

The industry has built excellent tools for embedded engineers to produce microcontroller designs once the desired specification is known. But when the task is to prove a concept or define a specification, even for experienced engineers, the risks and timescales often don't add up. The result is that ideas don't get tried; there is little iteration or design space exploration; the final design is also the prototype, or the specification is overly cautious. Given that in many cases the ideas, observations, and insights that could define these applications will be coming from people in other problem domains, these limitations are amplified. This has the potential to be a real barrier to adoption.

Strategy

The underlying goal of mbed is to enable efficient evaluation of microcontroller capabilities and prototyping of the applications they can be applied to. In particular, it aims to match the design cycle times of other aspects of product design. The strategy (Figure 1) that helps realize this is to look for the technologies and trade-offs that can optimize the time to get to a working prototype, rather than optimizing the design itself.

Figure 1: The mbed strategy.

Figure 1: The mbed strategy.

For example, the trend in microcontrollers is an increasing performance and memory capacity for a fixed price. While most tools focus on enabling users to exploit this in the end capability of the applications that can be created, mbed, instead, focuses on using this performance and capacity to reduce the design challenge. A good example is providing high-level abstractions that make the functionality accessible at the cost of implementation efficiency and increased code size.

Another key objective is to overcome barriers to entry; the Technology Acceptance Model (Figure 2) provides a clear framework to achieve this, highlighting ease of use and perceived usefulness. Perceived usefulness is driven by insight into technology through experimentation and education. The prototyping approach naturally supports user exploration, while enabling marketing and application engineering functions to easily demonstrate and showcase the technology.

Figure 2: Technology Acceptance.

Figure 2: Technology acceptance (Davis et al., 1989).

Ease of use is actually very dependent on context; most good tools are easy to use for the task they were intended. But for a different task, the results are unlikely to be the same. By clearly defining the context of rapid prototyping, it becomes much more meaningful to make design trade-offs focused on ease of use. For an embedded developer in the industry familiar with an existing proprietary architecture and toolchain, a change can be daunting with the additional negative feeling of going from expert to learner. These factors alone can be enough to put off exploring the benefits of moving to a modern solution. For a new user, the fear, uncertainty, and doubt can be equally prohibitive. This makes the initial experience critical; the tools must give results quickly with little investment, building trust and earning any further ongoing investment.

Getting started

A goal for mbed is to get a new user running his first program as soon as possible, building confidence and trust in the hardware and software toolchain. The mbed tools have applied some novel technology to achieve this, and the results speak for themselves; you can get started in 60 seconds. This achievement means there is little excuse not to experiment.

The results are achieved through two innovations; a USB disk based programmer on the hardware and compiler tools used as cloud-computing based web-applications that run in web browsers. These solutions have some obvious benefits, but some are not immediately apparent.

Up front is the advantage that there is nothing to setup or install. For many, this will simply come as a pleasant surprise, allowing instant access without the administrative duties. But for others with locked down computer systems as found in many educational and workplace environments, this could be the difference between being able to test out a microcontroller or not.

The IDE is simple but functional, allowing it to step out of the way and do what it is designed for — edit and compile code. With everything preconfigured, it will work out of the box on any platform, including PC, Mac, or Linux. This instant no-hassle access gives great confidence in the tools, enabling users to pick them up whenever they need to use or demo them.

With it now common to work on a number of computers, the online approach becomes a particular advantage. Not only do you avoid the problems of multiple installations and keeping them in sync, but your online workspace also comes with you wherever you are.

The subtle advantages are the things you don't see. There are the decisions you don't have to make, because the options and configurations that will give the most appropriate results for the task have been made already.

Much of the hardware and software groundwork has been done. The tools are so lightweight that from any machine, it is possible to login, create a project from scratch, and test out or modify something in a matter of minutes; that sort of flexibility can have a significant impact on working style. Having a simplified setup means everything is easily reproducible.

Combined with the single hardware and library model, every other mbed user is developing in an identical environment. That makes community support much easier, as people can share problems and questions with a common context.

Figure 3: Online compiler.

Figure 3: Online compiler.

Rapid prototyping

The architecture and implementation of the hardware and software components of mbed provide a unique advantage when it comes to prototyping.

The mbed microcontroller hardware packages an NXP LPC1768 microcontroller, support components, and smart USB interface in a practical 40-pin 0.1" pitch DIP form-factor, ideal for experimenting on solderless breadboards, stripboards, and through-hole PCBs. To support the exposed interfaces, an mbed C/C++ library provides high-level interfaces to microcontroller peripherals, enabling a clean, compact, API-driven approach to coding. The combination gives immediate connectivity to peripherals and modules for prototyping and iteration of microcontroller-based system designs, providing developers with the freedom to be more innovative and more productive.

Figure 4 shows the basic mbed microcontroller pinout, indicating the availability and location of the interface resources. The interfaces indicated match those found in the mbed library. This highlights some of the key benefits of them being developed together. The API provides an abstract peripheral interface rather than being implementation specific. The libraries use object-orientation, which maps well to tangible physical hardware resources. The hardware, libraries, and documentation share the same naming and concepts for interfaces.

Figure 4: The mbed Microcontroller pinout.

Figure 4: The mbed Microcontroller pinout.

The alignment between hardware and software enables a natural programming style that captures intent, essential for fast experiments and iteration.

For example, mbed avoids requiring the multiple levels of indirection that are usually needed for pinout and resource allocation. These tend to loose meaning and introduce bugs.

# include "mbed.h"
//mosi, miso, sclk
SPI myspi(p5, p6, p7);
int main () {
//Setup 9-bit SPI @ 1MHz
myspi.frequency(1000000);
myspi.format(9);
int response = myspi.write(0x8F);

Figure 5: Configure and write to a SPI device.

The SPI example in Figure 5 demonstrates setting up a SPI master interface. First, an SPI object is created and tied to the desired pins (mosi, miso and sclk), as chosen from Figure 4. Notice that this expression could now be equally useful when it came to physically wire up the device - the specification has captured the physical connectivity.

Next, the frequency and bit format of the SPI object (myspi) are configured before performing a write/read transaction. The methods on the SPI object are well defined, making the interface intuitive, and the operations are independent of the low level settings or requirements of the underlying hardware In fact, to change the SPI port being used in this example, only the pin names would need to be changed. This helps separate modification of the physical aspects of a design (the resources used and how they are pinned out) to the control (what they do).

A similar example of capturing intent is shown in Figure 6. In this case, a function is setup to be called every time a rising edge interrupt occurs on a digital input pin. Interrupts are a simple concept, but notoriously complex to setup and get to function correctly. With mbed, the code is conceptually very simple. Create a pin that can generate interrupts, and attach a function to the rising edge of that pin.

# include "mbed.h"
InterruptIn button(p5);
DigitalOut led(LED1);
void flip() {
led = !led;
}
int main () {
//attach flip to p5 edge
button.rise(&flip);
//hang around forever
while(1);

Figure 6: Attach a function to a pin interrupt event.

Interface Function
DigitalIn
DigitalOut
DigitalInOut
InterruptIn

AnalogIn
AnalogOut
PwmOut
Serial

SPI
I²C
CAN
Ethernet

Timer
Ticker
Timeout
Read the state of a digital input pin
Write the state of a digital output pin
Read and write a bi-directional digital pin
Trigger a function on a pin rising/falling edge

Read the voltage on an analog input pin
Control the voltage on an analog output pin
Control a pulse-width modulation output pin
Communicate with serial (UART) devices

Communicate with SPI slave devices
Communicate with I²C slave devices
Communicate on a CAN bus
Read and write Ethernet packets

A general purpose timer
Call a function at a recurring interval
Call a function at a point in the future

Figure 7: The mbed library interfaces.

The library is built using approaches throughout (see Figure 7), that allow developers to concentrate on application logic rather than implementation details.

The mbed library is built on top of the low-level ARM® Cortex™ Microcontroller Software Interface Standard (CMSIS), which is a vendor-independent hardware abstraction layer for the Cortex-M processor series.

In contrast to CMSIS, the mbed library provides a very high-level API, which is focused on providing abstract interfaces for basic control of peripherals. This structure provides a natural way for users to benefit from the mbed library wherever they can, yet add bespoke code built on CMSIS where they need to support functionality not provided. In particular, this enables concentration of effort only on critical or differentiating aspects when prototyping. In addition to the mbed Library, the mbed Community peripheral libraries are an expanding base of contributed code for controlling peripherals that are connected to the microcontroller, such as sensors, actuators, LCDs, and other modules. These are usually built on top of the mbed library and enable systems to be connected quickly, focusing on the logic and functionality rather than drivers. These libraries can be contributed by anyone within the mbed community and will be supplemented by middleware from third-party vendors over time.

Figure 8: mbed Library Architecture.

Figure 8: mbed Library Architecture.

Application example

To demonstrate how a simple application experiment can be realized with mbed, the following example demonstrates a hardware device controlled by an internet database.

The example program in Figure 9 implements a system which displays a message on a screen and moves a servo motor based on the result of an HTTP request. The solution is unlikely to be optimal, robust or complete but is enough to get the concept working.

The prototype may enable iteration of hardware, early development of the internet application, exploration of new markets or provide the case for committing to a project. By enabling an accessible way to test ideas, mbed helps reduce the risk associated with product development and gets advanced microcontrollers designed into applications more often.

# include      "mbed.h"
# include      "HTTPClient.h"
# include      "MobileLCD.h"
MobileLCD lcd(p5,p7,p8,p9);
//SPI LCD
//Ethernet client
HTTPClient http;
//R/C Servo
PwmOut servo(p21);
int main() {
//20ms servo period
servo.period(0.020);
char result[128];
while(1) {
http.get(http://a.com/stat.php", result);
lcd.printf("The status is %s\n, result);
//position the servo, 1-2ms pulsewidth
float percent = atof(result);
servo.pulsewidth(0.001 * percent);
//update every minute
wait(60);

Figure 9: Control a screen and servo from an Internet app.
Conclusion

The focus on rapid prototyping gives mbed a broad appeal. For engineers new to embedded applications, mbed will enable them to experiment and test product ideas for the first time. For experienced engineers, mbed provides a way to be more productive in the proof-of-concept stages of development. For marketing, distributors and application engineers, mbed provides a consistent platform for demonstration, evaluation and support of microcontrollers. As a result, the mbed tools will help a diverse audience exploit the opportunities presented by advanced microcontrollers like the NXP LPC1768.

免责声明:各个作者和/或论坛参与者在本网站发表的观点、看法和意见不代表 DigiKey 的观点、看法和意见,也不代表 DigiKey 官方政策。

关于此作者

Simon Ford

Article authored by Simon Ford of ARM.

关于此出版商

Convergence Promotions LLC