MicroPython eric7

Tue, 26 Nov 2024 16:56:34 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 26 Nov 2024 16:56:34 +0100
branch
eric7
changeset 11053
5f044e09aba5
parent 11052
316be9cd43bc
child 11054
38ffc8fbc782

MicroPython
- Improved the device detection of the UF2 Flash dialog to suppress devices not seen on the USB bus (happens when devices have identical BOOT volume names).

docs/changelog.md file | annotate | diff | comparison | revisions
pyproject.toml file | annotate | diff | comparison | revisions
scripts/install-dependencies.py file | annotate | diff | comparison | revisions
scripts/install.py file | annotate | diff | comparison | revisions
src/eric7/MicroPython/UF2FlashDialog.py file | annotate | diff | comparison | revisions
--- a/docs/changelog.md	Thu Nov 21 17:12:21 2024 +0100
+++ b/docs/changelog.md	Tue Nov 26 16:56:34 2024 +0100
@@ -14,6 +14,8 @@
     - Added support for ESP-C2, ESP32-C6, ESP32-H2, ESP32-P4 and ESP8684.
     - Extended the list of known VID/PID of ESP32 devices.
     - Added an entry to the ESP32 menu to show some device security information.
+    - Improved the device detection of the UF2 Flash dialog to suppress devices not
+      seen on the USB bus (happens when devices have identical BOOT volume names).
 - Project Type 'Eric7 Plugin'
     - Added code to ensure, that compiled form files get recreated before
       they are written to the plugin archive.
--- a/pyproject.toml	Thu Nov 21 17:12:21 2024 +0100
+++ b/pyproject.toml	Tue Nov 26 16:56:34 2024 +0100
@@ -89,6 +89,7 @@
     "psutil",
     "fido2",
     "requests",
+    "pyusb>= 1.2.0",
     "pywin32>=1.0;platform_system=='Windows'",
     "command-runner;platform_system=='Windows'",
 ]
--- a/scripts/install-dependencies.py	Thu Nov 21 17:12:21 2024 +0100
+++ b/scripts/install-dependencies.py	Tue Nov 26 16:56:34 2024 +0100
@@ -96,6 +96,7 @@
         "wheel",
         "esprima",
         "fido2",
+        "pyusb>=1.2.0",
     )
     optionalWindowsPackages = (
         "pywin32>=1.0",
--- a/scripts/install.py	Thu Nov 21 17:12:21 2024 +0100
+++ b/scripts/install.py	Tue Nov 26 16:56:34 2024 +0100
@@ -1735,6 +1735,7 @@
         "wheel": ("wheel", ""),
         "esprima": ("esprima", ""),
         "fido2": ("fido2", ""),
+        "pyusb": ("usb", ">=1.2.0"),
     }
     if withPyqt6Tools:
         optionalModulesList["qt6-applications"] = ("qt6_applications", "")
--- 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()

eric ide

mercurial