pyocd / pyocd/pyOCD

0.36.0 gdbserver generates "USB Error: [Errno 10060] Operation timed out"

Open
#1,653 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
1.5k
Forks
560
Avg merge
1h 41m
Merged PRs (30d)
3

Description

Hello,

I am using pyocd to host a GDB server and encountering an issue where the GDB server fails to open a debug session after flashing a firmware.

Here's the sequence of steps:

  1. I start the GDB server with the command:
    pyocd gdbserver -r --allow-remote --persist -S --verbose
    The server initialization seems to work fine.

  2. Connecting with a GDB client at this point works as expected.

  3. However, if I flash a Zephyr firmware before debugging using the command:
    west flash -r pyocd --dev-id remote:<ip-addr>:5555
    The output indicates successful flashing:

0006995 I Semihost server started on port 4444 (core 0) [server]
0007585 I GDB server started on port 3333 (core 0) [gdbserver]
0022919 I Client kubernetes.docker.internal (port 54076) connected to probe 001F002D3137510939383538 [tcp_probe_server]
0022922 D actual SWD frequency is 1000 kHz [stlink]
0022961 D creating memif for AP#0 (handle 0) [tcp_probe_server]
0022968 D creating memif for AP#1 (handle 1) [tcp_probe_server]
0022975 D creating memif for AP#2 (handle 2) [tcp_probe_server]
0024283 D empty request, closing connection [tcp_probe_server]
0024283 I Client kubernetes.docker.internal (port 54076) disconnected from probe 001F002D3137510939383538 [tcp_probe_server]
  1. When attempting to connect a debug session after flashing, I receive the following error message, indicating a timeout issue:
0165915 D Starting GDB server packet I/O thread [packet_io]
0165915 D halting core 0 [cortex_m]
0166921 E Unexpected exception: USB Error: [Errno 10060] Operation timed out [gdbserver]
Traceback (most recent call last):
  File "C:\Users\XXX\AppData\Local\Programs\Python\Python312\Lib\site-packages\pyocd\probe\stlink\usb.py", line 249, in transfer
    count = self._ep_out.write(writeData, timeout)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\XXX\AppData\Local\Programs\Python\Python312\Lib\site-packages\usb\core.py", line 408, in write
    return self.device.write(self, data, timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\XXX\AppData\Local\Programs\Python\Python312\Lib\site-packages\usb\core.py", line 989, in write
    return fn(
           ^^^
  File "C:\Users\XXX\AppData\Local\Programs\Python\Python312\Lib\site-packages\usb\backend\libusb1.py", line 837, in bulk_write
    return self.__write(self.lib.libusb_bulk_transfer,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\XXX\AppData\Local\Programs\Python\Python312\Lib\site-packages\usb\backend\libusb1.py", line 938, in __write
    _check(retval)
  File "C:\Users\XXX\AppData\Local\Programs\Python\Python312\Lib\site-packages\usb\backend\libusb1.py", line 602, in _check
    raise USBTimeoutError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBTimeoutError: [Errno 10060] Operation timed out

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

Traceback (most recent call last):
  File "C:\Users\XXX\AppData\Local\Programs\Python\Python312\Lib\site-packages\pyocd\gdbserver\gdbserver.py", line 336, in run
    self.target.halt()
  File "C:\Users\XXX\AppData\Local\Programs\Python\Python312\Lib\site-packages\pyocd\coresight\cortex_m.py", line 638, in halt
    self.write_memory(CortexM.DHCSR, CortexM.DBGKEY | CortexM.C_DEBUGEN | CortexM.C_HALT)
  File "C:\Users\XXX\AppData\Local\Programs\Python\Python312\Lib\site-packages\pyocd\coresight\cortex_m.py", line 579, in write_memory
    self.ap.write_memory(addr, data, transfer_size)
  File "C:\Users\XXX\AppData\Local\Programs\Python\Python312\Lib\site-packages\pyocd\utility\concurrency.py", line 29, in _locking
    return func(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\XXX\AppData\Local\Programs\Python\Python312\Lib\site-packages\pyocd\coresight\ap.py", line 1227, in _accelerated_write_memory
    self._accelerated_memory_interface.write_memory(addr, data, transfer_size,
  File "C:\Users\XXX\AppData\Local\Programs\Python\Python312\Lib\site-packages\pyocd\probe\stlink_probe.py", line 292, in write_memory
    self._link.write_mem32(addr, conversion.u32le_list_to_byte_list([data]), self._apsel, csw)
  File "C:\Users\XXX\AppData\Local\Programs\Python\Python312\Lib\site-packages\pyocd\probe\stlink\stlink.py", line 477, in write_mem32
    self._write_mem(addr, data, Commands.JTAG_WRITEMEM_32BIT, self.MAXIMUM_TRANSFER_SIZE, apsel, csw)
  File "C:\Users\XXX\AppData\Local\Programs\Python\Python312\Lib\site-packages\pyocd\probe\stlink\stlink.py", line 446, in _write_mem
    self._device.transfer(cmd, writeData=thisTransferData)
  File "C:\Users\XXX\AppData\Local\Programs\Python\Python312\Lib\site-packages\pyocd\probe\stlink\usb.py", line 267, in transfer
    raise exceptions.ProbeError("USB Error: %s" % exc) from exc
pyocd.core.exceptions.ProbeError: USB Error: [Errno 10060] Operation timed out
Exception in thread gdb-packet-thread-port3333:
Traceback (most recent call last):
  File "C:\Users\XXX\AppData\Local\Programs\Python\Python312\Lib\threading.py", line 1052, in _bootstrap_inner
    self.run()
  File "C:\Users\XXX\AppData\Local\Programs\Python\Python312\Lib\site-packages\pyocd\gdbserver\packet_io.py", line 111, in run
    data = self._abstract_socket.read()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\XXX\AppData\Local\Programs\Python\Python312\Lib\site-packages\pyocd\utility\sockets.py", line 55, in read
    return self.conn.recv(packet_size)
           ^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'recv'

To reproduce the issue, you can perform a fresh install of the following software versions:

  • pyocd version 0.36.0
  • libusb.dll version 1.0.26 (copied to the Python folder)
  • STLINKV3 with Firmware version V3J13M4 (recommended by en.stsw-link007-v3-13-4)
  • Windows OS 64Bit

I appreciate your assistance in addressing this issue.

Best regards.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the reported sequence with pyocd 0.36.0, west flash, an STLINKV3, and Windows. Read pyocd/probe/stlink/usb.py around transfer(), then follow the gdbserver.py run() path and the related packet_io failure. Done means a debug session can start after flashing without the USB timeout or resulting connection exception.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools, embedded-iot
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.