jenswilly.dk


From AVR to ARM

It seems more and more people are moving away from using AVR and PIC microprocessors and switching to ARM processors. So I thought I might take a look as well.

I'll skip the usual intro stuff about ARM (read about it on Wikipedia or somewhere). For my purposes, the ARM Cortex-M series which is the "Microcontroller profile" is what's interesting. The general sentiment is that the 32 bit ARM Cortex-M MCUs are better and faster the 8 bit AVR and PIC processors and have support for more peripherals. The only real disadvantage is that there are no ARM processors available in DIP packages for easy prototyping. Although I must add that another disadvantage is that there are a lot more code examples etc. available for AVR and PIC compared to pretty much any ARM processor.

Choice of processor

It looks like the Cortex-M0 and Cortex-M3 are what I'll be using. The M0's are best suited for low-power (as in battery powered) systems while the M3's are faster with higher performance and support for more peripherals.

There are several manufacturers of ARM Cortex-M0 and -M3 microprocessors. Among them are:

  • Atmel (SAM3)
  • STMicroelectronics (STM32)
  • NXP (LPC)
  • Energy Micro (Gecko)
  • TI (Stellaris)

It seems like the SMT32 and the LPC series are the most widely used. At least those were the devices I found the most information about. For now, I have chosen the NXP LPC series as my ARM of choice because:

  1. I can find enough information about them (mind you, there are nowhere near as much info and examples for ARM MCUs on the Internet as there is for the 8-bit AVR or PIC MCUs).
  2. They are cheap.
  3. They are readily available (meaning they are in stock at RS).
  4. It looks like it there is a Mac OS X compatible toolchain.
  5. Some of them have nice on-chip USB bootloaders.

… but in all honesty I could probably have picked any other from the list and never known the difference. Just like PIC vs. AVR or Canon vs. Nikon. So just pick whichever one you fancy that looks like it'll do the job and learn how to use it. I chose NXP's LPC series.

mbed

The mbed is a development board with either a LPC11U24 (Cortex-M0) or LPC1768 (Cortex-M3). It is built on a board with two rows of 0.1" pins suitable for mounting on a breadboard. The mbed is kind of like the ARM equivalent of AVR's Arduino: it is easy to program and has wrappers for most hardware and peripheral functions. The IDE and compiler are web-based so you write all code in a browser-based editor and download the compiled binary file. The mbed can be attached to the computer (Mac, Windows or Linux) by a USB cable and will appear as a USB mass storage device (aka "a disk"). Firmware is flashed by copying over the binary file to the USB disk and resetting the mbed.

Code for the mbed is written in C++ and uses libraries for hiding all the hardware register stuff. An example program for flashing a LED (really, really fast) looks like this:

#include "mbed.h"

DigitalOut myled(LED1);

int main() {
    while(1) {
        myled = 1;
        myled = 0;
    }
}

But it is also possible to forego the mbed.h libraries and use straight-up ARM C code in the mbed online IDE. Which appeals to me because I would like not to be tied to the mbed hardware and libraries so I can make my own ARM-powered devices. Here's how the same code might look in non-mbedified code (which still compiles fine in the mbed IDE):

#include "LPC11Uxx.h"

int main(void)
{
 LPC_SYSCON->SYSAHBCLKCTRL |= (1>> 6) | (1>> 16);
 LPC_IOCON->PIO1_8 = 0x00000080;
 LPC_GPIO->DIR[1] = 0x00000F00;

    while( 1 )
        LPC_GPIO->PIN[1] ^= (1>> 9);

    return 0;
}

One comment on "From AVR to ARM"

[...] MCU: NXP LPC11U24 ARM processor. I’m thinking that is a good project to start switching from AVR to ARM. [...]

Leave a Reply