diff --git a/trunner/target/armv7a9.py b/trunner/target/armv7a9.py index 9e4d44b51..97d41ab77 100644 --- a/trunner/target/armv7a9.py +++ b/trunner/target/armv7a9.py @@ -54,7 +54,7 @@ def __call__(self): """Loads plo image to RAM using gdb.""" # after reboot we need to wait for smt2 device - wait_for_vid_pid(vid=0x0403, pid=0x6014, timeout=5) + wait_for_vid_pid(vid=0x0403, pid=0x6014, timeout=5, device="smt2") with self.gdbserver.run(): try: diff --git a/trunner/tools/phoenix.py b/trunner/tools/phoenix.py index d09de1679..3c605c996 100644 --- a/trunner/tools/phoenix.py +++ b/trunner/tools/phoenix.py @@ -6,31 +6,31 @@ import pexpect from trunner.harness import ProcessError +from trunner.dut import PortNotFound from serial.tools import list_ports from contextlib import contextmanager from .common import add_output_to_exception -def wait_for_vid_pid(vid: int, pid: int, timeout=0): +def wait_for_vid_pid(vid: int, pid: int, timeout: int = 0, device: str = ""): """wait for connected usb serial device with required vendor & product id""" - asleep = 0 found_ports = [] while not found_ports: - time.sleep(0.01) - asleep += 0.01 - found_ports = [port for port in list_ports.comports() if port.pid == pid and port.vid == vid] if len(found_ports) > 1: - raise Exception( - "More than one plo port was found! Maybe more than one device is connected? Hint used to find port:" - f"{vid:04x}:{pid:04x}" + raise PortNotFound( + f"More than one {device} port was found! Maybe more than one device is connected?" + f"Hint used to find port: {vid:04x}:{pid:04x}" ) if timeout and asleep >= timeout: - raise TimeoutError(f"Couldn't find plo USB device with vid/pid: '{vid:04x}:{pid:04x}'") + raise PortNotFound(f"Couldn't find {device} device! Hint used to find port:" f"{vid:04x}:{pid:04x}") + + time.sleep(0.01) + asleep += 0.01 return found_ports[0].device @@ -115,7 +115,7 @@ def _reader(self): def _run(self): try: - self.port = wait_for_vid_pid(self.vid, self.pid, timeout=10) + self.port = wait_for_vid_pid(self.vid, self.pid, timeout=10, device="PLO") except (TimeoutError, Exception) as exc: raise PhoenixdError(str(exc)) from exc