Manual setup of JTAG chain

From SEGGER Wiki
Jump to: navigation, search

This article expects the reader to have a basic understanding about how JTAG works. Otherwise, we recommend to have a look into this article first: https://en.wikipedia.org/wiki/JTAG

Introduction

As the JTAG interface allows to daisy-chain devices (TAPs), J-Link has some certain level of JTAG chain auto-detection logic, to auto-detect the correct position of a device inside a given JTAG chain. This is necessary as when communicating with one device, the other ones in the chain should be in BYPASS state which can be achieved by shifting all 1s in their instruction register (IR). However, for that the J-Link has to properly detect how many stuff bits (1s) need to be added before and after the device J-Link is supposed to communicate with. This requires that J-Link knows the exact bit position of the device inside the JTAG chain. Unfortunately, the JTAG chain auto-detection has its limits because:

  • The JTAG specification does not provide a way to reliably detect the IRLen of a device in the JTAG chain, as only the first 2 bits of the IRPrint are defined by it.
  • There are devices/TAPs that do not behave JTAG compliant regarding their IRPrint

For these cases it might be necessary, to manually specify the JTAG chain and the position of the device to communicate with, via a J-Link script file.

Device counting

J-Link starts counting the TAPs with #0 where #0 is the TAP that is closest to TDO:

TDI -> #3 -> #2 -> #1 -> #0 -> TDO

This is because when shifting data, the data from device #0 is received by J-Link first.

Sample J-Link script file

It is recommended to set up the JTAG chain inside the ConfigTargetSettings() routine of J-Link script files manually. The following code example demonstrates how to manually setup a JTAG chain with 4 devices in it, where 3 of the devices are unknown to J-Link.

void ConfigTargetSettings(void) {
  JLINK_SYS_Report("J-Link script file: Manually configuring JTAG chain");
  JLINK_JTAG_SetDeviceId(0, 0x5BA00477);  // IRLen: 4 => CoreSight DAP (This is the one we want to communicate with)
  JLINK_JTAG_SetDeviceId(1, 0x149511C3);  // IRLen: 4
  JLINK_JTAG_SetDeviceId(2, 0x149511C3);  // IRLen: 4
  JLINK_JTAG_SetDeviceId(3, 0x149511C3);  // IRLen: 4
  //
  // Pre-select CoreSight DAP to be the one J-Link shall communicate with, for this session
  //
  JLINK_JTAG_IRPre  = 0;   // Sum of IRLen of all JTAG TAPs preceding the one we want to communicate with
  JLINK_JTAG_DRPre  = 0;   // Number of JTAG TAPs preceding the one we want to communicate with
  JLINK_JTAG_IRPost = 12;  // Sum of IRLen of all JTAG TAPs following the one we want to communicate with
  JLINK_JTAG_DRPost = 3;   // Number of JTAG TAPs following the one we want to communicate with
  JLINK_JTAG_IRLen  = 4;   // IRLen of device we want to communicate with
  return 0;
}

File download

File:ManualJTAGChain.JLinkScript

For more information about how to use J-Link script files in different environments, please refer to IDE and Debugger specifics