Я написал простой код для получения статуса подключенного устройства stm32 в режиме dfu. Я могу получить информацию об устройстве, но всегда получаю ошибку при проверке статуса с помощью метода get_status.
Ниже приведен мой код.
import usb
import time
import usb.backend.libusb1
# DFU Commands
DFU_DETACH = 0x00
DFU_DNLOAD = 0x01
DFU_UPLOAD = 0x02
DFU_GETSTATUS = 0x03
DFU_CLRSTATUS = 0x04
DFU_GETSTATE = 0x05
DFU_ABORT = 0x06
class STDFU:
def __init__(self):
# Initialize the device (replace with your device's VendorID and ProductID)
self.device = usb.core.find(idVendor=0x0483, idProduct=0xDF11, backend=usb.backend.libusb1.get_backend(find_library=lambda x: "libusb-1.0.dll"))
if self.device is None:
raise ValueError("Device not found.")
# Set up the device (claim interface, reset device, etc.)
self.device.set_configuration()
self.device.reset()
time.sleep(2) # Ensure the device has time to reset
def get_device_info(self):
if self.device:
print(f"Device: {self.device}")
print(f"Device Configuration: {self.device.get_active_configuration()}")
# Removed the line that tried to access the 'state' attribute
print("Device state info is not available via pyusb.")
else:
print("No device found.")
def get_status(self):
try:
if self.device is None:
raise ValueError("Device not initialized.")
print("Sending DFU_GETSTATUS request to device...")
response = self.device.ctrl_transfer(0xA1, DFU_GETSTATUS, 0, 0, 6, timeout=20000)
print(f"Received response: {response}")
# Assuming response follows this format:
dfu_status = DFUStatus()
dfu_status.status = response[0]
dfu_status.poll_timeout = response[1] | (response[2]
Подробнее здесь: [url]https://stackoverflow.com/questions/79303164/getting-the-status-of-an-stm32-device-in-dfu-mode[/url]
Я написал простой код для получения статуса подключенного устройства stm32 в режиме dfu. Я могу получить информацию об устройстве, но всегда получаю ошибку при проверке статуса с помощью метода get_status. Ниже приведен мой код. [code]import usb import time import usb.backend.libusb1
class STDFU: def __init__(self): # Initialize the device (replace with your device's VendorID and ProductID) self.device = usb.core.find(idVendor=0x0483, idProduct=0xDF11, backend=usb.backend.libusb1.get_backend(find_library=lambda x: "libusb-1.0.dll"))
if self.device is None: raise ValueError("Device not found.")
# Set up the device (claim interface, reset device, etc.) self.device.set_configuration() self.device.reset() time.sleep(2) # Ensure the device has time to reset
def get_device_info(self):
if self.device: print(f"Device: {self.device}") print(f"Device Configuration: {self.device.get_active_configuration()}") # Removed the line that tried to access the 'state' attribute print("Device state info is not available via pyusb.") else: print("No device found.")
def get_status(self):
try: if self.device is None: raise ValueError("Device not initialized.")