在DFU模式下烧录

This commit is contained in:
你是我的梦想 2022-08-01 17:32:13 +08:00
parent f6da0b85d0
commit 2db3ef0590
3 changed files with 66 additions and 11 deletions

View File

@ -5,11 +5,12 @@ block_cipher = None
binaries = [
('C:\\Windows\\System32\\libusb0.dll', '.'),
('C:\\Windows\\System32\\libusbK.dll', '.'),
('C:\\Windows\\System32\\libusb-1.0.dll', '.'),
('C:\\Windows\\System32\\libusbK.dll', '.'),
('C:\\Windows\\System32\\winusb.dll', '.'),
('C:\\Windows\\System32\\winusb.sys', '.'),
('C:\\Windows\\System32\\WinUSBCoInstaller2.dll', '.'),
('C:\\Windows\\System32\\drivers\\libusbK.sys', '.'),
('C:\\Windows\\System32\\drivers\\usbser.sys', '.')
]
a = Analysis(['src\\firmwareInstaller.py'],
pathex=['D:\\Work\\Project\\FirmwareInstaller'],

View File

@ -3,9 +3,11 @@ Created on 2017年8月15日
@author: CreatBot-SW
"""
#!/usr/bin/env python3
# !/usr/bin/env python3
# coding: utf-8
# !/usr/bin/env python3
# coding: utf-8
import json
import os
import sys
@ -22,7 +24,8 @@ from avr_isp.intelHex import formatError
from avr_isp.ispBase import IspError
from avr_isp.stk500v2 import stk500v2Thread, portError
from pydfu import DFUTool as DFUse
from datetime import datetime
import pydfu
if getattr(sys, 'frozen', False):
bundle_dir = sys._MEIPASS
else:
@ -67,7 +70,7 @@ class mainWindow(QWidget):
self.setWindowIcon(QIcon(os.path.join(bundle_dir, "ico.ico")))
self.setFixedSize(QSize(480, 240))
self.setAcceptDrops(True)
"""寻找串口设备"""
self.portUpdateTimer = QTimer()
self.portUpdateTimer.timeout.connect(self.portUpdate)
self.portUpdateTimer.start(100)
@ -241,6 +244,7 @@ class mainWindow(QWidget):
""" Auto 监听端口 """
if self.autoRadio.isChecked():
self.baudCombo.setCurrentText("115200")
# self.portCombo.addItems(portList())
self.portCombo.clear()
@ -251,9 +255,27 @@ class mainWindow(QWidget):
continue
self.portCombo.addItem(port.portName() + " (" + port.description() + ")", (port.portName(), portInfo.vendorIdentifier()))
# kwargs = {"idVendor": 0x0483, "idProduct": 0xdf11}
# # dful = pydfu.get_dfu_devices(**kwargs)
# # print(dful)
# for dfu in pydfu.get_dfu_devices(**kwargs):
# pass
# dfu.set_configuration()
# print(dfu)
# for dev in dfu:
# print("-------------------------------------------------------------------------")
# print(dev)
# cfg = dfu.get_active_configuration()
# print(cfg)
# print(cfg[(0, 0)])
else:
currentPortData = self.portCombo.currentData()
if forceUpdate or (currentPortData and currentPortData[0] not in [port.portName() for port in QSerialPortInfo.availablePorts()]):
if forceUpdate or (
currentPortData and currentPortData[0] not in [port.portName() for port in QSerialPortInfo.availablePorts()]):
currentPortText = self.portCombo.currentText()
self.portCombo.clear()
for port in QSerialPortInfo.availablePorts():
@ -261,6 +283,8 @@ class mainWindow(QWidget):
self.portCombo.addItem(port.portName() + " (" + port.description() + ")",
(port.portName(), portInfo.vendorIdentifier()))
self.portCombo.setCurrentIndex(self.portCombo.findText(currentPortText))
kwargs = {"idVendor": 0x0483, "idProduct": 0xdf11}
dful = pydfu.get_dfu_devices(**kwargs)
self.portCombo.setSizeAdjustPolicy(QComboBox.AdjustToContents)
self.baudCombo.setSizeAdjustPolicy(QComboBox.AdjustToContents)
@ -307,14 +331,42 @@ class mainWindow(QWidget):
if hexFileDialog.exec():
self.file.setText(hexFileDialog.selectedFiles()[0])
def installFile(self, notFromButton=True):
# if self.portCombo.currentData() is None:
# return
def installDFU(self, notFromButton=True):
self.statusBar.showMessage("Serial to dfu...")
self.task = DFUse(self, None, int(self.baudCombo.currentText()), self.file.text(),
self.progressUpdate)
self.task.stateCallback[str].connect(self.stateUpdate)
self.task.stateCallback[Exception].connect(self.stateUpdate)
self.task.finished.connect(self.autoAction) # 检查是否自动烧写,并启动。
def installFile(self, notFromButton=True):
print("installFile")
if self.file.text() == "":
if not notFromButton:
self.selectFile()
self.installFile(True)
return
kwargs = {"idVendor": 0x0483, "idProduct": 0xdf11}
if len(pydfu.get_dfu_devices(**kwargs)) > 0:
print("DEF")
self.statusBar.showMessage("dfu...")
self.task = DFUse(self, None, int(self.baudCombo.currentText()), self.file.text(),
self.progressUpdate)
self.task.stateCallback[str].connect(self.stateUpdate)
self.task.stateCallback[Exception].connect(self.stateUpdate)
self.task.finished.connect(self.autoAction) # 检查是否自动烧写,并启动。
# 更新UI
self.portBox.setDisabled(True)
self.fileBox.setDisabled(True)
self.installBtn.setDisabled(True)
self.progress.show()
self.resize()
else:
info = self.portCombo.currentData()
@ -455,6 +507,7 @@ class mainWindow(QWidget):
def progressUpdate(self, cur, total):
""" 进度条 """
print(total, cur)
self.progress.setMaximum(total)
self.progress.setValue(cur)
@ -520,6 +573,6 @@ if __name__ == '__main__':
if len(sys.argv) > 1: # 关联hex文件自动安装
win.portUpdate()
win.file.setText(sys.argv[1])
# win.installBtn.click()
win.installBtn.click()
sys.exit(app.exec())

View File

@ -1026,6 +1026,7 @@ class DFUTool(QThread):
else:
self.stateCallback[str].emit(self.tr("Programming..."))
# write_memory(134217728, dfu_file, progress=self.cl_progress, progress_addr=134217728, progress_size=len(dfu_file))
write_elements([elem], False, progress=self.cl_progress)
exit_dfu() # 退出DFU模式