diff -r 316be9cd43bc -r 5f044e09aba5 src/eric7/MicroPython/UF2FlashDialog.py --- a/src/eric7/MicroPython/UF2FlashDialog.py Thu Nov 21 17:12:21 2024 +0100 +++ b/src/eric7/MicroPython/UF2FlashDialog.py Tue Nov 26 16:56:34 2024 +0100 @@ -24,6 +24,9 @@ from . import Devices from .Ui_UF2FlashDialog import Ui_UF2FlashDialog +with contextlib.suppress(ImportError): + import usb.core + SupportedUF2Boards = { "circuitpython": { "volumes": { @@ -797,8 +800,9 @@ foundDevices = set() # step 1: determine all known UF2 volumes that are mounted - if not OSUtilities.isWindowsPlatform(): - userMounts = FileSystemUtilities.getUserMounts() + userMounts = ( + [] if OSUtilities.isWindowsPlatform() else FileSystemUtilities.getUserMounts() + ) boardTypes = [boardType] if boardType else list(SupportedUF2Boards) for board in boardTypes: @@ -813,6 +817,14 @@ if os.path.basename(userMount).startswith(volume): foundDevices.add((board, description, vidpid)) break + if len(foundDevices) > 1: + # There are potentially different devices with same mount path/volume. + # Check the USB bus for the VID/PID of found devices and remove all + # those not found on the bus. + with contextlib.suppress(NameError, IOError): + for board, description, vidpid in foundDevices.copy(): + if not usb.core.find(idVendor=vidpid[0], idProduct=vidpid[1]): + foundDevices.discard((board, description, vidpid)) # step 2: determine all devices that have their UF2 volume not mounted availablePorts = QSerialPortInfo.availablePorts()