mirror of
https://github.com/dragonpilot/dragonpilot.git
synced 2026-02-19 15:54:00 +08:00
openpilot v0.9.5 release
date: 2023-11-17T23:53:40
master commit: d3aad9ca46
This commit is contained in:
@@ -34,9 +34,16 @@ class STBootloaderUSBHandle(BaseSTBootloaderHandle):
|
||||
def __init__(self, libusb_device, libusb_handle):
|
||||
self._libusb_handle = libusb_handle
|
||||
|
||||
# TODO: Find a way to detect F4 vs F2
|
||||
# TODO: also check F4 BCD, don't assume in else
|
||||
self._mcu_type = McuType.H7 if libusb_device.getbcdDevice() == 512 else McuType.F4
|
||||
# example from F4: lsusb -v | grep Flash
|
||||
# iInterface 4 @Internal Flash /0x08000000/04*016Kg,01*064Kg,011*128Kg
|
||||
for i in range(20):
|
||||
desc = libusb_handle.getStringDescriptor(i, 0)
|
||||
if desc is not None and desc.startswith("@Internal Flash"):
|
||||
sector_count = sum([int(s.split('*')[0]) for s in desc.split('/')[-1].split(',')])
|
||||
break
|
||||
mcu_by_sector_count = {m.config.sector_count: m for m in McuType}
|
||||
assert sector_count in mcu_by_sector_count, f"Unkown MCU: {sector_count=}"
|
||||
self._mcu_type = mcu_by_sector_count[sector_count]
|
||||
|
||||
def _status(self) -> None:
|
||||
while 1:
|
||||
@@ -51,11 +58,8 @@ class STBootloaderUSBHandle(BaseSTBootloaderHandle):
|
||||
def get_mcu_type(self):
|
||||
return self._mcu_type
|
||||
|
||||
def erase_app(self):
|
||||
self._erase_page_address(self._mcu_type.config.app_address)
|
||||
|
||||
def erase_bootstub(self):
|
||||
self._erase_page_address(self._mcu_type.config.bootstub_address)
|
||||
def erase_sector(self, sector: int):
|
||||
self._erase_page_address(self._mcu_type.config.sector_address(sector))
|
||||
|
||||
def clear_status(self):
|
||||
# Clear status
|
||||
@@ -78,7 +82,7 @@ class STBootloaderUSBHandle(BaseSTBootloaderHandle):
|
||||
# Program
|
||||
bs = min(len(dat), self._mcu_type.config.block_size)
|
||||
dat += b"\xFF" * ((bs - len(dat)) % bs)
|
||||
for i in range(0, len(dat) // bs):
|
||||
for i in range(len(dat) // bs):
|
||||
ldat = dat[i * bs:(i + 1) * bs]
|
||||
print("programming %d with length %d" % (i, len(ldat)))
|
||||
self._libusb_handle.controlWrite(0x21, self.DFU_DNLOAD, 2 + i, 0, ldat)
|
||||
|
||||
Reference in New Issue
Block a user