JTAG

Cable options such as the TCK clock frequency are read and written through Cable. Low-level TAP shift sequences are built with JtagSequence.

Warning

Cable options are hw_server state shared by every connected client, and they persist for the life of the hw_server process. A change made by one session is visible to every other session and survives session close. Always restore the original value.

Changing an option is not synchronized with other traffic on the cable. The caller is responsible for not retuning a cable while it is in active use elsewhere, for example a live ILA capture or a PDI program.

frequency is quantized to what the cable hardware can generate, and frequency_list is advisory only at this level: hw_server accepts values outside the list and snaps them to the nearest achievable rate rather than rejecting them. Vivado’s set_property PARAM.FREQUENCY <hz> [current_hw_target] reaches the same underlying option, but the two surfaces are not interchangeable. Vivado models PARAM.FREQUENCY as an enum whose members are the frequency_list values, so it validates against the list where hw_server does not, and it caches the value it requested rather than rereading it, so a value read back through ChipScoPy can disagree with what Vivado reports for the same cable.

Reaching a cable

An ordinary session with no cs_server_url is the cheapest safe recipe:

from chipscopy import create_session

session = create_session(hw_server_url="TCP:my-host:3121")
cable = session.cables.get(Serial="252502174339A")

original = cable.get_option("frequency")
try:
    cable.set_option("frequency", 3_000_000)
    ...  # slow the clock for a marginal-signal experiment
finally:
    cable.set_option("frequency", original)

Do not reach for initial_device_scan=False as an optimization. It saves very little, and it skips the cable-readiness wait, because wait_for_all_cables_ready is only called from Session.scan_devices.

Cable

class chipscopy.api.cable.Cable[source]

A Cable represents a cable connection. This may be a physical jtag cable, or a virtual cable. Zero or more devices may be associated with the cable, and each device has a position. Roughly equivalent to a vivado hw_target.

static check_for_filter_match(filters_dict, filter_name, match_value)[source]

Matches filter_by() values by equality rather than by regular expression.

Cable serial numbers and descriptions routinely contain regular-expression metacharacters, and this operation retunes hardware shared with every other client, so an accidental wildcard match is unacceptable here.

Return type:

bool

Returns:

True if filter_name is present in filters_dict and equal to match_value.

abstract property context: str

Returns the TCF context id of this cable.

Return type:

str

abstract property devices: QueryList[Device]

Returns the devices discovered on this cable.

Return type:

QueryList[Device]

property filter_by: Dict[str, Any]

Specifies the dict used for filtering cables in the session.

Filters the QueryList returned by Session.cables. Both the raw hw_server property names (Description, Serial) and lowercase aliases (description, serial) are accepted. name is always the cable’s human readable description, matching Cable.name.

Match values are compared by equality, not by regular expression, so pass the property’s native type.

Return type:

Dict[str, Any]

Returns:

dict[str, value]

get_option(key)[source]

Reads a cable option value from the hw_server.

Option values are read live from the hw_server on every call. They are not cached in the api layer. Supported keys are cable dependent. frequency (in Hz), frequency_list, skew and timing_class are common.

Cable options are hw_server state shared by every client, and they persist for the life of the hw_server process. Restore anything you change.

Examples:

cable = session.cables.get(Serial="252502174339A")
original = cable.get_option("frequency")
try:
    cable.set_option("frequency", 3_000_000)
    ...
finally:
    cable.set_option("frequency", original)
Parameters:

key (str) – Name of the option, for example "frequency".

Return type:

Any

Returns:

The current option value.

Raises:
  • NotImplementedError – If this cable type does not support options.

  • Exception – If the hw_server rejects the request.

abstract property is_valid: bool

Returns True if the underlying cable node is still valid.

Return type:

bool

abstract property name: str

Returns the human readable description of this cable.

Return type:

str

set_option(key, value)[source]

Sets a cable option in the hw_server and returns the value actually applied.

The hw_server is free to apply a value different from the one requested. JTAG TCK frequency in particular is quantized to what the cable hardware can generate. On the FT4232H cables this was verified against, an out-of-range value was snapped down to an achievable one rather than rejected, but that is cable-dependent and another cable may reject the request instead. This method sets the option, reads it back, and returns the read-back value. It does not raise when the applied value differs from the requested value, so the caller must compare.

The returned value is a best-effort read-back. The set and the read are two independent unlocked requests, so another client may have intervened.

A frequency of 0 is reserved. On some cables it requests auto-negotiation rather than setting a rate, and on others it does nothing. Read the value back.

Parameters:
  • key (str) – Name of the option, for example "frequency".

  • value (Any) – New value for the option. Only int values are supported today.

Return type:

Any

Returns:

The option value as read back from the hw_server after the set.

Raises:
  • NotImplementedError – If this cable type does not support options.

  • TypeError – If value is not an int.

  • Exception – If the hw_server rejects the set or the read back.

abstract to_dict()[source]

Returns a dict of this cable’s properties.

Return type:

Dict

abstract to_json()[source]

Returns a JSON string representation of this cable’s properties.

Return type:

str

JTAG sequences

JTAG TAP shift-sequence builder, providing JtagState and JtagSequence. For cable-level operations such as the TCK clock frequency, see chipscopy.api.cable.

class chipscopy.api.jtag.JtagPadding(size, value)
size

Alias for field number 0

value

Alias for field number 1

class chipscopy.api.jtag.JtagSequence(jtag_node)[source]

Builder that accumulates TCF JTAG sequence commands and a data payload.

Commands and data are queued locally and then executed together in a single round trip to the JTAG node via run().

clear()[source]

Remove all commands from JTAG sequence

Parameters:

None –

dr_shift(*, data=None, tdi=None, size, capture=True, end_state=JtagState.RESET)[source]

Add JTAG sequence command to shift data in DR SHIFT state

Parameters:
  • data – Integer or bytearray data to shift

  • tdi (int) – TDI value to use for all clocks in shift state

  • size – Size of data to be shifted in bits

  • capture (bool) – Capture TDO data during shift and return from sequence run command

  • end_state (JtagState) – JTAG state to enter after shift is complete. The default is RESET.

ir_shift(*, data=None, tdi=None, size, capture=True, end_state=JtagState.RESET)[source]

Add JTAG sequence command to shift data in IR SHIFT state

Parameters:
  • data – Integer or bytearray data to shift

  • tdi (int) – TDI value to use for all clocks in shift state

  • size – Size of data to be shifted in bits

  • capture (bool) – Capture TDO data during shift and return from sequence run command

  • end_state (JtagState) – JTAG state to enter after shift is complete. The default is RESET.

run()[source]

Run JTAG operations in sequence for target JTAG node. This method will return the result from IR/DR shift commands for which capture is true.

Parameters:

None –

TODO: Option to mask and compare data returned after running sequence

Return type:

List[bytearray]

set_state(state, count=0)[source]

Add JTAG sequence command to move JTAG state machine to a new state and then generate certain number of JTAG clocks

Parameters:
  • state (JtagState) – Move JTAG state machine to this state

  • count (int) – Number of JTAG clocks to generate after moving to specified JTAG state

shift(*, shift_type='dr', data=None, tdi=None, size, capture=True, end_state=JtagState.RESET)[source]

Add JTAG sequence command to shift data in IR/DR SHIFT state

Parameters:
  • shift_type (str) – JTAG state in which data to shift. Valid options: “dr” or “ir”

  • data (int) – Integer or bytearray data to shift

  • tdi (int) – TDI value to use for all clocks in shift state

  • size – Size of data to be shifted in bits

  • capture (bool) – Capture TDO data during shift and return from sequence run command

  • end_state (JtagState) – JTAG state to enter after shift is complete. The default is RESET.

TODO: Mask and compare options

class chipscopy.api.jtag.JtagState(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]