diff --git a/mik32_spifi.py b/mik32_spifi.py index 75b1d88..92edad3 100644 --- a/mik32_spifi.py +++ b/mik32_spifi.py @@ -310,10 +310,26 @@ def spifi_send_command( return out_list if direction == SPIFI_Direction.WRITE: - for i in range(byte_count): - # openocd.write_word(SPIFI_CONFIG_DATA32, data[i+ByteAddress]) - openocd.write_memory(SPIFI_CONFIG_DATA32, 8, [data[i]]) + start_time = time.perf_counter() + openocd.write_memory(0x02003F00, 8, data) + + write_time = time.perf_counter() - start_time + print(f"write ram time {write_time:.2f}") + + start_time = time.perf_counter() + + if (byte_count % 4) == 0: + for i in range(0, byte_count, 4): + # openocd.write_word(SPIFI_CONFIG_DATA32, data[i+ByteAddress]) + openocd.write_memory(SPIFI_CONFIG_DATA32, 32, [data[i] + data[i+1] * 256 + data[i+2] * 256 * 256 + data[i+3] * 256 * 256 * 256]) + else: + for i in range(byte_count): + openocd.write_memory(SPIFI_CONFIG_DATA32, 8, [data[i]]) + + write_time = time.perf_counter() - start_time + print(f"write memory time {write_time:.2f}") + return [] @@ -345,7 +361,7 @@ def spifi_chip_erase(openocd: OpenOcdTclRpc): def spifi_sector_erase(openocd: OpenOcdTclRpc, address: int): - print("Erase sector %s..." % hex(address), flush=True) + print(f"Erase sector {address:#010x}...", flush=True) spifi_send_command(openocd, SECTOR_ERASE_COMMAND, SPIFI_Frameform.OPCODE_3ADDR, SPIFI_Fieldform.ALL_SERIAL, address=address) @@ -487,6 +503,7 @@ def write_pages(pages: Dict[int, List[int]], openocd: OpenOcdTclRpc, use_quad_sp address = 0 if (use_quad_spi): + print("quad enable") spifi_quad_enable(openocd) else: spifi_quad_disable(openocd) @@ -496,12 +513,17 @@ def write_pages(pages: Dict[int, List[int]], openocd: OpenOcdTclRpc, use_quad_sp for index, page_offset in enumerate(pages_offsets): page_bytes = pages[page_offset] + start_time = time.perf_counter() + if (use_quad_spi): spifi_quad_page_program( openocd, page_offset, page_bytes, 256, f"{(index*100)//pages_offsets.__len__()}%") else: spifi_page_program(openocd, page_offset, page_bytes, 256, f"{(index*100)//pages_offsets.__len__()}%") + + page_program_time = time.perf_counter() - start_time + print(f"page program time {page_program_time:.2f}") result = spifi_read_data(openocd, page_offset, 256, page_bytes) diff --git a/mik32_upload.py b/mik32_upload.py index 91014d6..2eaac98 100644 --- a/mik32_upload.py +++ b/mik32_upload.py @@ -2,6 +2,7 @@ import shlex import argparse import subprocess import os +import time from enum import Enum from typing import List, Dict, NamedTuple, Union from tclrpc import OpenOcdTclRpc, TclException @@ -212,6 +213,7 @@ def run_openocd( openocd_target=openocd_target_path, is_open_console=False ) -> subprocess.Popen: + print(openocd_scripts) cmd = shlex.split( f"{openocd_exec} -s {openocd_scripts} " f"-f {openocd_interface} -f {openocd_target}", posix=False @@ -312,6 +314,7 @@ def upload_file( openocd.run(f"log_output \"{log_path}\"") openocd.run(f"debug_level 1") + start_time = time.perf_counter() if (pages.pages_eeprom.__len__() > 0): result |= mik32_eeprom.write_pages( pages.pages_eeprom, openocd) @@ -325,6 +328,9 @@ def upload_file( mik32_ram.write_segments(segments_ram, openocd) result |= 0 + write_time = time.perf_counter() - start_time + print(f"All segments written in {write_time:.2f} seconds") + openocd.run(post_action) except ConnectionRefusedError: print("ERROR: The connection to OpenOCD is not established. Check the settings and connection of the debugger") @@ -430,6 +436,13 @@ def createParser(): default=default_log_path, help=f"Путь к файлу журнала. По умолчанию: {default_log_path}" ) + # parser.add_argument( + # '--log-terminal', + # dest='log_termir', + # action='store_true', + # default=False, + # help='Вывод журнала в консоль' + # ) parser.add_argument( '--post-action', dest='post_action',