Ethernut Home Hardware Firmware Tools Download Community
 
 
Search | Legals | Deutsch

In-System Programming

Application development for embedded systems is usually done on a desktop computer (PC), using a high level language like C or assembly language. After the executable binary has been created by the cross development tools, this binary needs to be uploaded to the target board. In most cases it will go to some kind of non-volatile memory, requiring specific programming procedures.

While in earlier days a chip had been removed from the target board and placed in a programming device, today's microcontrollers and external memory chips can be re-programmed without being removed from the circuit. This is called in-ciruit or in-system programming.

For in-system programming the following items are needed

  1. A software tool running on the desktop computer, which is able to control the programming interface via any standard port.
  2. A programming adapter which allows to connect the programming interface to any standard port available at the PC, like USB, RS-232, printer port etc.
  3. A special programming interface like SPI (Serial Programming Interface), JTAG (Joint Test Action Group) etc.

All three requirements must be fulfilled somehow, but there is a large variety of real world implementations. For example, the programming adapter may be integrated on the target board. In that case, for example, a USB cable may be used to directly connect the PC to the target board. Sometimes the programming interface is accessible by special microcontroller instructions or registers, which allows to load new firmware.

This document will present various in-system programming methods used with the popular AVR and ARM microcontroller families.

Programming Software

There are quite many tools available, each of which supports its own set of programming adapters, interfaces and targets. And, quite important, not every tool is available for every desktop operating system.

These tools either run on a command line (CLI) or provide a graphical user interface (GUI). Each has its advantages and disadvantages. While CLI tools are perfect for automation, the large number of available options are easier to handle manually with GUI tools. Some tools offer both worlds: A graphical interface controls an underlying command line tool, which can alternatively run without the GUI.

Some programming adapters, like the Zylin ZY1000 (see below) have an integrated programming software, being controlled by a web interface, which makes them practically independent from the operating system of the desktop computer.

Free Programming Software

Product Open
Source
Supported
OSes
CLI GUI Supported
Targets
AVRDUDE Yes Linux
Windows
OS X
Yes Yes AVR
AVR Studio 4 -  
Windows
 
Yes Yes AVR
JTAG-O-MAT Yes Linux
Windows
 
Yes - ARM
OpenOCD Yes Linux
Windows
OS X
Yes - ARM
SAM-PROG -  
Windows
 
? Yes ARM
UISP Yes Linux
Windows
 
Yes - AVR

PC Ports used with In-System Programming

The most simple programming adapters are available for the parallel printer port. Typically they are not much more than a logic buffer or level converter attached to the parallel printer port, sometimes a few resistors do the trick. Today you will hardly find a PC that has this ancient interface, but some companies still offer adapter cards for the PCI bus.

Like parallel printer ports, the RS-232 (COM port) interface has been largely replaced by USB. However, RS-232 serial ports are still popular with embedded systems. More advanced programming adapters are based on microcontrollers and nearly all of these controller provide at least one UART, the logic part for doing RS-232 communication. Thus, programming adapters with RS-232 ports are still in use today. Several companies offer USB to RS-232 converters, but not all of them work flawlessly.

USB is much more complex than the parallel printer port or RS-232, but an increasing number of microcontrollers provide this interface. Hence, more and more programming adapters are offered for the USB port, because it is available on almost any PC. After FTDI offered a special chips, which can do JTAG programming via USB without the need to write any firmware, the prices of JTAG programming adapters for USB dropped significantly.

While talking about prices it should be noted, that they vary widely, starting at a few bucks up to several thousand dollars. This is well-grounded in most cases and based on higher programming speeds, unique features, strong support etc.

One disadvantage of USB is its limited cable length. Today's most advanced programming adapters offer Ethernet connectivity and allow remote programming and debugging over the Internet.

AVR In-System Programming

There are a number of ways to program internal flash memory of AVR microcontrollers:

The STK200 dongle is a simple, low cost ISP programming adapter for the parallel printer port. It had been initially included in Atmel's STK200 starter kit, which is no longer available. Many companies still offer clones of this adapter and several schematics are available as well.

Atmel offers two programming adapters for the AVR: First, the low cost AVR ISP mkII with, as its name applies, ISP programming interface. On the PC side it connects to the USB port. And second the more advanced JTAGICE mkII (picture on the right) with JTAG and debugWIRE programming capabilities via USB and RS-232. Several companies offer cheap clones of the Atmel programmers, running Atmel's firmware more or less well.

The SP Duo from Embedded Creations as well as the AVR DUO ICE from MCU ProShop are somewhat special, because they provide ISP and JTAG programming. The SP Duo has an RS-232 interface and comes with its own firmware, JTAG debugging is not supported. The AVR DUO ICE has a USB interface and supports JTAG debugging.

The

Several attempts had been made by the Open Source community to use the FT2232 for implementing a low cost JTAG adapter, without much success. Programming is very slow and JTAG debugging is unreliable due to Atmel's policy of keeping information about AVR debugging a secret.

ARM In-System Programming

In-system programming of ARM microcontrollers with internal flash memory is typically done via JTAG. One of the most simple JTAG adapters, hardware-wise, is the well known Wiggler for the parallel printer port, which had become a synonym for this type. Initially offered by Macraigor Systems, many clones are available and various schematics are published in the Internet.

The Turtelizer programming adapter is an example of a JTAG adapter for the RS-232 port. The design is based on an ATmega8 or ATmega168 microcontroller and the firmware is released under the BSD License.

Today many JTAG adapters are based on the FT2232. The chip provides two USB devices and some programming adapters use the second one to offer an additional RS-232 port. The Turtelizer 2 is one example of such an adapter and is published as Open Source Hardware.

The Norwegian company Zylin AS, well known for its Embedded CDT plugin for Eclipse and its OpenOCD contributions, offers one of the most advanced JTAG adapters available today. Based on Open Source software, the ZY1000 programming adapter is actually a tiny Linux system with Ethernet and JTAG interface, integrating OpenOCD and a web server. A web browser is all you need for programming ARM devices (click on the picture).

In-System Programming of External Memory

Due to the Harvard architecture with mixed 8 bit data and 16 bit instruction code bus, program execution of all members of the 8 bit AVR family is limited to internal flash memory. This is true, even if an external bus interface is available. Nevertheless, external flash memory may be used as non-volatile data memory.

ARM microcontrollers with external memory bus are not limited in this way. A large number of ARM microcontrollers does not even provide any internal flash memory and firmware must be stored in external memory chips.

There are at least two major procedures for in-system programming of external memory devices. The first is based on JTAG boundary scan, which allows to toggle almost any pin of a JTAG enabled device. If all programming pins of the memory chip are tied to such a devices, JTAG boundary scan can be used to apply the programming sequence to the memory chip. This has the advantage, that no initial software is required on the target board, because JTAG boundary scan is implemented in pure hardware. But, as you can imagine, this may become time consuming.

The second method uses the JTAG debugging interface, which allows to let the CPU execute single instructions. This way a programming sequence for the external memory chip can be executed, step by step. This is signigicantly faster than the boundary scan method, but requires, that the CPU is initialized and running. A variant of this method can be used with some RAM available. Instead of emulating single instructions, the whole procedure is uploaded and then run by the CPU. The contents that needs to be programmed into the external memory chip may be transfered through another interface or use the JTAG cable itself, if a so called JTAG COMM interface is provided.

Boot Loading Firmware

In general, boot loaders transfer an executable binary from some kind of external device to on-board memory and jumps to a specific entry point of this binary to execute it. This is typically done after power-on or after resetting the system and not too complicated when using RAM. In other words: A standard boot loader will load the binary image into volatile memory each time the system is started.

Firmware boot loaders are somewhat different. They are able to program non-volatile memory and are only needed during so called firmware updates. Thus, they will be activated on demand only. If internal flash is used, the device must provide self-programming capabilities.

AVR Firmware Boot Loaders

The tricky part on the AVR is, that program code can run on internal flash only. Programming the same flash that runs the flashing code must fail, because during programming cycles the CPU won't be able to load the next instruction code. Fortunately, flash memory has been devided into two parts, the application and the boot area. A program running in either of the two is able to program the other area.

ARM Firmware Boot Loaders

Almost all AT91SAM devices have a boot loader stored in internal ROM, called SAM-BA. A programmable, non-volatile bit in the chip decides, whether the CPU starts the boot loader or the previously uploaded firmware after hardware reset. When erasing the device, the boot loader will be activated.