Channels ▼

Al Williams

Dr. Dobb's Bloggers

Mbedded Systems

April 30, 2014

I've been working with two different ARM-based systems lately. One is an inexpensive Freescale FRDM-KL25Z and the other is a simple breadboard with an LPC1114 CPU in a DIP package. These are pretty powerful 32-bit processors with a built-in clock that will run at 48MHz. The Freescale board has 128K of flash and 16K of RAM while the LPC1114 CPU has 32K of flash and 4K of RAM. The Freescale board is a bargain at about $13, and the LPC1114 chip is just a few dollars (and doesn't require much more than a 3.3V power supply).

I wanted to focus on the software side of things this time. If you've tried using ARM processors before, you may have found it difficult to get a toolchain (unless you bought one or used a commercial offering). Things have gotten better, but even with a toolchain you may have found you needed vendor-specific startup files and library code. ARM's done a lot to make that better, too, with some standardized libraries like CMSIS.

The Mbed library (I almost hate to call it a library, since that's only part of what it is) solves just about all of those problems. Much like the Arduino, the Mbed libraries use objects to make accessing the embedded hardware on supported ARM platforms very simple. On supported hardware, it handles all the startup, interrupt handling, and pin multiplexing. You just write code using abstractions for the platform hardware. The library is open source (it has not always been open source, but now it resides on github).

The toolchain isn't a problem either. The Mbed website has a complete IDE that lets you write and compile code. You can import a large number of examples and specialty libraries right from the IDE (see the figure below).

The IDE compiles your code (and does a nice job, creating smaller files than my copy of the GNU compiler) and downloads a .BIN file. For the LPC1114, you can program the chip using the onboard bootloader or via a debug probe like an inexpensive LPC-Link board. I'll talk about the details of that setup soon.

For this time, though, I wanted to focus on the FRDM-KL25Z board. It plugs into your computer and appears like a USB drive. Simply copying the .BIN file to this USB drive is sufficient to program the board. You do need to update the loader on the board to make this work with Mbed, but that's a simple process.

The FRDM-KL25Z has some fun peripherals including a three-color LED, an accelerometer, and a capacitive touch sensor. It also has USB ports. Without some help, it would be quite a few lines of code to handle the processor reset, the switching of all the I/O lines to the right devices, and then actually driving or reading the device. The Mbed library takes care of all of that for you.

Consider this example that I put online (this is a modification of one of the default examples provided). The three-color LED appears to software to be three distinct LEDs and setting them up to drive using pulse width modulation (PWM) is trivial:

int main(void) {
    PwmOut led_r(LED_RED);
    PwmOut led_g(LED_GREEN);
    PwmOut led_b(LED_BLUE);

Setting the analog slider isn't very hard either:

    TSIAnalogSlider tsi(ELEC0, ELEC1, 40);

That's the setup. I made the software keep the blue LED on until a touch is detected. Then it blends the red and green colors depending on the position of your finger:

    while (true) {
        float f=tsi.readPercentage();
        if (f<.05)
        {
        led_b=0.0;
        led_g=led_r=1.0;
        } else
            {
            led_b=1.0;
            led_r= 1.0 - f;
            led_g = f;
            }
        wait(0.1);
    }

Note the libraries use floating-point numbers, which is no issue for the compiler. The PWM (and the touch sensor) use a number from 0.0 to 1.0 instead of the more common integer representation.

This is pretty easy. Yet, you still have access to a full C++ compiler and all the features of the CPU. The development effort is on par with the ubiquitous Arduino, but with a lot more horsepower than a typical Arduino.

One of my usual complaints about the Arduino is that without doing gymnastics, you can't really do hardware debugging. The same is true here. As nice as the Mbed online IDE is, it doesn't support debugging (although you are free to pepper your code with printf statements, of course). Debugging is possible on the Arduino with some extra work and the same is true here.

To do debugging, you need an external debug probe and a local IDE. The Mbed IDE can, sort of, export your project to an external IDE for just this purpose. I'll talk about the options along with some more about the custom hardware next time.

Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.
 


Video