flashing speeeed (#2264)

* less sectors

* why are we taking baby steps

* revert

* cleanup

---------

Co-authored-by: Comma Device <device@comma.ai>
This commit is contained in:
Adeeb Shihadeh
2025-08-31 16:47:03 -07:00
committed by GitHub
parent c1f0cfe223
commit 819fa5854e
3 changed files with 9 additions and 17 deletions

View File

@@ -431,7 +431,7 @@ class Panda:
handle.controlWrite(Panda.REQUEST_IN, 0xb2, i, 0, b'')
# flash over EP2
STEP = 0x10
STEP = 0x200
logger.info("flash: flashing")
for i in range(0, len(code), STEP):
handle.bulkWrite(2, code[i:i + STEP])

View File

@@ -116,10 +116,11 @@ class PandaDFU:
def program_bootstub(self, code_bootstub):
self._handle.clear_status()
# erase all sectors
for i in range(len(self._mcu_type.config.sector_sizes)):
# erase bootstub + app sectors
for i in (0, 1):
self._handle.erase_sector(i)
# write bootstub
self._handle.program(self._mcu_type.config.bootstub_address, code_bootstub)
def recover(self):

View File

@@ -5,7 +5,6 @@ from panda import Panda, PandaDFU
class GPIO:
STM_RST_N = 124
STM_BOOT0 = 134
HUB_RST_N = 30
def gpio_init(pin, output):
@@ -18,32 +17,24 @@ def gpio_set(pin, high):
if __name__ == "__main__":
for pin in (GPIO.STM_RST_N, GPIO.STM_BOOT0, GPIO.HUB_RST_N):
for pin in (GPIO.STM_RST_N, GPIO.STM_BOOT0):
gpio_init(pin, True)
# reset USB hub
gpio_set(GPIO.HUB_RST_N, 0)
time.sleep(0.5)
gpio_set(GPIO.HUB_RST_N, 1)
# flash bootstub
print("resetting into DFU")
gpio_set(GPIO.STM_RST_N, 1)
gpio_set(GPIO.STM_BOOT0, 1)
time.sleep(1)
time.sleep(0.2)
gpio_set(GPIO.STM_RST_N, 0)
gpio_set(GPIO.STM_BOOT0, 0)
time.sleep(1)
# bootstub flash takes 2s and is limited by the 255 byte flashing chunk size
print("flashing bootstub")
assert Panda.wait_for_dfu(None, 5)
PandaDFU(None).recover()
gpio_set(GPIO.STM_RST_N, 1)
time.sleep(0.5)
gpio_set(GPIO.STM_RST_N, 0)
time.sleep(1)
print("flashing app")
assert Panda.wait_for_panda(None, 5)
p = Panda()
assert p.bootstub
p.flash()