diff --git a/python/dfu.py b/python/dfu.py index 9beba45e5..4394d2502 100644 --- a/python/dfu.py +++ b/python/dfu.py @@ -100,11 +100,14 @@ class PandaDFU: def st_serial_to_dfu_serial(st: str, mcu_type: McuType = McuType.F4): if st is None or st == "none": return None - uid_base = struct.unpack("H" * 6, bytes.fromhex(st)) - if mcu_type == McuType.H7: - return binascii.hexlify(struct.pack("!HHH", uid_base[1] + uid_base[5], uid_base[0] + uid_base[4], uid_base[3])).upper().decode("utf-8") - else: - return binascii.hexlify(struct.pack("!HHH", uid_base[1] + uid_base[5], uid_base[0] + uid_base[4] + 0xA, uid_base[3])).upper().decode("utf-8") + try: + uid_base = struct.unpack("H" * 6, bytes.fromhex(st)) + if mcu_type == McuType.H7: + return binascii.hexlify(struct.pack("!HHH", uid_base[1] + uid_base[5], uid_base[0] + uid_base[4], uid_base[3])).upper().decode("utf-8") + else: + return binascii.hexlify(struct.pack("!HHH", uid_base[1] + uid_base[5], uid_base[0] + uid_base[4] + 0xA, uid_base[3])).upper().decode("utf-8") + except struct.error: + return None def get_mcu_type(self) -> McuType: return self._mcu_type diff --git a/python/spi.py b/python/spi.py index 5be1e56b6..2b086dc2b 100644 --- a/python/spi.py +++ b/python/spi.py @@ -402,7 +402,8 @@ class STBootloaderSPIHandle(BaseSTBootloaderHandle): def get_chip_id(self) -> int: r = self._cmd(0x02, read_bytes=3) - assert r[0] == 1 # response length - 1 + if r[0] != 1: # response length - 1 + raise PandaSpiException("incorrect response length") return ((r[1] << 8) + r[2]) def go_cmd(self, address: int) -> None: