From 187aa9a3cfc0efe867ea2dced834c77c0496c8f4 Mon Sep 17 00:00:00 2001 From: Grigori Goronzy Date: Sat, 9 Jan 2021 02:16:27 +0100 Subject: [PATCH] stc15: erase EEPROM flash when needed If option eeprom_erase_enabled is False, we need to signal to the BSL to explicitly erase EEPROM flash when needed. Addresses #59. --- stcgal/protocols.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/stcgal/protocols.py b/stcgal/protocols.py index 382792a..aeaed46 100644 --- a/stcgal/protocols.py +++ b/stcgal/protocols.py @@ -1464,11 +1464,15 @@ class Stc15Protocol(Stc15AProtocol): Note that this protocol always seems to erase everything. """ - # XXX: how does partial erase work? - print("Erasing flash: ", end="") sys.stdout.flush() - packet = bytes([0x03, 0x00]) + packet = bytes([0x03]) + if erase_size <= flash_size: + # erase flash only + packet += bytes([0x00]) + else: + # erase flash and eeprom + packet += bytes([0x01]) if self.bsl_version >= 0x72: packet += bytes([0x00, 0x5a, 0xa5]) self.write_packet(packet)