Friday, April 10, 2009

Poor man's JTAG programmer for the Atmel NGW100

The NGW100 Network Gateway Kit from Atmel is a fantastic and inexpensive way for hobbyists to get into embedded Linux development. Unfortunately, the same cannot be said of the AVR JTAGICE MK II programmer which Atmel developed to allow debugging and external Flash programming on AVR32 platforms. The NGW100 can be had for US$89 from Digi Key, but the JTAGICE MK II retails for US$299, out of the reach of most hobbyists (myself included).

Happily, an alternative (and open source) solution has come onto the market thanks to the clever fellows at Embedded Projects. The USBprog is an open source JTAG programmer which has been designed to accommodate as many micro controller variants as possible through the use of easily up-datable firmware.

After working with the AVR32 on a commercial project I neglected to realise that the version of the U-Boot bootloader installed by default on the NGW100 executes out of Flash rather than SDRAM. My attempt to update the bootloader in Flash from the U-Boot command line left me with a "bricked" board.

I purchased the 5V to 3.3V Level shifter and USBprog v3.0 from Embedded Projects for EUR48.70 including shipping to Australia (about AU$90 on current exchange rates). My order arrived within a week despite the fact it was shipped from Augsburg, Germany. Nice.

The documentation on how to set up the USBprog to program the Flash on the NGW100 is sparse, so I'll reproduce the method I used here.

The first step is to install the USBprog software and download the correct firmware to the device. I used Ubuntu, but Windows binaries are also available. USBprog under Linux has the following package dependencies:
  • build-essential (g++)
  • libwxgtk2.8-dev (wxWidgets)
  • libusb-dev
  • libxml2-dev
  • libcurl4-openssl-dev
  • libreadline5-dev
Use Synaptic or apt-get to install these packages. Next download and extract the USBprog sources, which can be found here. Open and terminal and enter ./configure followed by make to compile the source. Connect the USBprog, then cd to the gui folder and execute ./usbprog-gui.

The USBprog should appear in the first drop-down box under Device. If it doesn't, it may be necessary to place a jumper on pins 2 and 3 of JP3 to force the device into programming mode, which is indicated by a flashing red LED. The firmware image can be found on the USBprogAVR32 page of the Embedded Projects website. Select the Local Disk option and browse to the firmware image. Click Update to download the firmware to the device.


The next step is to connect the 5V to 3.3V Level Shifter board to the NGW100 using a set of flying leads. I carefully cut up and old Xilinx Parallel 3 JTAG cable for this purpose - I was even lucky enough to have most of the data lines to the correct labels on the cable. The table below shows the pin configuration I used. (Note that some pins are not connected).


5V to 3.3V Level Shifter (J1)PinPinNGW100 JTAG Connector
TDI
1
9
TDI
VREF
2
4
3.3V
SRST
3
6
RESETN
TRST
4
8
TRSTN
TMS
5
5
TMS
TCK
7
1
TCK
TDO
9
3
TDO
GND
10
2
GND


When everything is connected it should look a little like this:



Download the usbprogavr32 executable from the Embedded Projects web site, power up the NGW100 and execute ./usbprogavr32 detect. My unit responds with the following:

USBProg AVR32 programmer

Firmware version is 1.
Detecting ...
Found AVR32 AP7000, Rev.2.
Found flash chip AT49BV642D.


At this point it is possible to program the U-Boot binary into the device using the command ./usbprogavr32 -f u-boot.bin. The latest U-Boot binary can be found here, or compiled using the Buildroot source.

Firmware version is 1.
Detecting ...
Found AVR32 AP7000, Rev.2.
Found flash chip AT49BV642D.
Note: not specify programming size,
using the file size (14058) instead.
Erasing sectors ..[DONE]
Erased 2 sector(s). Used 30 seconds.
Programming ............................[DONE]
Programmed 14058 bytes. Used 102 seconds.


Well done to the people at Embedded Projects. Atmel has released the details of the JTAGICE mkII Communication Protocol, so perhaps one day we'll even have support for debugging.