Friday, April 20, 2012

Road Testing an ARM LPC2101: Part 2

At long last I've successfully programmed my ARM7. I developed my own breakout board and switched to an LPC2103, an upgraded version of the LPC2101 I started the road test with.

Creating a simple "Hello World" application on an ARM7 proved to be non-trivial but now I have it sorted out for an LPC2103. Here's everything you need to know to get started with your LPC2103...

Integrated Development Environment

First, you'll need an Integrated Development Environment. My IDE of choice for now is the IAR Systems Embedded Workbench for ARM (EWARM), Kickstart edition. It's free, although code size is limited to 32k. As the LPC2103 can only fit 32K of code in flash memory this is a non-issue for this processor.

EWARM is fast; I run it on a pokey old 2.8GHz Pentium D without complaint. It provides a nice, familiar user experience similar to those of NetBeans, Eclipse and other industry standard IDEs.

IAR EWARM with my UART test code
On the left is a navigation pane showing file navigation and/or project code navigation, and possibly other things I've not tried. Status information and build output appears in a window below. Collections of files are called Workspaces, another familiar paradigm.

One nice feature is the tool provides tutorials, user guides, example projects, integrated Real-Time Operationg Systems, all available from an initial Information Center window.


To configure your project to work with the LPC2103, right click on your top level project node and select Options... from the contextual menu that appears. Under General Options select your device under the Processor Variant area. Select NXP LPC2103.

Additionally, in EWARM, one must configure the memory map and stack sizes for your process. Under the Options... dialog, select Linker. You'll see the path to the .icf configuration file. Click Edit.

Configure the memory regions used by your processor under the Memory Regions tab. Presumably the LPC2101 numbers would be smaller since it only has 2K of SRAM not 8K like the LPC2103.

Set the sizes for your stacks and heap under the Stack/Heap Sizes tab-- if you know what you're doing. Presumably you want small stack sizes for a processor that is severely SRAM challenged. The numbers above and below are what came with the LPC2103 example programs I used.

Arcane ARM7

ARM7 micros require something called startup code to initialize stacks, stack pointers, vectored interrupt controller, and such. On the ARM7 this code must be written in assembly language. Coming from the worlds of AVR or Propeller, this is unfamiliar territory. Luckily, it's provided within the IAR Embedded Workbench tool if you start with an example program.

Where To Get Example Code

Your best bet is to start with an existing, working example and tweak it.

My Own Simple Examples

I've put together two simple projects (download; also in source here). The first blinks an LED connected to P0.12. The second sends "Hello World!" to UART0. The LED blink is very straightforward. The UART example is based on code in an NXP Application Note. I recommend taking a look at this first as both programs are fairly simple.

IAR Examples

Or, in the IAR EWARM tool, select Information Center from the Help menu. Then click on Example Projects. Select NXP as the manufacturer, LPC2103, and then choose the IAR LPC2103 Mini Board. Click Open Project when the LED Blink project appears.

This project is fairly complicated using timers and interrupts extensively. It's also designed for a board with LEDs and buttons.

Once you've saved the code somewhere, you can open the .eww file, the Embedded Workbench Workspace. It should load up into the IDE.

Programming the Microcontroller

One really cool feature about many of the LPC chips, the LPC210x family included, is a factory-supplied serial bootloader. Yes, that's right, just like the Arduino AVR Bootloader. No need for costly JTAG hardware.

Flash Programmer Software

You'll need a tool to upload your firmware and the favorite tool is Flash Magic. It takes a .hex file and does everything else needed to upload to the microcontroller. Where does the .hex file come from?

Making Hex Files

The EWARM compiler has to generate it. And you have to tell it to do so. In EWARM, right click the project workspace and select Options... and then under Output Converter, check Generate additional output. Select Intel extended from the Output format pulldown menu.

USB to Serial Adapter

I use an older version of the 5V Sparkfun FTDI breakout which exposes DTR, RXI, TXO, VCC and GND. Any USB to Serial programmer that exposes DTR will work.

My LPC2101 breakout board has a header for the FTDI board which supplies power to the onboard regulators, resets the chip through DTR and communicates with the Bootloader and UART0.

Configuring Flash Magic

One last step and then you can compile your code and program your ARM. Configure Flash Magic with the correct processor type. Click the Select device... button and select LPC2103 from the list.

Now select the baud rate and COM port. I found that some rates worked better than others; 38400 seems a bit more reliable than 14400, for example. You might want to try 9600bps at first and try increasing speed later.

Plug in the FTDI, enable programming (on my board, flip the switch to PGM) and then select Read device signature from the ISP menu. If this works, you should have no trouble programming your device.

Program Your Hex

Click the Browse button under Step 3 - Hex File in Flash Magic. Find the hex file under a subdirectory within your project workspace. In my example projects, the subdirectory is Output\Exe.

To be safe, check the Verify after programming checkbox to make sure what's on the device is what's in the hex file. If you find the programming to be reliable, skip this step if you want.

Now click Start and Flash Magic will do the rest. When you're ready to run the program disable program mode (flip the slider switch away from the PGM position for my breakout board) and press the reset button.

Et Voila

That's it, you're done. Hopefully everything went well and you now have example code running on your mcu.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.