Simple ARM example for LPC1114

My colleagues Frank Duignan and Richard Hayes have been experimenting with an ARM Cortex M0 microcontroller in a dual inline package (DIP) which can be plugged straight into a breadboard. The chip they’re using is LPC1114FN28/102, which is made by NXP and is available for less than €2. Frank spent a bit of time working out how to program the chip using a low-cost USB-to-serial converter, so the whole thing provides a micrcontroller programming setup that’s incredibly inexpensive, but quite powerful!

Following Frank’s instructions, I’ve just got my first simple flashing LED example working on the ARM LPC1114. Here’s a couple of snaps of my breadboard circuit:

ARM LPC1114 simple breadboard circuit

ARM LPC1114 simple breadboard circuit

The following code (filename “main.c”) is really just a stripped back version of a more extensive example Frank sent me, so I must emphasise that all credit here goes to him.

//
// main.c - Blinking LED example for ARM LPC1114
// Written by Ted Burke (based on code by Frank Duignan)
// Last updated 29-11-2013
//

#include "lpc111x.h"

int main()
{
    // Turn on clock for GPIO, IOCON and ADC
    SYSAHBCLKCTRL |= BIT6 + BIT13 + BIT16;
    GPIO0DIR = BIT8; // Make PIO0_8 an output
    GPIO0DATA = 0;   // Turn off PIO0 outputs
    
    int n;
    while(1)
    {
        GPIO0DATA = BIT8; // Turn on PIO0_8
        n=1000000; while(--n);
        GPIO0DATA = 0;    // Turn on PIO0_8
        n=1000000; while(--n);
    }    
}

I’m using the following build script (filename “build.bat”), also courtesy of Frank Duignan. Note the full path included in the linker command on line 3. If your installation directory is different from mine, you will need to modify line 3 to match your own installation folder. Note that the default installation folder may be different on other versions of Windows (note that my installation folder is under “C:\Program Files (x86)\”).

arm-none-eabi-gcc -mcpu=cortex-m0 -mthumb -g -c init.c -o init.o
arm-none-eabi-gcc -mcpu=cortex-m0 -mthumb -g -c main.c -o main.o
arm-none-eabi-ld init.o main.o -L "C:\Program Files (x86)\GNU Tools ARM Embedded\4.7 2013q3\lib\gcc\arm-none-eabi\4.7.4\armv6-m" -lgcc -T linker_script.ld --cref -Map main.map -nostartfiles -o main.elf
objcopy -O ihex main.elf main.hex

I built my program using the gcc compiler from the GNU Tools for ARM Embedded Processors. This was the version I installed (4.7 2013q3):

During the installation, the following dialog box appears. I suggest ticking the check box to “Add path to environment variable”.

Dialog box during installation of GNU Tools for ARM Embedded Processors

I used Flash Magic to transfer the compiled program (main.hex) to the microcontroller:

To compile the example code above, three more files are required: a header file “lpc111x.h”, a linker script “linker_script.ld”, and a C file called “init.c” which contains initialisation code for the ARM. All three files can be downloaded (along with lots of other useful info) from Frank’s web page. Alternatively, a quick way to get all three is to download this zip file (I just zipped the three files with Frank’s permission – thanks Frank!).

So, before building the program, my project folder contained the following five files:

ARM blinking LED project folder screenshot

Then I built the program by running the batch file build.bat.

Building a simple example program for the ARM LPC1114  - console screenshot

After building, the project folder contained the following files:

ARM blinking LED project folder screenshot

Finally, I transferred the compiled program (“main.hex”) to the LPC1114 using FlashMagic.

About these ads
This entry was posted in Uncategorized and tagged , , , , , , , , , , , . Bookmark the permalink.

11 Responses to Simple ARM example for LPC1114

  1. Dsoberoi says:

    Good, to begin with.

    Thanks

  2. Dsoberoi says:

    Will ping u for some issue. I am trying to introduce same o my students.

  3. Dsoberoi says:

    I had gone through that.
    I had received samples from NXP India and want same to be used by students now. Ur article has been a good help. Could not find “lpc111x.h”, a linker script “linker_script.ld”, and a C file called “init.c” in a Zipped file, in the link as indicated above. Pls. check the link.

    • batchloaf says:

      Hi Dsoberoi,

      Ok sorry, I see the problem now! The link Frank sent me for the zip file only works when I’m logged into my gmail. I’ve just checked with Frank if I could upload a new zip file containing those three files and he said that’s fine (thanks Frank!), so here’s the link:

      ARM LPC111 development files from Frank Duignan (lpc111x.h, linker_script.ld, init.c)

      Sorry about the confusion. I’ll update the post now with the new link.

      Ted

  4. Dsoberoi says:

    Thanks.
    Will start work, after my winter vacations. Let us see how my experiments goes ahead.

  5. Dsoberoi says:

    Thanks. Best wishes.
    Regards

  6. Kiran Manju says:

    Hi…I am having LPC2148 development board. I wanted to use Eclipse IDE with GCC compiler. So I using Eclipse IDE with the Sourcery CodeBench Lite (Bare Metal) . I started off with led_blinky. The build is successful with an warning:cannot find entry symbol _start. How do I solve this. The code did not blink any led.

    • batchloaf says:

      Hi Kiran,

      Sorry, but I’m not sure what the problem is there. You’re using a different ARM chip and development environment, so I don’t think I can offer much useful advice.

      Ted

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s