remove mcu_type (#2324)

* remove mcu_type from Panda, it's redundant since all supported devices are H7

* revert disable automatic CAN-FD switching H7 check

* revert original can no longer be flashed error

* assert, assert, assert

* normal reset is fine
This commit is contained in:
Andi Radulescu
2026-02-09 19:36:32 +02:00
committed by GitHub
parent 259645f427
commit 8922b48a30
5 changed files with 20 additions and 41 deletions

View File

@@ -52,7 +52,7 @@ class PandaJungle(Panda):
def flash(self, fn=None, code=None, reconnect=True):
if not fn:
fn = os.path.join(FW_PATH, self._mcu_type.config.app_fn.replace("panda", "panda_jungle"))
fn = os.path.join(FW_PATH, McuType.H7.config.app_fn.replace("panda", "panda_jungle"))
super().flash(fn=fn, code=code, reconnect=reconnect)
def recover(self, timeout: int | None = 60, reset: bool = True) -> bool:
@@ -73,15 +73,9 @@ class PandaJungle(Panda):
self.flash()
return True
def get_mcu_type(self) -> McuType:
hw_type = self.get_type()
if hw_type in PandaJungle.H7_DEVICES:
return McuType.H7
raise ValueError(f"unknown HW type: {hw_type}")
def up_to_date(self, fn=None) -> bool:
if fn is None:
fn = os.path.join(FW_PATH, self.get_mcu_type().config.app_fn.replace("panda", "panda_jungle"))
fn = os.path.join(FW_PATH, McuType.H7.config.app_fn.replace("panda", "panda_jungle"))
return super().up_to_date(fn=fn)
# ******************* health *******************

View File

@@ -145,7 +145,6 @@ class Panda:
else:
self._connect_serial = serial
# connect and set mcu type
self.connect(claim)
def _cli_select_panda(self):
@@ -202,13 +201,9 @@ class Panda:
self._serial = serial
self._connect_serial = serial
self._handle_open = True
self._mcu_type = self.get_mcu_type()
self.health_version, self.can_version, self.can_health_version = self.get_packets_versions()
logger.debug("connected")
hw_type = self.get_type()
assert hw_type in self.SUPPORTED_DEVICES, f"Unknown HW: {hw_type}"
# disable openpilot's heartbeat checks
if self._disable_checks:
self.set_heartbeat_disabled()
@@ -335,6 +330,9 @@ class Panda:
return []
def reset(self, enter_bootstub=False, enter_bootloader=False, reconnect=True):
if enter_bootstub or enter_bootloader:
assert (hw_type := self.get_type()) in self.SUPPORTED_DEVICES, f"Unknown HW: {hw_type}"
# no response is expected since it resets right away
timeout = 5000 if isinstance(self._handle, PandaSpiHandle) else 15000
try:
@@ -414,16 +412,14 @@ class Panda:
pass
def flash(self, fn=None, code=None, reconnect=True):
assert (hw_type := self.get_type()) in self.SUPPORTED_DEVICES, f"Unknown HW: {hw_type}"
if self.up_to_date(fn=fn):
logger.info("flash: already up to date")
return
hw_type = self.get_type()
if hw_type not in self.SUPPORTED_DEVICES:
raise RuntimeError(f"HW type {hw_type.hex()} is deprecated and can no longer be flashed.")
if not fn:
fn = os.path.join(FW_PATH, self._mcu_type.config.app_fn)
fn = os.path.join(FW_PATH, McuType.H7.config.app_fn)
assert os.path.isfile(fn)
logger.debug("flash: main version is %s", self.get_version())
if not self.bootstub:
@@ -438,13 +434,15 @@ class Panda:
logger.debug("flash: bootstub version is %s", self.get_version())
# do flash
Panda.flash_static(self._handle, code, mcu_type=self._mcu_type)
Panda.flash_static(self._handle, code, mcu_type=McuType.H7)
# reconnect
if reconnect:
self.reconnect()
def recover(self, timeout: int | None = 60, reset: bool = True) -> bool:
assert (hw_type := self.get_type()) in self.SUPPORTED_DEVICES, f"Unknown HW: {hw_type}"
dfu_serial = self.get_dfu_serial()
if reset:
@@ -489,7 +487,7 @@ class Panda:
def up_to_date(self, fn=None) -> bool:
current = self.get_signature()
if fn is None:
fn = os.path.join(FW_PATH, self.get_mcu_type().config.app_fn)
fn = os.path.join(FW_PATH, McuType.H7.config.app_fn)
expected = Panda.get_signature_from_firmware(fn)
return (current == expected)
@@ -601,12 +599,6 @@ class Panda:
else:
return (0, 0, 0)
def get_mcu_type(self) -> McuType:
hw_type = self.get_type()
if hw_type in Panda.H7_DEVICES:
return McuType.H7
raise ValueError(f"unknown HW type: {hw_type}")
def is_internal(self):
return self.get_type() in Panda.INTERNAL_DEVICES
@@ -627,7 +619,7 @@ class Panda:
return self._serial
def get_dfu_serial(self):
return PandaDFU.st_serial_to_dfu_serial(self._serial, self._mcu_type)
return PandaDFU.st_serial_to_dfu_serial(self._serial, McuType.H7)
def get_uid(self):
"""

View File

@@ -11,7 +11,6 @@ def check_signature(p):
def test_dfu(p):
app_mcu_type = p.get_mcu_type()
dfu_serial = p.get_dfu_serial()
p.reset(enter_bootstub=True)
@@ -19,7 +18,7 @@ def test_dfu(p):
assert Panda.wait_for_dfu(dfu_serial, timeout=19), "failed to enter DFU"
dfu = PandaDFU(dfu_serial)
assert dfu.get_mcu_type() == app_mcu_type
assert dfu.get_mcu_type() == McuType.H7
assert dfu_serial in PandaDFU.list()
@@ -38,9 +37,9 @@ def test_known_bootstub(p):
McuType.H7: ["bootstub.panda_h7.bin"],
}
for kb in known_bootstubs[p.get_mcu_type()]:
app_ids = (p.get_mcu_type(), p.get_usb_serial())
assert None not in app_ids
for kb in known_bootstubs[McuType.H7]:
app_serial = p.get_usb_serial()
assert app_serial is not None
p.reset(enter_bootstub=True)
p.reset(enter_bootloader=True)
@@ -57,10 +56,9 @@ def test_known_bootstub(p):
p.connect(claim=False, wait=True)
# check for MCU or serial mismatch
# check for serial mismatch
with Panda(p._serial, claim=False) as np:
bootstub_ids = (np.get_mcu_type(), np.get_usb_serial())
assert app_ids == bootstub_ids
assert np.get_usb_serial() == app_serial
# ensure we can flash app and it jumps to app
p.flash()

View File

@@ -17,8 +17,6 @@ def test_hw_type(p):
"""
hw_type = p.get_type()
mcu_type = p.get_mcu_type()
assert mcu_type is not None
app_uid = p.get_uid()
usb_serial = p.get_usb_serial()
@@ -30,7 +28,6 @@ def test_hw_type(p):
with Panda(p.get_usb_serial()) as pp:
assert pp.bootstub
assert pp.get_type() == hw_type, "Bootstub and app hw type mismatch"
assert pp.get_mcu_type() == mcu_type, "Bootstub and app MCU type mismatch"
assert pp.get_uid() == app_uid
def test_heartbeat(p, panda_jungle):

View File

@@ -15,7 +15,6 @@ def recover(s):
def flash(s):
with PandaJungle(s) as p:
p.flash()
return p.get_mcu_type()
# Reset + flash all CI hardware to get it into a consistent state
# * port 1: jungles-under-test
@@ -42,5 +41,4 @@ if __name__ == "__main__":
for s in SERIALS:
assert PandaJungle.wait_for_panda(s, timeout=10)
assert set(PandaJungle.list()) >= SERIALS
mcu_types = list(exc.map(flash, SERIALS, timeout=20))
assert set(mcu_types) == {McuType.H7, }
list(exc.map(flash, SERIALS, timeout=20))