Manual setup of JTAG chain

From SEGGER - Support Wiki
Jump to: navigation, search

This article expects that there is already 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, to properly detect how many stuff bits (1s) J-Link needs to add before and after the one J-Link shall 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 spec. 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 the spec.
  • There are devices/TAPs out there 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 we want 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 do the manual JTAG chain setup inside the ConfigTargetSettings() routine of J-Link script files. 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