diff --git a/python/__init__.py b/python/__init__.py index cde75637..c89582d5 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -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]) diff --git a/python/dfu.py b/python/dfu.py index c62ba5cc..624530cb 100644 --- a/python/dfu.py +++ b/python/dfu.py @@ -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): diff --git a/scripts/reflash_internal_panda.py b/scripts/reflash_internal_panda.py index c2ad9f89..e892faf8 100755 --- a/scripts/reflash_internal_panda.py +++ b/scripts/reflash_internal_panda.py @@ -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()