diff --git a/pylink/jlink.py b/pylink/jlink.py index 6df2bc5..cb395e4 100644 --- a/pylink/jlink.py +++ b/pylink/jlink.py @@ -5191,3 +5191,39 @@ def cp15_register_write(self, cr_n, op_1, cr_m, op_2, value): if res != 0: raise errors.JLinkException(res) return res + +############################################################################### +# +# JTAG API (Raw JTAG access for boundary scan or other purposes) +# +############################################################################### + + @interface_required(enums.JLinkInterfaces.JTAG) + def jtag_raw_rw(self, tdo, tms, numbits=None): + """Writes a list of raw bits to TDO+TMS, returns TDI input. + + Args: + self (JLink): the ``JLink`` instance + tdo (List): List of bytes to be shifted out tdo. + tms (List): list of bytes to be shifted out tms. + numbits (Int): Number of bits to shift out in total. + + Returns: + tdi (List): Output from device shifted into tdi. + """ + + if len(tdo) != len(tms): + raise ValueError("TMS & TDO arrays must be same length") + + buf_size = len(tdo) + + if numbits is None: + numbits = len(tdo) * 8 + + tdobuf = (ctypes.c_ubyte * buf_size)(*bytearray(tdo)) + tmsbuf = (ctypes.c_ubyte * buf_size)(*bytearray(tms)) + tdibuf = (ctypes.c_ubyte * buf_size)() + + self._dll.JLINKARM_JTAG_StoreGetRaw(tdobuf, tdibuf, tmsbuf, numbits) + + return list(tdibuf)