Skip to content

Commit

Permalink
fix flash rw unprotecting
Browse files Browse the repository at this point in the history
  • Loading branch information
DominikN committed Nov 22, 2023
1 parent 8b81972 commit ccc890c
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions flash-firmware.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")

Expand Down

0 comments on commit ccc890c

Please sign in to comment.