Tuesday, August 11

Getting Started with ARM Using mbed

Even though the Arduino was hardly the first 8 bit microcontroller board to support a bootloader and the C/C++ language, it quickly became the de facto standard for hobby-level microcontrollers as well as a common choice for one-off or prototype projects. I’m sure there are a lot of reasons why this occurred, but in my mind there were three major reasons: price, availability of lots of library and sample code, and the existence of a simplified GUI IDE that you could install in a few minutes. The build process is simple, too, even though if you ever have to actually figure it out, it is quite ugly. For most people, it works, and that makes it not ugly.

I like the ATMega chips. In fact, I had boards based around the ATMega8 and a bootloader way before there was an Arduino. However, they are fairly small parts. It is true that the Arduino infrastructure has grown to support more ATMega chips, many with more memory and I/O and clock speeds. However, 32-bit processors are getting inexpensive enough that for all but the simplest or highest volume projects, you should be thinking about using 32-bit.

If you’ve tried to go that route before, you’ve probably been daunted by the price, especially the price of development tools. Your alternative is to roll your own tool chain which is very doable (and there are some nice scripts out there that will help you). You also need to worry about libraries and how to integrate them. Not to mention, many of the advanced processors require a lot of setup to get, say, an A/D converter turned on. Most processors keep things they aren’t using turned off, and each pin requires setup to select the 4 or 5 things shared on that pin.

All of this has been a barrier to entry. The vendors have all figured this out, though, and many have tried to build tools aimed at breaking up the Arduino market ranging from inexpensive development boards to code-generating wizards, to full blown IDEs. I want to tell you (and show you, in the video below) how you can make the jump from 8-bit to 32-bit much easier than you might think.

First, let’s talk price. I’m going to focus on the KL25Z Freedom board from Freescale. It isn’t much bigger than a standard Arduino board and it costs (today) about $13. What do you get for that? A 32 bit ARM processor running at 48MHz. It has 128K of flash, 16K of RAM, a USB port, and several SPI, UART, I2C, and PWM peripherals. It also has 16-bit A/D converters and a 12 bit DAC. The board itself also has an accelerometer and a touch sensor along with a tri-color LED. Not bad for $13.

Of course, you are thinking you can get an ATMega chip for less and plug it in a breadboard. You can use the same techniques I’ll talk about to program an LPC1114FN28 chip. Sure, it only has 4K of RAM and 16K of program storage, but it will easily fit in a breadboard and costs less than $5, even if you are only buying one.

The KL25Z even has an Arduino-compatible daughterboard socket (you know, a place to plug in a shield, as much as it pains me to say shield). You do have to be careful as the board is 3.3V and not 5V. Some 32-bit devices have 5V compatible I/O, but you should always make sure before directly connecting anything.

mbed0A $13 development board with a lot of memory and other goodies; sounds good, right? But surely the development tools are expensive or difficult to set up, right? Actually, no. ARM provides the mbed website that offers a full-blow C/C++ IDE in your browser (see picture to the left). No software to install at all. Version control, sharing libraries between users, documentation. Everything you might want in an IDE except debugging (but don’t forget the Arduino IDE doesn’t have debugging either). You don’t have to use the online IDE if you prefer to use a local toolchain. However, the IDE is very pleasant and has a lot of productive features.

Maybe the catch is you need an expensive device programmer? Again, no. The board looks like a USB drive. You plug it into your Windows PC (or anything that will recognize a USB drive; I use Linux) and it pops up as a disk drive. The IDE produces files that you just copy to the drive and that programs the microcontroller. The bootloader is built into the chip.

The mbed library (and also third party libraries, including those you create) let you sidestep complexity the same way you do with the Arduino. For example, if you want to create a PWM output, you simply use a PWMOut object:

   PwmOut led_r(LED_RED);

This takes care of turning on the right parts of the chip, enabling the PWM outputs, and whatever other voodoo it takes to make that work on the ARM chip you are using. Just about any other I/O task you want is just as easy. The IDE lets you search for libraries ranging from math solutions to an entire real time operating system.

So if you are running into the limits of an 8 bit processor — or even if you just want to step up for the sake of stepping up–you can be up and running on a 32-bit development platform in a few minutes for about $13. Once you get used to having 128K of code space, a ton of RAM and executing code at about 48 MIPS, you’ll find it hard to go back.

Want to know more? The video below will get you started. You can also check out the documentation on the mbed website. We’ve also talked about the BBC Micro:Bit which will work with mbed and even looked at an ZX81 recreated on an mbed-compatible processor, if you want to get some more ideas.


Filed under: ARM, Microcontrollers

No comments:

Post a Comment