viveris / jtag-boundary-scanner

JTAG boundary scan debug & test tool.
GNU General Public License v3.0
124 stars 37 forks source link

Python3 interface for library #4

Open colinoflynn opened 3 years ago

colinoflynn commented 3 years ago

Short comment first - thanks so much for this library, I spent a while playing with various JTAG boundary scan options and it's frustrating how hard it is to toggle some IO pins for testing with other tools. I came close to buying some of the very expensive tools even but they wouldn't provide enough up-front information.

I'm adding a Python interface to this library, so far it seems to work OK (tested on Windows 10 w/ JLINK). See https://github.com/colinoflynn/jtag-boundary-scanner/tree/python-interface/pylibjtag

You use it something like this:

jtag = JTAGCore()
probes = jtag.get_probe_names()
jtag.open_probe(probes[b"USB JLINK ARM"])
jtag.scan_init_chain()
numdev = jtag.get_number_devices()

print("Found %d devices."%numdev)

for n in range(0, numdev):
    print("Device %d: %x"%(n, jtag.get_devid(n)))

jtag.bsdl_attach(r"bsdl_files/STM32F405_415_407_417_WLCSP90.bsd", 1)

total_pins = jtag.pins_get_number(1)

for pinid in range(0, total_pins):
    pinname, pinprop = jtag.pin_get_properties(1, pinid)
    print("{:3d} {} {}".format(pinid, pinname, pinprop))

jtag.set_scan_mode(1, "passive")

jtag.scan() #Get updated pin status
print(jtag.pin_get_state(1, "PA9")) #Print status of a pin

jtag.set_scan_mode(1, "active")

jtag.pin_set_state(1, "PA11", True) #set pin high (active out)
jtag.pin_set_state(1, "PA11", False) #Set pin low (active out)
jtag.pin_set_state(1, "PA11", None) #Set pin to high-z

I've included my library build in that repo to make it easier for other people to use. I had a few issues I ran into - I can open separate issues for them or just paste as comments here, roughly around:

Finally - do you want to have the Python interface as part of the repo (i.e. - I can open a PR once it's cleaner)? If you're not using Python you might be hesitant too for future support. I can start it as a separate project if you prefer, but it makes more sense to have it here to me (especially to keep any changes in the library & Python API in sync).

colinoflynn commented 3 years ago

I'm going to be reorganizing the python module - I decided in the end it might be easier keeping the python side in a separate project (which could work with other backends later). Could still easily add the "core" part to this project - I'm open. For now I'll keep all my Python stuff separate to avoid problems!

nowinnovation commented 2 years ago

I read your article on Circuit Cellar and share your interest in this codebase as an extensible library of JTAG boundary scan algorithms. Take a look at my pull request. Does this offer a simpler way to build your Python3 interface?