diff --git a/mik32_eeprom.py b/mik32_eeprom.py index e8d1f7a..6b17780 100644 --- a/mik32_eeprom.py +++ b/mik32_eeprom.py @@ -203,6 +203,8 @@ def write_words(words: List[int], write_by_word = False, read_through_apb = Fals TODO: implement setting byte array offset, add error handling, improve progress visualization, add option check page immidiately after writing + + @return: return 0 if successful, 1 if failed """ print(f"Write {len(words*4)} bytes") with OpenOcdTclRpc() as openocd: diff --git a/mik32_spifi.py b/mik32_spifi.py index f334894..214b675 100644 --- a/mik32_spifi.py +++ b/mik32_spifi.py @@ -334,7 +334,7 @@ def spifi_chip_erase(openocd: OpenOcdTclRpc): spifi_wait_intrq_timeout(openocd, "Timeout executing chip erase command") -def spifi_read_data(openocd: OpenOcdTclRpc, address: int, byte_count: int, bin_data: List[int]): +def spifi_read_data(openocd: OpenOcdTclRpc, address: int, byte_count: int, bin_data: List[int]) -> int: print("read data") read_data: List[int] = [] openocd.write_word(SPIFI_CONFIG_ADDR, address) @@ -374,6 +374,9 @@ def spifi_read_data(openocd: OpenOcdTclRpc, address: int, byte_count: int, bin_d for i in range(byte_count): if read_data[i] != bin_data[address + i]: print(f"DATA[{i+address}] = {read_data[i]:#0x} - ошибка") + return 1 + + return 0 def spifi_page_program(openocd: OpenOcdTclRpc, ByteAddress: int, data: List[int], byte_count: int): @@ -444,13 +447,16 @@ def spifi_write_file(bytes: List[int], is_resume=True): break print("address = ", address) spifi_write(openocd, address, bytes, 256) - spifi_read_data(openocd, address, 256, bytes) + if spifi_read_data(openocd, address, 256, bytes) == 1: + return 1 if (len(bytes) % 256) != 0: print( f"address = {address}, +{len(bytes) - address-1}[{address + len(bytes) - address-1}]") spifi_write(openocd, address, bytes, len(bytes) - address) - spifi_read_data(openocd, address, len(bytes) - address, bytes) + if spifi_read_data(openocd, address, len(bytes) - address, bytes) == 1: + return 1 print("end") if is_resume: openocd.resume(0) + return 0 diff --git a/mik32_upload.py b/mik32_upload.py index 74d36b0..0793458 100644 --- a/mik32_upload.py +++ b/mik32_upload.py @@ -39,6 +39,8 @@ def upload_file(filename: str, boot_source: str = "eeprom", is_resume=True) -> i @filename: full path to the file with hex or bin file format @boot_source: boot source, eeprom, ram or spifi, define memory block mapped to boot memory area (0x0 offset) + @return: return 0 if successful, 1 if failed + TODO: Implement error handling """ @@ -71,8 +73,7 @@ def upload_file(filename: str, boot_source: str = "eeprom", is_resume=True) -> i if boot_source == "eeprom": result = write_words(bytes2words(get_content(filename)), is_resume) elif boot_source == "spifi": - spifi_write_file(get_content(filename), is_resume) - result = 0 # TODO + result = spifi_write_file(get_content(filename), is_resume) elif boot_source == "ram": write_file(filename, is_resume) result = 0 # TODO