pyocd / pyOCD

Open source Python library for programming and debugging Arm Cortex-M microcontrollers
https://pyocd.io
Apache License 2.0
1.13k stars 484 forks source link

Uncatchable exception occurred when disconnecting SW physical interface during session.close() execution #1347

Open cyberxnomad opened 2 years ago

cyberxnomad commented 2 years ago
while 1:
    session = ConnectHelper.session_with_chosen_probe(
        unique_id=debuggers[probe_sel].unique_id,
        target_override="STM32f412xG",
        auto_open=False,
    )
    try:
        session.open()
        board = session.board
        target = board.target

        # do something

        start = time.perf_counter()
        session.close()
        end = time.perf_counter()
        print("close time: %s" % (end - start))

    except Exception as err:
        print(err)
        # do something else

    sleep(2)

If the SW physical interface is not connected, No ACK receive will be printed every two seconds. After connecting the SW interface, disconnecting the physical connection during session.close() will throw an uncaught exception. By the way, it takes 5 seconds to execute session.close() .

link exception during target disconnect: No ACK received
Traceback (most recent call last):
  File "G:\Program\Python3\lib\site-packages\pyocd\probe\cmsis_dap_probe.py", line 353, in read_dp_result_callback
    value = result()
  File "G:\Program\Python3\lib\site-packages\pyocd\probe\pydapaccess\dap_access_cmsis_dap.py", line 970, in read_reg_cb
    res = transfer.get_result()
  File "G:\Program\Python3\lib\site-packages\pyocd\probe\pydapaccess\dap_access_cmsis_dap.py", line 154, in get_result
    self.daplink.flush()
  File "G:\Program\Python3\lib\site-packages\pyocd\utility\concurrency.py", line 29, in _locking
    return func(self, *args, **kwargs)
  File "G:\Program\Python3\lib\site-packages\pyocd\probe\pydapaccess\dap_access_cmsis_dap.py", line 790, in flush
    self._read_packet()
  File "G:\Program\Python3\lib\site-packages\pyocd\utility\concurrency.py", line 29, in _locking
    return func(self, *args, **kwargs)
  File "G:\Program\Python3\lib\site-packages\pyocd\probe\pydapaccess\dap_access_cmsis_dap.py", line 1056, in _read_packet
    decoded_data = cmd.decode_data(raw_data)
  File "G:\Program\Python3\lib\site-packages\pyocd\probe\pydapaccess\dap_access_cmsis_dap.py", line 473, in decode_data
    data = self._decode_transfer_block_data(data)
  File "G:\Program\Python3\lib\site-packages\pyocd\probe\pydapaccess\dap_access_cmsis_dap.py", line 442, in _decode_transfer_block_data
    self._check_response(data[3])
  File "G:\Program\Python3\lib\site-packages\pyocd\probe\pydapaccess\dap_access_cmsis_dap.py", line 363, in _check_response
    raise DAPAccessIntf.TransferError("No ACK received")
pyocd.probe.pydapaccess.dap_access_api.DAPAccessIntf.TransferError: No ACK received

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

Traceback (most recent call last):
  File "G:\Program\Python3\lib\site-packages\pyocd\board\board.py", line 137, in uninit
    self.target.disconnect(resume)
  File "G:\Program\Python3\lib\site-packages\pyocd\coresight\coresight_target.py", line 123, in disconnect
    self.dp.disconnect()
  File "G:\Program\Python3\lib\site-packages\pyocd\coresight\dap.py", line 359, in disconnect
    self.power_down_debug()
  File "G:\Program\Python3\lib\site-packages\pyocd\coresight\dap.py", line 523, in power_down_debug
    r = self.read_reg(DP_CTRL_STAT)
  File "G:\Program\Python3\lib\site-packages\pyocd\coresight\dap.py", line 471, in read_reg
    return self.read_dp(addr, now)
  File "G:\Program\Python3\lib\site-packages\pyocd\coresight\dap.py", line 752, in read_dp
    return read_dp_cb()
  File "G:\Program\Python3\lib\site-packages\pyocd\coresight\dap.py", line 740, in read_dp_cb
    result = result_cb()
  File "G:\Program\Python3\lib\site-packages\pyocd\probe\cmsis_dap_probe.py", line 358, in read_dp_result_callback
    raise self._convert_exception(error) from error
pyocd.core.exceptions.TransferError: No ACK received
flit commented 2 years ago

Several questions for you:

Assuming you are connecting/disconnecting the SWD cable to some board (and not USB), then this is the expected behaviour. If there's nothing on the other end of the SWD interface, you'll of course get a "No ACK received" error. There's really nothing else we can do in that case!