# Buggy code
def open(self):
    self._device.open()
    self.get_version()
    self.get_target_voltage()


# Traceback (usb.core.USBError)
/usr/bin/python3.6 /home/user/project/pyOCD/test/basic_test.py
WARNING:session:Error attempting to access config file 'test_boards.yaml': [Errno 2] No such file or directory: 'test_boards.yaml'
INFO:board:Target type is cortex_m
DEBUG:stlink.usb:  USB CMD> f1 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
DEBUG:stlink.usb:  USB IN < (6 bytes)
DEBUG:stlink.usb:  USB IN < 27 07 83 04 48 37
DEBUG:stlink.usb:  USB CMD> f7 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
DEBUG:stlink.usb:  USB IN < (8 bytes)
Traceback (most recent call last):
File "/home/user/project/pyOCD/pyocd/probe/stlink/usb.py", line 206, in transfer
data = self._read(readSize)
File "/home/user/project/pyOCD/pyocd/probe/stlink/usb.py", line 179, in _read
data = self._ep_in.read(read_size, timeout)
File "/home/user/.local/lib/python3.6/site-packages/usb/core.py", line 402, in read
return self.device.read(self, size_or_buffer, timeout)
File "/home/user/.local/lib/python3.6/site-packages/usb/core.py", line 988, in read
self.__get_timeout(timeout))
File "/home/user/.local/lib/python3.6/site-packages/usb/backend/libusb1.py", line 833, in bulk_read
timeout)
File "/home/user/.local/lib/python3.6/site-packages/usb/backend/libusb1.py", line 936, in __read
_check(retval)
File "/home/user/.local/lib/python3.6/site-packages/usb/backend/libusb1.py", line 595, in _check
raise USBError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBError: [Errno 32] Pipe error

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/home/user/project/pyOCD/pyocd/probe/stlink_probe.py", line 86, in open
self._link.open()
File "/home/user/project/pyOCD/pyocd/probe/stlink/stlink.py", line 67, in open
self.get_target_voltage()
File "/home/user/project/pyOCD/pyocd/probe/stlink/stlink.py", line 141, in get_target_voltage
response = self._device.transfer([Commands.GET_TARGET_VOLTAGE], readSize=8)
File "/home/user/project/pyOCD/pyocd/probe/stlink/usb.py", line 211, in transfer
six.raise_from(STLinkException("USB Error: %s" % exc), exc)
File "<string>", line 3, in raise_from
pyocd.probe.stlink.STLinkException: USB Error: [Errno 32] Pipe error

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/home/user/project/pyOCD/test/basic_test.py", line 238, in <module>
basic_test(None, file)
File "/home/user/project/pyOCD/test/basic_test.py", line 47, in basic_test
with ConnectHelper.session_with_chosen_probe(unique_id=board_id, **get_session_options()) as session:
File "/home/user/project/pyOCD/pyocd/core/helpers.py", line 199, in session_with_chosen_probe
session.open()
File "/home/user/project/pyOCD/pyocd/core/session.py", line 155, in open
self._probe.open()
File "/home/user/project/pyOCD/pyocd/probe/stlink_probe.py", line 89, in open
six.raise_from(self._convert_exception(exc), exc)
File "<string>", line 3, in raise_from
pyocd.core.exceptions.ProbeError: USB Error: [Errno 32] Pipe error

Process finished with exit code 1

# Fixed code
def open(self):
    self._device.open()
    self.enter_idle()
    self.get_version()
    self.get_target_voltage()