mirror of
https://github.com/infiniteCable2/panda.git
synced 2026-02-19 01:33:52 +08:00
PandaDFU: retry SPI comms (#1348)
* retry * set exc --------- Co-authored-by: Comma Device <device@comma.ai>
This commit is contained in:
@@ -421,7 +421,7 @@ class Panda:
|
||||
except Exception:
|
||||
logging.debug("reconnecting is taking %d seconds...", i + 1)
|
||||
try:
|
||||
dfu = PandaDFU(PandaDFU.st_serial_to_dfu_serial(self._serial, self._mcu_type))
|
||||
dfu = PandaDFU(self.get_dfu_serial())
|
||||
dfu.recover()
|
||||
except Exception:
|
||||
pass
|
||||
@@ -493,7 +493,7 @@ class Panda:
|
||||
self.reconnect()
|
||||
|
||||
def recover(self, timeout: Optional[int] = None, reset: bool = True) -> bool:
|
||||
dfu_serial = PandaDFU.st_serial_to_dfu_serial(self._serial, self._mcu_type)
|
||||
dfu_serial = self.get_dfu_serial()
|
||||
|
||||
if reset:
|
||||
self.reset(enter_bootstub=True)
|
||||
@@ -677,6 +677,9 @@ class Panda:
|
||||
"""
|
||||
return self._serial
|
||||
|
||||
def get_dfu_serial(self):
|
||||
return PandaDFU.st_serial_to_dfu_serial(self._serial, self._mcu_type)
|
||||
|
||||
def get_uid(self):
|
||||
"""
|
||||
Returns the UID from the MCU
|
||||
|
||||
@@ -149,7 +149,7 @@ class PandaSpiHandle(BaseHandle):
|
||||
return dat[:-1]
|
||||
except PandaSpiException as e:
|
||||
exc = e
|
||||
logging.debug("SPI transfer failed, %d retries left", n, exc_info=True)
|
||||
logging.debug("SPI transfer failed, %d retries left", MAX_XFER_RETRY_COUNT - n - 1, exc_info=True)
|
||||
raise exc
|
||||
|
||||
# libusb1 functions
|
||||
@@ -201,7 +201,7 @@ class STBootloaderSPIHandle(BaseSTBootloaderHandle):
|
||||
spi.xfer([self.SYNC, ])
|
||||
try:
|
||||
self._get_ack(spi)
|
||||
except PandaSpiNackResponse:
|
||||
except (PandaSpiNackResponse, PandaSpiMissingAck):
|
||||
# NACK ok here, will only ACK the first time
|
||||
pass
|
||||
|
||||
@@ -222,7 +222,7 @@ class STBootloaderSPIHandle(BaseSTBootloaderHandle):
|
||||
elif data != self.ACK:
|
||||
raise PandaSpiMissingAck
|
||||
|
||||
def _cmd(self, cmd: int, data: Optional[List[bytes]] = None, read_bytes: int = 0, predata=None) -> bytes:
|
||||
def _cmd_no_retry(self, cmd: int, data: Optional[List[bytes]] = None, read_bytes: int = 0, predata=None) -> bytes:
|
||||
ret = b""
|
||||
with self.dev.acquire() as spi:
|
||||
# sync + command
|
||||
@@ -252,6 +252,16 @@ class STBootloaderSPIHandle(BaseSTBootloaderHandle):
|
||||
|
||||
return bytes(ret)
|
||||
|
||||
def _cmd(self, cmd: int, data: Optional[List[bytes]] = None, read_bytes: int = 0, predata=None) -> bytes:
|
||||
exc = PandaSpiException()
|
||||
for n in range(MAX_XFER_RETRY_COUNT):
|
||||
try:
|
||||
return self._cmd_no_retry(cmd, data, read_bytes, predata)
|
||||
except PandaSpiException as e:
|
||||
exc = e
|
||||
logging.debug("SPI transfer failed, %d retries left", MAX_XFER_RETRY_COUNT - n - 1, exc_info=True)
|
||||
raise exc
|
||||
|
||||
def _checksum(self, data: bytes) -> bytes:
|
||||
if len(data) == 1:
|
||||
ret = data[0] ^ 0xFF
|
||||
|
||||
Reference in New Issue
Block a user