Monday, June 6, 2011

Open-source tools for ARM microcontrollers

The ARM (Advanced RISC Machine) architecture appears in many 32-bit microcontrollers. I have NXP (Philips) LPC2138 (ARM7TMDI-S) and Luminary Micro LM3S811 (ARM7 Cortex-M3) microcontrollers. Embedded software development is well supported by open-source tools.

My current preferred development environment is Cygwin running under Windows, but Linux works well too. The GNU cross compiler for ARM7 can be built to run with Cygwin. Binutils, GCC, and GDB source code can be configured and compiled under Cygwin. The graphic user interface for gdb is available with insight and ddd. Windows Emacs also works with gdb. The Cortex-M3 support is not available with earlier versions of GCC. A relatively compact C library can be built from newlib.  The flash programming for LPC21xx can be done with the open source program lpc21isp.

The ARM7 microcontrollers have on-chip debugging capability with JTAG interface. Openocd (Open On-Chip Debugger) is the package for flash memory download and debugging interface for gdb. Openocd supports a number of JTAG hardwares, including simply parallel port "wiggler" interface, USB FT2232 interface. It can also be built under Cygwin. The parallel port interface requires the giveio driver (from AVRDUDE). The driver package (including .h and .lib) from FTDI can be used for the FT2232 interface. An open-source driver for FT2232 is also available.

The Luminary Micro's LM3S811 eval board use FTDI's FT2232 chip to drive the JTAG signals. It can also be used as the JTAG interface for external devices. Despite of lacking TRST (Tap Reset) and SRST (System Reset) signals at the external connector, it is able to interface with LPC2138. A small modification to the LM3S811 eval board allows the control of TRST. By lifting the resistor connecting to the USB_RSTn line and soldering a haywire to the connector TRST pad, we have the control of TRST. When we debug the on-board microcontroller, we need to insert a jumper wire between the TRST pin and the external debug pin. Note that the existing openocd software thinks it is toggling SRST, but I found it works quite well with LPC2138.  [Update: The later version of the LM3S811 Eval board has the SRST signal added.]
Modified to debug external device with OpenOCD.

Thus embedded software development is possible with the set of open-source tools. If a real-time operating system is desired, FreeRTOS has been ported to a number of ARM microcontrollers.

However, it is worth noting that the code generated by the GNU compiler seems far less efficient than the commercial compilers.  My single-precision Whetstone benchmark testing has shown it to be 6 times as slow and double-precision to be 3 times as slow with almost 3 times of code size.