@@ -13,21 +13,22 @@ def init_libusb_windows():
1313 """
1414 Initializes the libusb backend on Windows and caches it module-wide.
1515
16+ Uses libusb_package, which bundles pre-built libusb shared libraries and
17+ exposes a ready-to-use pyusb backend, removing the need to locate the DLL.
18+
1619 Returns:
1720 The usb backend object if successful, None otherwise.
1821 """
1922 global _libusb_backend
2023 if _libusb_backend is not None :
2124 return _libusb_backend
25+ try :
26+ import libusb_package # type: ignore
27+ except ImportError :
28+ log .error ("libusb_package not found, please install it with 'pip install libusb-package'" )
29+ return None
2230
23- import libusb # type: ignore
24- import usb .backend .libusb1 as libusb1
25-
26- arch = "x86_64" if platform .architecture ()[0 ] == "64bit" else "x86"
27- libusb1_dll = Path (libusb .__file__ ).parent / "_platform" / "windows" / arch / "libusb-1.0.dll"
28- if not libusb1_dll .exists ():
29- raise FileNotFoundError (f"libusb1.dll not found at { libusb1_dll } " )
30- _libusb_backend = libusb1 .get_backend (find_library = lambda x : libusb1_dll .as_posix ())
31+ _libusb_backend = libusb_package .get_libusb1_backend ()
3132 return _libusb_backend
3233
3334
@@ -95,11 +96,11 @@ def flash_stm32_dfu(
9596 try :
9697 pydfu .list_dfu_devices (** kwargs )
9798 except ValueError as e :
98- log .error (f"Insuffient permissions to access usb DFU devices: { e } " )
99+ log .error (f"Insufficient permissions to access usb DFU devices: { e } " )
99100 return None
100101
101102 # Needs to be a list of serial ports
102- log .debug ("Inititialize pydfu..." )
103+ log .debug ("Initialize pydfu..." )
103104 pydfu .init (** kwargs )
104105
105106 if erase :
0 commit comments