diff options
author | Nick Sanders <nsanders@chromium.org> | 2018-07-02 18:44:50 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-07-06 18:48:32 -0700 |
commit | 7d26ae49bffcf269df82df7d0fee00e8c3341166 (patch) | |
tree | 31bc6a099279595fd0b3d90943a91233cbc85b38 /extra/tigertool/ecusb/stm32usb.py | |
parent | 66b400fa25992943f1278426b54f3109fb033407 (diff) | |
download | chrome-ec-7d26ae49bffcf269df82df7d0fee00e8c3341166.tar.gz |
ec-devutils: update pyusb to 1.0.2
Pyusb interface has changed yet again. Patch calls to get_string
and usb.core.find. Modify ordering of detetch kernel driver
and avoid rereferencing endpoints.
BRANCH=None
BUG=b:110907544
TEST=emerge ec-devutils, run powerlog, usb_console, servo_updater
CQ-DEPEND=CL:1119632
Signed-off-by: Nick Sanders <nsanders@chromium.org>
Change-Id: I33df474ce3bb57d2e11c9f384ac013b51d210843
Reviewed-on: https://chromium-review.googlesource.com/1125354
Commit-Ready: Nick Sanders <nsanders@chromium.org>
Tested-by: Nick Sanders <nsanders@chromium.org>
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
Diffstat (limited to 'extra/tigertool/ecusb/stm32usb.py')
-rw-r--r-- | extra/tigertool/ecusb/stm32usb.py | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/extra/tigertool/ecusb/stm32usb.py b/extra/tigertool/ecusb/stm32usb.py index b8ffb2765e..3d3627e8ab 100644 --- a/extra/tigertool/ecusb/stm32usb.py +++ b/extra/tigertool/ecusb/stm32usb.py @@ -57,8 +57,10 @@ class Susb(object): def _find_device(self): """Set up the usb endpoint""" # Find the stm32. - dev_list = usb.core.find(idVendor=self._vendor, idProduct=self._product, + dev_g = usb.core.find(idVendor=self._vendor, idProduct=self._product, find_all=True) + dev_list = list(dev_g) + if not dev_list: raise SusbError('USB device not found') @@ -66,7 +68,7 @@ class Susb(object): dev = None if self._serialname: for d in dev_list: - dev_serial = usb.util.get_string(d, 256, d.iSerialNumber) + dev_serial = usb.util.get_string(d, d.iSerialNumber) if dev_serial == self._serialname: dev = d break @@ -79,12 +81,20 @@ class Susb(object): raise SusbError('USB device %04x:%04x not found' % ( self._vendor, self._product)) + # Detach raiden.ko if it is loaded. CCD endpoints support either a kernel + # module driver that produces a ttyUSB, or direct endpoint access, but + # can't do both at the same time. + if dev.is_kernel_driver_active(self._interface) is True: + dev.detach_kernel_driver(self._interface) + # If we can't set configuration, it's already been set. try: dev.set_configuration() - except usb.core.USBError: + except usb.core.USBError as e: pass + self._dev = dev + # Get an endpoint instance. cfg = dev.get_active_configuration() intf = usb.util.find_descriptor(cfg, bInterfaceNumber=self._interface) @@ -93,12 +103,6 @@ class Susb(object): raise SusbError('Interface %04x:%04x - 0x%x not found' % ( self._vendor, self._product, self._interface)) - # Detach raiden.ko if it is loaded. CCD endpoints support either a kernel - # module driver that produces a ttyUSB, or direct endpoint access, but - # can't do both at the same time. - if dev.is_kernel_driver_active(intf.bInterfaceNumber) is True: - dev.detach_kernel_driver(intf.bInterfaceNumber) - read_ep_number = intf.bInterfaceNumber + self.READ_ENDPOINT read_ep = usb.util.find_descriptor(intf, bEndpointAddress=read_ep_number) self._read_ep = read_ep @@ -106,3 +110,6 @@ class Susb(object): write_ep_number = intf.bInterfaceNumber + self.WRITE_ENDPOINT write_ep = usb.util.find_descriptor(intf, bEndpointAddress=write_ep_number) self._write_ep = write_ep + + def close(self): + usb.util.dispose_resources(self._dev) |