From c9c2fd8fa585354e87119b0b4a9f13d61839fad6 Mon Sep 17 00:00:00 2001 From: sh-sergey <26677086+sh-sergey@users.noreply.github.com> Date: Tue, 1 Apr 2025 14:44:32 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D0=B4=D0=B4=D0=B5=D1=80=D0=B6?= =?UTF-8?q?=D0=BA=D0=B0=20=D1=87=D0=B0=D1=81=D1=82=D0=B8=D1=87=D0=BD=D0=BE?= =?UTF-8?q?=D0=B3=D0=BE=20=D1=81=D1=82=D0=B8=D1=80=D0=B0=D0=BD=D0=B8=D1=8F?= =?UTF-8?q?=20EEPROM=20=D0=B4=D0=BB=D1=8F=20=D0=BF=D1=80=D0=BE=D1=88=D0=B8?= =?UTF-8?q?=D0=B2=D0=BA=D0=B8=20=D1=81=20=D0=B4=D1=80=D0=B0=D0=B9=D0=B2?= =?UTF-8?q?=D0=B5=D1=80=D0=BE=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mik32_debug_hal/eeprom.py | 29 +++++++++++++++++++++++------ mik32_upload.py | 11 ++++++++++- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/mik32_debug_hal/eeprom.py b/mik32_debug_hal/eeprom.py index fdbeea2..a722765 100644 --- a/mik32_debug_hal/eeprom.py +++ b/mik32_debug_hal/eeprom.py @@ -33,8 +33,9 @@ def combine_pages(pages: Dict[int, List[int]]) -> List[int]: class EEPROM(): openocd: OpenOcdTclRpc - def __init__(self, openocd: OpenOcdTclRpc): + def __init__(self, openocd: OpenOcdTclRpc, full_erase: bool = True): self.openocd = openocd + self.full_erase = full_erase self.eeprom_sysinit() @@ -195,7 +196,7 @@ class EEPROM(): if self.eeprom_check_data_ahb_lite([0]*2048, 0, False): print("EEPROM global erase failed", flush=True) return 1 - + # configure cycles duration self.eeprom_configure_cycles(1, 3, 1, 100000, 1000) time.sleep(0.1) @@ -234,16 +235,32 @@ class EEPROM(): RAM_BUFFER_OFFSET = 0x02001800 RAM_DRIVER_STATUS = 0x02003800 + STATUS_CODE_S = 0 + STATUS_CODE_M = 0x7F + + STATUS_CODE_OK = 0 + STATUS_CODE_START = 1 + STATUS_CODE_MISMATCH = 2 + + STATUS_CODE_ERASE_S = 7 + STATUS_CODE_ERASE_M = (1 << STATUS_CODE_ERASE_S) + STATUS_CODE_ERASE_FULL = 0 + STATUS_CODE_ERASE_USED = STATUS_CODE_ERASE_M + bytes_list = combine_pages(pages) self.openocd.halt() # Отключение прерываний self.openocd.run("riscv.cpu set_reg {mstatus 0 mie 0}") - STATUS_CODE_M = 0xFF - max_address = len(bytes_list) // 128 self.openocd.write_memory(RAM_DRIVER_STATUS, 32, [ - 1 | (max_address << 8)]) + (STATUS_CODE_START << STATUS_CODE_S) | + (max_address << 8) | + ( + STATUS_CODE_ERASE_FULL if self.full_erase + else STATUS_CODE_ERASE_USED << STATUS_CODE_ERASE_S + ) + ]) pathname = os.path.dirname(sys.argv[0]) @@ -281,7 +298,7 @@ class EEPROM(): result = self.openocd.read_memory(RAM_DRIVER_STATUS, 32, 1)[0] - if (result & STATUS_CODE_M) == 0: + if (result & STATUS_CODE_M) == STATUS_CODE_OK: print(f"EEPROM writing successfully completed!", flush=True) else: miss_page = (result >> 8) & (64 - 1) diff --git a/mik32_upload.py b/mik32_upload.py index 8d2aaea..9f9ad94 100644 --- a/mik32_upload.py +++ b/mik32_upload.py @@ -195,6 +195,7 @@ def upload_file( post_action=default_post_action, mik_version=MIK32_Version.MIK32V2, use_driver=True, + eeprom_full_erase=True, ) -> int: """ Запись прошивки в формате Intel HEX или бинарном в память MIK32. @@ -264,7 +265,7 @@ def upload_file( logging.debug("PM configured!") if (pages.pages_eeprom.__len__() > 0): - eeprom = EEPROM(openocd) + eeprom = EEPROM(openocd, full_erase=eeprom_full_erase) start_time = time.perf_counter() @@ -462,6 +463,13 @@ def createParser(): default=True, help='Отключает прошивку с использованием драйвера в ОЗУ' ) + parser.add_argument( + '--eeprom-partial-erase', + dest='eeprom_full_erase', + action='store_false', + default=True, + help='Включает режим очистки EEPROM по страницам для режима с использованием драйвера в ОЗУ' + ) return parser @@ -492,6 +500,7 @@ if __name__ == '__main__': post_action=namespace.post_action, mik_version=namespace.mcu_type, use_driver=namespace.use_driver, + eeprom_full_erase=namespace.eeprom_full_erase, ) ) else: