From ccc890c1553db1849e2b90cf83e44bdd237fc3af Mon Sep 17 00:00:00 2001 From: dominikn Date: Wed, 22 Nov 2023 15:11:49 +0100 Subject: [PATCH] fix flash rw unprotecting --- flash-firmware.py | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/flash-firmware.py b/flash-firmware.py index 5e358ef..00b3359 100755 --- a/flash-firmware.py +++ b/flash-firmware.py @@ -60,30 +60,33 @@ def exit_bootloader_mode(self): def flash_firmware(self): self.enter_bootloader_mode() - # Flashing the firmware - succes_no = 0 + # Disable the flash write-protection for i in range(self.max_approach_no): try: - if succes_no == 0: - # Disable the flash write-protection - sh.stm32flash(self.port, "-u", _out=sys.stdout) - time.sleep(0.2) - succes_no += 1 - - if succes_no == 1: - # Disable the flash read-protection - sh.stm32flash(self.port, "-k", _out=sys.stdout) - time.sleep(0.2) - succes_no += 1 - - if succes_no == 2: - # Flashing the firmware - sh.stm32flash(self.port, "-v", w=self.binary_file, b="115200", _out=sys.stdout) - time.sleep(0.2) - break + sh.stm32flash(self.port, "-u", _out=sys.stdout) + time.sleep(0.2) except Exception: pass + else: + print("ERROR! Something goes wrong. Try again.") + # Disable the flash read-protection + for i in range(self.max_approach_no): + try: + sh.stm32flash(self.port, "-k", _out=sys.stdout) + time.sleep(0.2) + except Exception: + pass + else: + print("ERROR! Something goes wrong. Try again.") + + # Flashing the firmware + for i in range(self.max_approach_no): + try: + sh.stm32flash(self.port, "-v", w=self.binary_file, b="115200", _out=sys.stdout) + time.sleep(0.2) + except Exception: + pass else: print("ERROR! Something goes wrong. Try again.")