nxp-mcuxpresso/spsdk

mboot get_interface() raises exception if more than one device is found

Closed this issue · 1 comments

In some windows machines for some reason we see more than one connection when working with RT500 chip family in ISP mode over usb.
print(MBootInterfaceModule.scan_usb("0x1FC9:0x0023")) [<spsdk.mboot.interfaces.usb.RawHid object at 0x00000243034632E0>, <spsdk.mboot.interfaces.usb.RawHid object at 0x0000024303463580>]
the example above shows 2 instances of USB HID class (for some reason).
there is an exception raised by spsdk/apps/utils.py:
Traceback (most recent call last):
File "<pyshell#3>", line 1, in
i = get_interface(module='mboot', port=None, usb="0x1FC9,0x0023", timeout=5000)
File "C:<>\Programs\Python\Python39\lib\site-packages\spsdk\apps\utils.py", line 108, in get_interface
raise SPSDKError(f"More than one device '{format_vid_pid(vid_pid)}' found")
spsdk.exceptions.SPSDKError: SPSDK: More than one device '0x1fc9:0x0023' found

the code raising exception looks like:
if usb: vid_pid = usb.replace(',', ':') devices = interface_module.scan_usb(vid_pid) # type: ignore if len(devices) == 0: raise SPSDKError(f"Cannot find USB device '{format_vid_pid(vid_pid)}'") if len(devices) > 1: raise SPSDKError(f"More than one device '{format_vid_pid(vid_pid)}' found") devices[0].timeout = timeout return devices[0]

Would it be possible instead of raising an exception to caller to return the first member of devices[0]?

Hello Ivan,
after some investigation we decided to NOT updated the code to get the first device from list. :-( Is better to notify user and he can use on that "affected" Windows machine tool nxpdevscan to get USB_PATH and use this UCB_PATH instead of PID/VID.

This decision is based on security constrains to be sure what device is really connected to tool.

Thank you for understanding.

Petr