From f3c371b005ff92e18b04a6599d82a49228df9f3e Mon Sep 17 00:00:00 2001 From: Codex Date: Sat, 15 Aug 2026 07:33:57 +0000 Subject: [PATCH] pandad: wait for internal SPI panda to boot its app before flashing (fallback to recover) --- openpilot/selfdrive/pandad/pandad.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/openpilot/selfdrive/pandad/pandad.py b/openpilot/selfdrive/pandad/pandad.py index a618daccc..856be9f5c 100755 --- a/openpilot/selfdrive/pandad/pandad.py +++ b/openpilot/selfdrive/pandad/pandad.py @@ -104,11 +104,27 @@ def main() -> None: while not do_exit: try: cloudlog.event("pandad.flash_and_connect", count=count) - if (count % 2) == 0: - HARDWARE.reset_internal_panda() - else: - HARDWARE.recover_internal_panda() + HARDWARE.reset_internal_panda() count += 1 + # The internal SPI panda takes ~10s to boot its app after a reset. + # Wait for it to come back in normal (non-bootstub) mode before + # deciding whether to flash. Only fall back to the bootloader + # (recover) path if it never appears. + panda_serials: list[str] = [] + for _ in range(40): + panda_serials = Panda.list() + if panda_serials: + try: + with Panda(panda_serials[0]) as p: + if not p.bootstub: + break + except Exception: + pass + time.sleep(0.5) + if not panda_serials: + cloudlog.info("Panda did not appear after reset, trying recover...") + HARDWARE.recover_internal_panda() + time.sleep(5) # Flash all Pandas in DFU mode for serial in PandaDFU.list():