mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-10-28 17:13:54 +08:00
Power
Manage device power, parked services and vehicle-specific Panda wake behavior. Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> Co-authored-by: Daniel Koepping <elkoled@gmail.com> Co-authored-by: firestarsdog <229254897+firestarsdog@users.noreply.github.com>
This commit is contained in:
@@ -129,6 +129,7 @@ class Panda:
|
||||
|
||||
# from https://github.com/commaai/openpilot/blob/103b4df18cbc38f4129555ab8b15824d1a672bdf/cereal/log.capnp#L648
|
||||
HW_TYPE_UNKNOWN = b'\x00'
|
||||
HW_TYPE_DOS = b'\x06'
|
||||
HW_TYPE_RED_PANDA = b'\x07'
|
||||
HW_TYPE_TRES = b'\x09'
|
||||
HW_TYPE_CUATRO = b'\x0a'
|
||||
@@ -150,9 +151,10 @@ class Panda:
|
||||
HEALTH_FLAG_HARDFAULT_RESET = 1 << 8
|
||||
|
||||
H7_DEVICES = [HW_TYPE_RED_PANDA, HW_TYPE_TRES, HW_TYPE_CUATRO, HW_TYPE_BODY]
|
||||
SUPPORTED_DEVICES = H7_DEVICES
|
||||
F4_DEVICES = [HW_TYPE_DOS]
|
||||
SUPPORTED_DEVICES = H7_DEVICES + F4_DEVICES
|
||||
|
||||
INTERNAL_DEVICES = (HW_TYPE_TRES, HW_TYPE_CUATRO)
|
||||
INTERNAL_DEVICES = (HW_TYPE_DOS, HW_TYPE_TRES, HW_TYPE_CUATRO)
|
||||
|
||||
HARNESS_STATUS_NC = 0
|
||||
HARNESS_STATUS_NORMAL = 1
|
||||
@@ -408,7 +410,9 @@ class Panda:
|
||||
apps_sectors_cumsum = accumulate(mcu_type.config.sector_sizes[1:])
|
||||
last_sector = next((i + 1 for i, v in enumerate(apps_sectors_cumsum) if v > len(code)), -1)
|
||||
assert last_sector >= 1, "Binary too small? No sector to erase."
|
||||
assert last_sector < 7, "Binary too large! Risk of overwriting provisioning chunk."
|
||||
assert last_sector < len(mcu_type.config.sector_sizes), "Binary too large! Risk of overwriting provisioning chunk."
|
||||
if mcu_type == McuType.F4:
|
||||
assert last_sector < 12, "DOS bootstubs support sectors 1..11"
|
||||
|
||||
# unlock flash
|
||||
logger.info("flash: unlocking")
|
||||
@@ -440,7 +444,7 @@ class Panda:
|
||||
return
|
||||
|
||||
if not fn:
|
||||
fn = os.path.join(FW_PATH, McuType.H7.config.app_fn)
|
||||
fn = os.path.join(FW_PATH, self.get_mcu_type().config.app_fn)
|
||||
assert os.path.isfile(fn)
|
||||
logger.debug("flash: main version is %s", self.get_version())
|
||||
if not self.bootstub:
|
||||
@@ -455,7 +459,7 @@ class Panda:
|
||||
logger.debug("flash: bootstub version is %s", self.get_version())
|
||||
|
||||
# do flash
|
||||
Panda.flash_static(self._handle, code, mcu_type=McuType.H7)
|
||||
Panda.flash_static(self._handle, code, mcu_type=self.get_mcu_type())
|
||||
|
||||
# reconnect
|
||||
if reconnect:
|
||||
@@ -506,7 +510,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, McuType.H7.config.app_fn)
|
||||
fn = os.path.join(FW_PATH, self.get_mcu_type().config.app_fn)
|
||||
expected = Panda.get_signature_from_firmware(fn)
|
||||
return (current == expected)
|
||||
|
||||
@@ -639,8 +643,16 @@ class Panda:
|
||||
"""
|
||||
return self._serial
|
||||
|
||||
def get_mcu_type(self) -> McuType:
|
||||
hw_type = self.get_type()
|
||||
if hw_type in self.F4_DEVICES:
|
||||
return McuType.F4
|
||||
if hw_type in self.H7_DEVICES:
|
||||
return McuType.H7
|
||||
raise ValueError(f"Unknown HW: {hw_type}")
|
||||
|
||||
def get_dfu_serial(self):
|
||||
return PandaDFU.st_serial_to_dfu_serial(self._serial, McuType.H7)
|
||||
return PandaDFU.st_serial_to_dfu_serial(self._serial, self.get_mcu_type())
|
||||
|
||||
def get_uid(self):
|
||||
"""
|
||||
|
||||
@@ -31,6 +31,13 @@ class McuConfig(NamedTuple):
|
||||
return self.bootstub_address + sum(self.sector_sizes[:i])
|
||||
|
||||
|
||||
F4Config = McuConfig(
|
||||
"STM32F4", 0x463,
|
||||
[0x4000 for _ in range(4)] + [0x10000] + [0x20000 for _ in range(11)],
|
||||
16, 0x1FFF7A10, 0x800, 0x1FFF79C0, 0x8004000,
|
||||
"panda.bin.signed", 0x8000000, "bootstub.panda.bin",
|
||||
)
|
||||
|
||||
H7Config = McuConfig(
|
||||
"STM32H7",
|
||||
0x483,
|
||||
@@ -48,6 +55,7 @@ H7Config = McuConfig(
|
||||
|
||||
@enum.unique
|
||||
class McuType(enum.Enum):
|
||||
F4 = F4Config
|
||||
H7 = H7Config
|
||||
|
||||
@property
|
||||
|
||||
@@ -104,6 +104,8 @@ class PandaDFU:
|
||||
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")
|
||||
if mcu_type == McuType.F4:
|
||||
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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user