MBED - Embedded for the Rest of Us

October 24, 2009

4 Min Read
MBED - Embedded for the Rest of Us

In a previous post I mentioned the MBED ARM powered development board. This board is such a neat product I thought I’d write a column giving more details about it.

In the interest of full disclosure, I am currently an ARM employee and have been for the past 11 years, in ARM’s Processor Division. During this time I have worked on parts such as ARM 1026, 926, 968, Cortex A8, and others.

Embedded development can be complicated…
There are plenty of ARM powered development boards out there, what is special about this one? Most development boards are targeted to embedded developers, and require the developer to don an exoskeleton of software and hardware: Debuggers, ICE boxes, development tools and their associated licenses or dongles, etc. These items are powerful once mastered but installation can be difficult and the learning curve steep.

Beyond the tools, embedded programming itself is much more complicated than developing code for a desktop environment. Exception vectors, periodic and asynchronous interrupts, complicated hardware register files, memory maps, etc. are all items that are rarely dealt with directly when programming for the desktop.

What if there was a development environment that completely avoided the cables and tools issues of embedded development, and made the programming environment as simple as writing object oriented code?

MBED makes it simple
Enter the MBED platform and development environment. MBED has one connector, a USB cable that you attach to your computer. Once attached MBED appears as a removable drive on your computer, be it Windows, Linux, or Mac. On the flash drive is an mbed.html file. Double click that file to go to the mbed.org WWW page. From here you can download a precompiled “hello world” executable binary file. Save it to the MBED flash drive — saving a .bin file to MBED automatically installs that file as firmware. To run it press the blue reset button in the middle, and you will be treated to blinking LEDs. It doesn’t get much simpler than that.

The C++ development environment is just as easy. It is hosted online, so you can get started with only a web browser. Write your program in C++, instantiating peripheral classes and configuring them as needed. When you’re done press the compile button. If your code compiles without errors, the online IDE will provide you with a link to your executable bin file. Click the link and save to your attached MBED and your new firmware is installed and ready to go.

For example…
As you can tell from the pinout diagram above, MBED uses a fully featured microcontroller (NXP LPC1768, based on an ARM Cortex-M3 Core running at 100MHz). A pretty basic embedded task is setting up a periodic heartbeat timer for your embedded code or RTOS. You might have the ISR toggle an LED so you can tell visually that your interrupt is still occurring. This involves writing code to configure the timer using its register file, writing the ISR itself (both usually in assembly), and interfacing them to the rest of the embedded code, usually in C. It’s a little simpler with MBED:

#include “mbed.h”
Ticker flipper; // a periodic interrupt class
DigitalOut led1(LED1); // a digital output class connected to an LED
DigitalOut led2(LED2); // same for LED2

// The function flip() is the ISR! All it does is toggle led2
void flip()
led2 = !led2;

int main()
led2 = 1;
flipper.attach(&flip, 2.0); // the address of the function to be attached
// (flip) and the interval (2 seconds)

// spin in a main loop. flipper will interrupt it to call flip
while(1) {
led1 = !led1;

This program will toggle led1 with an on/off time of .2 seconds in the main loop. The timer will interrupt every 2 seconds to toggle led2. Notice that the member functions of the flipper class use real world units, in this case seconds to specify intervals. MBED provides objects to abstract the configuration of all of the peripherals, written to accept real world units such as seconds, microseconds, volts, etc.

What if you wanted to log data to an SDcard attached to your MBED? How about this:

#include “mbed.h”
#include “SDFileSystem.h”
SDFileSystem sd(p5, p6, p7, p13, “sd”);
int main()
printf(”Hello World!\n”);
FILE *fp = fopen(”/sd/foo.txt”, “w”);
if(fp == NULL) {
error(”Could not open file for write\n”);
fprintf(fp, “Hello SD Card World!”);
printf(”Goodbye World!\n”);

Go get one!
The MBED handbook documents all of the available peripheral classes and their member functions. In the MBED cookbook you can find examples of code to interface to LCD panels, accelerometers, even http clients and servers.

What kind of gadget can you build with a high performance microcontroller, easy access to ethernet, analog and digital I/O, a gigabyte or more of SDcard storage, and many other peripherals that can be connected via SPI or I2C? Go to mbed.org and watch the 1 minute MBED ninja video, take the tour, and get one for yourself. Production is underway and pre-orders are being taken at Digikey (US) and Farnell (Europe).

Taking suggestions…
The purpose of this blog is to explore strange gadgets, to seek out new time sinks and new forms of creative idleness, to boldly go where no gadgeteer has gone before. And, to take you along. If you have seen an interesting gadget online, or have designed one yourself, drop me a line and I may write a future article about it. You can reach me at [email protected].

Happy gadgeting!

Sign up for the Design News Daily newsletter.

You May Also Like