colinoflynn / pyjtagbs

Python JTAG Boundary Scan tool
GNU Lesser General Public License v2.1
73 stars 14 forks source link

How to close JTAG reference properly #2

Open boortel opened 3 years ago

boortel commented 3 years ago

Hello again,

I continue with the experiments and I'm not able to find, how to close the JTAG reference properly. This cause troubles in finding probes, when I restart the processor, or when I try to run the script again.

The dummy code, which leads to error by its re-running, is following:

from jtagbs import JTAGCore, JTAGBS
import time

# Initialize
interface = JTAGCore()
jtag = JTAGBS(interface)

# Get list of probes
probes = jtag.list_available_probes()
probesVal = ([(k) for k in probes])

print("Probes values are:")
print(probesVal)

# Open the selected probe and get Device ID
jtag.open_probe(probesVal[0])
jtag.init_scanchain()

print("Device ID:")
print(jtag.list_devids())
print("Device information:")
print(jtag.list_devices())

# Load the BSD file - better use the absolute path - relative does not work time to time
stm32 = jtag.get_device(0)
stm32.set_bsdl(r'BSDL/TMS320F2803X_TQFP.bsdl')
#stm32.set_bsdl(os.path.join(dirname, 'BSDL/TMS320F2803X_TQFP.bsdl'))

print(stm32.list_pins())

stm32.set_scan_mode("active")

stm32.set_pin_state("GPIO34", True)
print(stm32.get_pin_state("GPIO34"))

The following error occurs when running the script again:

Probes values are:
[]
Traceback (most recent call last):

  File "C:\Users\user\JTAGBS_FirstTry.py", line 25, in <module>
    jtag.open_probe(probesVal[0])

IndexError: list index out of range

Everything works properly while the first run and I can fix the re-run problem with the kernel restart. However, I need to re-run my script and BS for several times and the restart solution is not suitable for me. It would be nice to close everything and then to initialize the references again. Could you please help me with this issue?

Thanks in advance!

Sims

colinoflynn commented 3 years ago

What probe are you using & OS? I'll try here - to be honest I've just been rerunning it without noticing a problem. The underlying library doesn't have a "close" function which suggests we don't either.

You might be able to delete the object (at least the ctypes interface) which could close it?

boortel commented 3 years ago

I use the Texas Instruments XDS100+RS232 V1.0 A TI16QHTYA probe and Win10 OS.

The problem occurs only, when I rerun the initialization part - the next run returns only empty probes. Removing the interface and jtag variables doesn't help - I always have to restart the whole kernel.

Oremuss commented 1 year ago

I have same problem and its also with XDS100. @boortel did you find solution or you just made workaround with resetting kernel?