AN 425: Using the Command-Line Jam STAPL Solution for Device Programming

ID 683089
Date 12/09/2016
Public
Document Table of Contents

1.7.2.2. Step 2: Map the JTAG Signals to the Hardware Pins

The jbi_jtag_io() function in jbistub.c contains the code that sends and receives the binary programming data. By default, the source code writes to the parallel port of the PC. You must remap all four JTAG signals to the pins of the embedded processor.
Figure 11. Default PC Parallel Port Signal MappingThis figure shows the jbi_jtag_io() signal mapping of the JTAG pins to the parallel port registers of the PC. The PC parallel port hardware inverts the most significant bit: TDO.


PC Parallel Port Signal Mapping Sample Source Code for jbi_jtag_io()

int jbi_jtag_io(int tms, int tdi, int read_tdo)
{
    int data = 0;
    int tdo = 0;

    if (!jtag_hardware_initialized)
    {
        initialize_jtag_hardware();
        jtag_hardware_initialized = TRUE;
    }
    data = ((tdi ? 0x40 : 0) | (tms ? 0x2 : 0));    /*TDI,TMS*/
    write_byteblaster(0, data);

    if (read_tdo)
    {
        tdo = (read_byteblaster(1) & 0x80) ? 0 : 1; /*TDO*/
    }
    write_blaster(0, data | 0x01);                  /*TCK*/
    write_blaster(0, data);

    return (tdo);
}
  • The PC parallel port inverts the actual value of TDO. Because of this, the jbi_jtag_io() function in the preceding code inverts the value again to retrieve the original data in the following line:
    tdo = (read_byteblaster(1) & 0x80) ? 0 : 1;
  • If your target processor does not invert TDO, use the following code:
    tdo = (read_byteblaster(1) & 0x80) ? 1 : 0;
  • To map the signals to the correct addresses, use the left shift (<<) or right shift (>>) operator. For example, if TMS and TDI are at ports 2 and 3, respectively, use this code:
    data = (((tdi ? 0x40 : 0) >> 3) | ((tms ? 0x02 : 0) << 1));
  • Apply the same process to TCK and TDO.

The read_byteblaster and write_byteblaster signals use the inp() and outp() functions from the conio.h library, respectively, to read and write to the port. If these functions are not available, you must substitute them with equivalent functions.