Abrufen des Status eines STM32-Geräts im DFU-ModusPython

Python-Programme
Guest
 Abrufen des Status eines STM32-Geräts im DFU-Modus

Post by Guest »

Ich habe einen einfachen Code geschrieben, um den Status eines verbundenen STM32-Geräts im DFU-Modus abzurufen. Ich kann die Informationen zum Gerät abrufen, erhalte jedoch immer eine Fehlermeldung, wenn ich den Status mit der Methode get_status überprüfe.
Unten ist mein Code.

Code: Select all

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]

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post