jenswilly.dk


Archive for July, 2012

From AVR to ARM

27. July 2012 23:23 by Jens Willy Johannsen
Categories: 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;
}
Comments 1 comment »

Flashing LPC11U24 or LPC1343 from Mac OS X

27. July 2012 22:53 by Jens Willy Johannsen
Categories: ARM

Here is how to flash an LPC11U24 or LPC1343 from Mac OS X using the ROM-based USB bootloader.
This post is just code snippet-style and I'm assuming you have a compiled .bin file and have the MCU connected with a USB cable so a disk named "CRP DISABLD" appears on the desktop.

  1. Add the required checksum using the crc executable as described here: http://vn1k.blogspot.dk/2010/11/lpc1343-loading-binaries-using-on-chip.html
  2. In Terminal do
    $ df -h

    to identify the filesystem device that is mounted as the CRP DISABLD disk. It will be something like "/dev/disk1" (which I will use in this example).

  3. Unmount the disk using
    $ diskutil unmount /dev/disk1
  4. Copy binary file to device using
    $ dd if=firmware.bin of=/dev/disk1 seek=4

    This is where the tricky stuff happens. In order for everything to work we must write data beginning at sector 4. And if we just copy the file in the Finder the OS will start at sector 6.

The info here is extracted from http://vn1k.blogspot.dk/2010/11/lpc1343-loading-binaries-using-on-chip.html and http://jogglerwiki.info/index.php?title=Writing_image_files_to_USB_drives

No comments No comments »