PandaDFU: fix F2 detection (#1664)

Co-authored-by: Comma Device <device@comma.ai>
This commit is contained in:
Adeeb Shihadeh 2023-09-14 13:50:42 -07:00 committed by GitHub
parent bdecf82605
commit f660323969
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 3 deletions

View File

@ -34,9 +34,15 @@ 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
# lsusb -v | grep Flash
# iInterface 4 @Internal Flash /0x08000000/04*016Kg,01*064Kg,011*128Kg
out = libusb_handle.controlRead(0x80, 0x06, 0x0300 | 4, 0, 255)
flash_desc = bytes(out[2:]).decode('utf-16le')
sector_count = sum([int(s.split('*')[0]) for s in flash_desc.split('/')[-1].split(',')])
mcu_by_sector_count = {len(m.config.sector_sizes): 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: