optimize periphery regs write, add timestamps

This commit is contained in:
Sergey Shchelkanov 2024-01-19 18:02:28 +03:00
parent 6fe85c2058
commit c699c4e072
5 changed files with 32 additions and 17 deletions

View File

@ -227,10 +227,6 @@ class DMA_Channel:
destination_address: int, destination_address: int,
length: int, length: int,
): ):
self.set_source(source_address)
self.set_destination(destination_address)
self.set_length(length)
self.write_buffer |= (DMA_CFG_CH_ENABLE_M self.write_buffer |= (DMA_CFG_CH_ENABLE_M
| (self.priority.value << DMA_CFG_CH_PRIOR_S) | (self.priority.value << DMA_CFG_CH_PRIOR_S)
| (self.read_mode.value << DMA_CFG_CH_READ_MODE_S) | (self.read_mode.value << DMA_CFG_CH_READ_MODE_S)
@ -246,7 +242,7 @@ class DMA_Channel:
| (self.write_request.value << DMA_CFG_CH_WRITE_REQ_S) | (self.write_request.value << DMA_CFG_CH_WRITE_REQ_S)
| (self.write_ack.value << DMA_CFG_CH_ACK_WRITE_S)) | (self.write_ack.value << DMA_CFG_CH_ACK_WRITE_S))
self.set_config(self.write_buffer) self.openocd.write_memory(DMA_CHANNEL_DESTINATION(1), 32, [destination_address, source_address, length, self.write_buffer])
class DMA: class DMA:

View File

@ -70,9 +70,8 @@ class EEPROM_AffectedPages(Enum):
def eeprom_execute_operation(openocd: OpenOcdTclRpc, op: EEPROM_Operation, affected_pages: EEPROM_AffectedPages, offset: int, buffer: List[int]): def eeprom_execute_operation(openocd: OpenOcdTclRpc, op: EEPROM_Operation, affected_pages: EEPROM_AffectedPages, offset: int, buffer: List[int]):
# buffer write enable and select affected pages # buffer write enable and select affected pages
openocd.write_word(EEPROM_REGS_EECON, (1 << EEPROM_BWE_S) openocd.write_memory(EEPROM_REGS_EEA, 32, [offset, (1 << EEPROM_BWE_S)
| (affected_pages.value << EEPROM_WRBEH_S)) | (affected_pages.value << EEPROM_WRBEH_S)])
openocd.write_word(EEPROM_REGS_EEA, offset)
if buffer.__len__() > 32: if buffer.__len__() > 32:
return return

View File

@ -3,6 +3,7 @@ from mik32_upload import Segment
from tclrpc import TclException from tclrpc import TclException
from tclrpc import OpenOcdTclRpc from tclrpc import OpenOcdTclRpc
from pathlib import Path from pathlib import Path
import time
from utils import bytes2words from utils import bytes2words
@ -17,7 +18,9 @@ def write_file(filename):
def write_segments(segments: List[Segment], openocd: OpenOcdTclRpc): def write_segments(segments: List[Segment], openocd: OpenOcdTclRpc):
openocd.halt() openocd.halt()
for segment in segments: for segment in segments:
print("Writing segment %s with size %d..." % (hex(segment.offset), segment.data.__len__())) t = time.localtime()
current_time = time.strftime("%H:%M:%S", t)
print("[{current_time}] Writing segment %s with size %d..." % (hex(segment.offset), segment.data.__len__()))
segment_words = bytes2words(segment.data) segment_words = bytes2words(segment.data)
openocd.write_memory(segment.offset, 32, segment_words) openocd.write_memory(segment.offset, 32, segment_words)

View File

@ -293,11 +293,7 @@ def spifi_send_command(
255 255
) )
openocd.write_word(SPIFI_CONFIG_ADDR, address) openocd.write_memory(SPIFI_CONFIG_ADDR, 32, [address, idata])
# if idata != 0:
# openocd.write_word(SPIFI_CONFIG_IDATA, idata)
# if cache_limit != 0:
# openocd.write_word(SPIFI_CONFIG_CLIMIT, cache_limit)
# # spifi_intrq_clear(openocd) # # spifi_intrq_clear(openocd)
# openocd.write_word(SPIFI_CONFIG_CMD, (cmd << SPIFI_CONFIG_CMD_OPCODE_S) | # openocd.write_word(SPIFI_CONFIG_CMD, (cmd << SPIFI_CONFIG_CMD_OPCODE_S) |
@ -315,7 +311,7 @@ def spifi_send_command(
(idata_length << SPIFI_CONFIG_CMD_INTLEN_S) | (idata_length << SPIFI_CONFIG_CMD_INTLEN_S) |
(direction.value << SPIFI_CONFIG_CMD_DOUT_S)) (direction.value << SPIFI_CONFIG_CMD_DOUT_S))
openocd.write_memory(SPIFI_CONFIG_CMD, 32, [cmd_write_value, address, idata, cache_limit]) openocd.write_memory(SPIFI_CONFIG_CMD, 32, [cmd_write_value])
if direction == SPIFI_Direction.READ: if direction == SPIFI_Direction.READ:
out_list = [] out_list = []
@ -594,10 +590,18 @@ def check_pages(pages: Dict[int, List[int]], openocd: OpenOcdTclRpc, use_quad_sp
print("SPIFI page checking completed", flush=True) print("SPIFI page checking completed", flush=True)
return 0 return 0
# # PROFILING IMPORTS
# import cProfile, pstats, io
# from pstats import SortKey
def write_pages(pages: Dict[int, List[int]], openocd: OpenOcdTclRpc, use_quad_spi=False, use_chip_erase=False): def write_pages(pages: Dict[int, List[int]], openocd: OpenOcdTclRpc, use_quad_spi=False, use_chip_erase=False):
result = 0 result = 0
# # PROFILING INIT
# pr = cProfile.Profile()
# pr.enable()
# # PROFILING INIT END
openocd.halt() openocd.halt()
spifi_init(openocd) spifi_init(openocd)
@ -686,6 +690,15 @@ def write_pages(pages: Dict[int, List[int]], openocd: OpenOcdTclRpc, use_quad_sp
if (use_quad_spi): if (use_quad_spi):
spifi_quad_disable(openocd) spifi_quad_disable(openocd)
# # PROFILING GET STATS
# pr.disable()
# s = io.StringIO()
# sortby = SortKey.CUMULATIVE
# ps = pstats.Stats(pr, stream=s).sort_stats(sortby)
# ps.print_stats()
# print(s.getvalue())
# # PROFILING GET STATS END
if result == 0: if result == 0:
print("SPIFI page recording completed", flush=True) print("SPIFI page recording completed", flush=True)
return 0 return 0

View File

@ -247,8 +247,10 @@ def upload_file(
write_time = time.perf_counter() - start_time write_time = time.perf_counter() - start_time
write_size = pages.pages_eeprom.__len__( write_size = pages.pages_eeprom.__len__(
) * memory_page_size[MemoryType.EEPROM] ) * memory_page_size[MemoryType.EEPROM]
t = time.localtime()
current_time = time.strftime("%H:%M:%S", t)
print( print(
f"Wrote {write_size} bytes in {write_time:.2f} seconds (effective {(write_size/(write_time*1024)):.1f} kbyte/s)") f"[{current_time}] Wrote {write_size} bytes in {write_time:.2f} seconds (effective {(write_size/(write_time*1024)):.1f} kbyte/s)")
if (pages.pages_spifi.__len__() > 0): if (pages.pages_spifi.__len__() > 0):
gpio_init(openocd, mik_version) gpio_init(openocd, mik_version)
start_time = time.perf_counter() start_time = time.perf_counter()
@ -259,8 +261,10 @@ def upload_file(
write_time = time.perf_counter() - start_time write_time = time.perf_counter() - start_time
write_size = pages.pages_spifi.__len__( write_size = pages.pages_spifi.__len__(
) * memory_page_size[MemoryType.SPIFI] ) * memory_page_size[MemoryType.SPIFI]
t = time.localtime()
current_time = time.strftime("%H:%M:%S", t)
print( print(
f"Wrote {write_size} bytes in {write_time:.2f} seconds (effective {(write_size/(write_time*1024)):.1f} kbyte/s)") f"[{current_time}] Wrote {write_size} bytes in {write_time:.2f} seconds (effective {(write_size/(write_time*1024)):.1f} kbyte/s)")
gpio_deinit(openocd, mik_version) gpio_deinit(openocd, mik_version)
segments_ram = list(filter( segments_ram = list(filter(