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

Ethernut 3 JTAG

During the development phase it is recommended to use the TFTP based bootloader for Ethernut 3, which is much faster than any other method to upload the compiled code from the PC into the Ethernut 3 RAM.

JTAG programming is required to initially burn the bootloader into flash memory or to permanently store application code.

Beginners may first get confused, because JTAG had been specified by the Joint Test Action Group (see logo) for testing electronic boards using boundary scan. Today it is also widely used for software debugging, which includes uploading and downloading (programming) of memory contents.

The IEEE Std 1149.1 (JTAG) Testability Primer from Texas Instruments provides a good introduction to JTAG.

JTAG Signals

Only four core signals are required to meet the initial IEEE Std 1149.1-1990.

The following lines are optional. Some of them are useful and some are required by specific targets.

Programming Hardware

Any JTAG adapter for the ARM7TDMI may be used, but the connector layout on Ethernut 3 is kind of alien in the world of ARM CPUs. See the next chapter.

The most simple adapter for the PC's parallel printer port, a so called Wiggler compatible adapter can be easily built without much effort. A sample schematic is available at jtag-arm9.sourceforge.net. However, this one uses a 74AC244 buffer and may not work reliable with 3.3V targets like Ethernut 3. When driven by a 3.3V power supply, the lines from the parallel port may raise above Vcc + 0.5, which violates the absolute maximum ratings given in the datasheet. In the worst case, voltages above 3.3V may appear on the target side of the JTAG adapter and destroy the target board. The 5V tolerant versions 74LVC244 or 74LVX244 are better choices, but are available as SMD parts only, requiring some soldering skills. As an alternative you can use the 74HC244 and add 220 Ohm series resistors between the chip inputs and the parallel port outputs. Internal diodes clamp the voltage at the inputs and the series resistors will limit the resulting current.


The original Wiggler shown above can be purchased from www.macraigor.com. It comes with software, which supports a large number of target devices.

A not so simple adapter is the Turtelizer, which is included in the Ethernut 3 Starter Kit from www.egnite.de. The hardware is actually based on a modified SP Duo Adapter, which is a commercial product developed by Embedded Creations for the AVR. and schematics are not published. However, with minimal AVR experience, it should be not to difficult to build a similar board, if you want to. In general the Turtelizer contains an ATmega8L and an RS232 level shifter.

Last not least an Ethernut 1 or 2 may be used to run the Turtelizer firmware and make the most expensive JTAG adapter for the JTAG-O-MAT.

Ethernut Connector And De-Facto Standards

On all Ethernut Boards the same connector layout is used for JTAG, which is the same as the one used by Atmel for the AVR and which is used by most AVR based boards.

Ethernut 10-Pin JTAG Connector
TCK - 1 2 - GND
TDO - 3 4 - VTref
TMS - 5 6 - nSRST
Vsupply - 7 8 - NC
TDI - 9 10 - GND

A similar layout is used by Altera.

However, most ARM based boards use a different connector, either with 14 or 20 pins. You can still use a programmer with one of these connectors, but a cable adapter will be needed.

Additional ground wires at the 14-pin connector allow higher transfer rates on longer cables.

Standard 14-Pin JTAG Connector
VTref - 1 2 - GND
nTRST - 3 4 - GND
TDI - 5 6 - GND
TMS - 7 8 - GND
TCK - 9 10 - GND
TDO - 11 12 - nSRST
VTref - 13 14 - GND

The 20-pin connector designed by ARM offers three additional control lines (RTCK, DBGRQ and DBGACK) including additional ground lines for better signal integrity. Today this is the most common JTAG connector layout for ARM CPUs.

Typically a dual row pin header with 0.1" or 0.05" pitch is used, either vertical or angled.

Standard 20-Pin JTAG Connector
VTref - 1 2 - Vsupply
nTRST - 3 4 - GND
TDI - 5 6 - GND
TMS - 7 8 - GND
TCK - 9 10 - GND
RTCK - 11 12 - GND
TDO - 13 14 - GND
nSRST - 15 16 - GND
DBGRQ - 17 18 - GND
DBGACK - 19 20 - GND

For real-time tracing additional signal lines may be required. For the ARM Embedded Trace Macrocell a 38-pin connector is recommended, which combines an ETM trace port with a JTAG interface.

38-Pin AMP Mictor Connector
N/C - 1 2 - N/C
N/C - 3 4 - N/C
GND - 5 6 - TRACECLK
DBGRQ - 7 8 - DBGACK
nSRST - 9 10 - EXTTRIG
TDO - 11 12 - Vtref
RTCK - 13 14 - Vsupply
TCK - 15 16 - TRACEPKT[7]
TMS - 17 18 - TRACEPKT[6]
TDI - 19 20 - TRACEPKT[5]
nTRST - 21 22 - TRACEPKT[4]
TRACEPKT[15] - 23 24 - TRACEPKT[3]
TRACEPKT[14] - 25 26 - TRACEPKT[2]
TRACEPKT[13] - 27 28 - TRACEPKT[1]
TRACEPKT[12] - 29 30 - TRACEPKT[0]
TRACEPKT[11] - 31 32 - TRACESYNC
TRACEPKT[10] - 33 34 - PIPESTAT[2]
TRACEPKT[9] - 35 36 - PIPESTAT[1]
TRACEPKT[8] - 37 38 - PIPESTAT[0]

Programming Software

Any programming software with ARM7TDMI support may be used.

As far as we can say, the situation for Open Source Software is dissatisfactory. Either it is not available for Linux or Win32 or never has been finished or is too specific towards a special programmer or target or it simply doesn't work. Finally we decided to create a separate Project at SourceForge, called JTAG-O-MAT.

This utility is far from being perfect, but the full source code is provided and it works half-way reliable for Ethernut 3 with the Turtelizer (on Linux and Win32) or the Wiggler programming adapters (currently Win32 only).

Restoring the Bootloader

If the bootloader is destroyed by accident or if you need to replace it with a different version, you can use the JTAG-O-MAT utility.

jtagomat-1.2.7.exe Windows Installer.

jtagomat-1.2.5.tar.bz2 Linux Source Package.

To install, follow the instructions on the SourceForge Project Page.

Next you need to download the bootloader code.

bootmon-1.0.2.zip
contains the source code as well as a pre-compiled binary. Best unpack it in your Nut/OS application directory, the sample directory created by the Nut/OS Configurator. However, any other place will be OK too.

Connect the Turtelizer Programming adapter to the first serial port of your desktop PC using a 9-pin Null Modem Cable and connect the flat cable with the 10-pin JTAG connector of your Ethernut 3 board. Make sure that the JTAG jumper on the Ethernut Board is configured for programming the AT91 CPU as shown in the following image. Finally switch on the Ethernut 3 power supply, which will also power up the Turtelizer.

AT91 Programming Jumper

JTAG-O-MAT is a command driven tool running on the command line. In order to avoid typing the same commands over and over again, you can create so called JOM files, which are basically text files containing a sequence of commands.

A file named at91-upl.jom is included in the archives and has been prepared to upload code to the Ethernut 3 RAM or FLASH memory. To upload the bootloader into flash memory, change to the directory that contains the bootmon.bin file.

$ cd bootmon
On Windows you need to add the bin directory of the JTAG-O-MAT to your PATH environment.
> SET PATH=C:\jtagomat-1.2.7\bin;%PATH%
This directory contains the JTAG-O-MAT executable as well as the JOM files and a target binary named flasher.bin.

On Linux it is typically not required to extend the PATH environment. After installation the executable will be stored in /usr/local/bin/ and the other files in /usr/local/etc/.

Now enter

$ jtagomat -DDEVICE=0x1F0F0F0F -DIMAGE=./bootmon.bin BATCH at91-upl.jom FLASH
on the command line. Here's the meaning of the command line parameters: You may take a look into the jom file and refer to the JTAG-O-MAT Command Reference.

If everything works as expected, the following output should appear

Reset OK, uploading flasher...
Upload OK, starting flasher...
Flasher running and flashing ./bootmon.bin
./bootmon.bin flashed, resetting target
If something went wrong, for example you may get
Bad device, expected 0x1F0F0F0F
then simply enter the command again. Either the JTAG-O-MAT utility or the Turtelizer firmware seems to contain a bug and stopping the target CPU sometimes fails. It may also help to stop the CPU first, before starting the upload batch.
$ jtagomat -v HALT
The additional command line parameter '-v' enables the JTAG-O-MAT verbose mode, which produces additional output in the command line window. In this case the Turtelizer's firmware revision is displayed.
Turtelizer 1.2.4
You may also add the '-v' option to the command line that uploads the bootloader.
$ jtagomat -v -DDEVICE=0x1F0F0F0F -DIMAGE=./bootmon.bin BATCH at91-upl.jom FLASH
This produces a lot of additional output and helps to track down problems.

If you connected the Turtelizer to the second serial port of the PC, use

$ jtagomat -a /dev/ttyS1 -DDEVICE=0x1F0F0F0F -DIMAGE=./bootmon.bin BATCH at91-upl.jom FLASH
on Linux or
> jtagomat -a com2 -DDEVICE=0x1F0F0F0F -DIMAGE=./bootmon.bin BATCH at91-upl.jom FLASH
on Windows.

Flashed Applications

When an application has been tested, you may want to flash it into Ethernut's non-volatile memory, so it boots up every time power is applied or reset is pressed.

The first thing that needs to be done is to change the default setting of your build tree. Start the configurator and change the linker script from at91_ram to at91_boot.

ROMed Applications

Then rebuild the build tree and your application, in this order. Your application will no longer run in RAM. Instead, it is expected to get started in flash memory and will copy itself into RAM.

We can use the same command as with the bootloader to burn the application's binary image into flash memory

$ jtagomat -DDEVICE=0x1F0F0F0F -DIMAGE=./httpserv.bin BATCH at91-upl.jom FLASH
The at91_boot linker script will implement a different runtime initialization, which copies the code from Flash Memory to RAM. Thus, the code is still executed at full speed in the 32 bit internal RAM and still limited to 256 kBytes total memory for code and data. Currently no linker script is available for programs running directly in Flash Memory. Of course, with some experience it is possible to create your own linker scripts.

Flash Memory Layout

Flash Memory DIP Switch

As explained in Ethernut 3 Memory Map, after system reset the flash memory is located at address 0x00000000 and will be remapped later to 0x10000000. This remapping is done by the bootloader or may be done via JTAG before uploading the application code into RAM (see at91-remap.jom).

Beside that, Ethernut 3 contains a tiny double slide switch, located between the JTAG connector and the reset button. This slide switch divides the 4 MByte flash memory chip into four pages.

As shown in the schematic, the switch selects either the original or the negated signal of address bits 20 and 21. This way the following absolute flash memory addresses are moved the CPU address space (after remap):

Flash Memory DIP Switch

SW A20 SW A21 Chip Address CPU Address
Ori Ori 0x00000000
0x00100000
0x00200000
0x00300000
0x10000000
0x10100000
0x10200000
0x10300000
Neg Ori 0x00100000
0x00000000
0x00300000
0x00200000
0x10000000
0x10100000
0x10200000
0x10300000
Ori Neg 0x00200000
0x00300000
0x00000000
0x00100000
0x10000000
0x10100000
0x10200000
0x10300000
Neg Neg 0x00300000
0x00200000
0x00100000
0x00000000
0x10000000
0x10100000
0x10200000
0x10300000

The address line is negated, if the slide switch is moved towards the reset switch and not negated if moved towards the JTAG connector. The slider at the edge of the board is the one that switches address bit 20.

TODO
An unsolved problem is, how to determine by software, which of the 4 pages are mapped to which CPU address. Not knowing that makes it difficult to correctly erase the flash memory, because the AT49BV322A used on Ethernut 3 has 63 pages of 64 kBytes and 16 pages of 8 kBytes. The latter are located at chip relative addresses 0x00000000 to 0x0001FFFF. Thus the smaller pages move when changing the slide switch settings.