mirror of
https://github.com/MikronMIK32/mik32-uploader.git
synced 2026-01-01 21:37:05 +03:00
spifi check using dma
This commit is contained in:
parent
dd548641b5
commit
23a433baf0
@ -247,6 +247,10 @@ def spifi_init(openocd: OpenOcdTclRpc):
|
|||||||
|
|
||||||
spifi_init_periphery(openocd)
|
spifi_init_periphery(openocd)
|
||||||
|
|
||||||
|
control = openocd.read_word(SPIFI_CONFIG_CTRL)
|
||||||
|
control |= SPIFI_CONFIG_CTRL_DMAEN_M
|
||||||
|
openocd.write_word(SPIFI_CONFIG_CTRL, control)
|
||||||
|
|
||||||
time.sleep(INIT_DELAY)
|
time.sleep(INIT_DELAY)
|
||||||
|
|
||||||
|
|
||||||
@ -319,28 +323,29 @@ def spifi_send_command(
|
|||||||
data: List[int] = [],
|
data: List[int] = [],
|
||||||
dma: Union[DMA, None] = None
|
dma: Union[DMA, None] = None
|
||||||
) -> List[int]:
|
) -> List[int]:
|
||||||
if dma is not None:
|
if dma is not None and direction == SPIFI_Direction.WRITE:
|
||||||
control = openocd.read_word(SPIFI_CONFIG_CTRL)
|
|
||||||
control |= SPIFI_CONFIG_CTRL_DMAEN_M
|
|
||||||
openocd.write_word(SPIFI_CONFIG_CTRL, control)
|
|
||||||
|
|
||||||
# start_time = time.perf_counter()
|
|
||||||
|
|
||||||
openocd.write_memory(0x02003F00, 8, data)
|
openocd.write_memory(0x02003F00, 8, data)
|
||||||
|
|
||||||
# write_time = time.perf_counter() - start_time
|
|
||||||
# print(f"write ram time {write_time:.2f}")
|
|
||||||
|
|
||||||
dma.channels[0].start(
|
dma.channels[0].start(
|
||||||
0x02003F00,
|
0x02003F00,
|
||||||
SPIFI_CONFIG_DATA32,
|
SPIFI_CONFIG_DATA32,
|
||||||
255
|
255
|
||||||
)
|
)
|
||||||
|
elif dma is not None and direction == SPIFI_Direction.READ:
|
||||||
|
dma.channels[1].start(
|
||||||
|
SPIFI_CONFIG_DATA32,
|
||||||
|
0x02003F00,
|
||||||
|
255
|
||||||
|
)
|
||||||
|
|
||||||
|
if address != 0:
|
||||||
openocd.write_word(SPIFI_CONFIG_ADDR, address)
|
openocd.write_word(SPIFI_CONFIG_ADDR, address)
|
||||||
|
if idata != 0:
|
||||||
openocd.write_word(SPIFI_CONFIG_IDATA, idata)
|
openocd.write_word(SPIFI_CONFIG_IDATA, idata)
|
||||||
|
if cache_limit != 0:
|
||||||
openocd.write_word(SPIFI_CONFIG_CLIMIT, cache_limit)
|
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) |
|
||||||
(frameform.value << SPIFI_CONFIG_CMD_FRAMEFORM_S) |
|
(frameform.value << SPIFI_CONFIG_CMD_FRAMEFORM_S) |
|
||||||
(fieldform.value << SPIFI_CONFIG_CMD_FIELDFORM_S) |
|
(fieldform.value << SPIFI_CONFIG_CMD_FIELDFORM_S) |
|
||||||
@ -351,28 +356,28 @@ def spifi_send_command(
|
|||||||
|
|
||||||
if direction == SPIFI_Direction.READ:
|
if direction == SPIFI_Direction.READ:
|
||||||
out_list = []
|
out_list = []
|
||||||
|
if dma is not None:
|
||||||
|
dma.dma_wait(dma.channels[1], 0.1)
|
||||||
|
out_list.extend(openocd.read_memory(0x02003F00, 8, byte_count))
|
||||||
|
|
||||||
|
return out_list
|
||||||
|
else:
|
||||||
for i in range(byte_count):
|
for i in range(byte_count):
|
||||||
out_list.append(openocd.read_memory(SPIFI_CONFIG_DATA32, 8, 1)[0])
|
out_list.append(openocd.read_memory(SPIFI_CONFIG_DATA32, 8, 1)[0])
|
||||||
return out_list
|
return out_list
|
||||||
|
|
||||||
if direction == SPIFI_Direction.WRITE:
|
if direction == SPIFI_Direction.WRITE:
|
||||||
# start_time = time.perf_counter()
|
|
||||||
|
|
||||||
if dma is not None:
|
if dma is not None:
|
||||||
dma.dma_wait(dma.channels[0], 0.1)
|
dma.dma_wait(dma.channels[0], 0.1)
|
||||||
else:
|
else:
|
||||||
if (byte_count % 4) == 0:
|
if (byte_count % 4) == 0:
|
||||||
for i in range(0, byte_count, 4):
|
for i in range(0, byte_count, 4):
|
||||||
# openocd.write_word(SPIFI_CONFIG_DATA32, data[i+ByteAddress])
|
|
||||||
openocd.write_memory(SPIFI_CONFIG_DATA32, 32, [
|
openocd.write_memory(SPIFI_CONFIG_DATA32, 32, [
|
||||||
data[i] + data[i+1] * 256 + data[i+2] * 256 * 256 + data[i+3] * 256 * 256 * 256])
|
data[i] + data[i+1] * 256 + data[i+2] * 256 * 256 + data[i+3] * 256 * 256 * 256])
|
||||||
else:
|
else:
|
||||||
for i in range(byte_count):
|
for i in range(byte_count):
|
||||||
openocd.write_memory(SPIFI_CONFIG_DATA32, 8, [data[i]])
|
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 []
|
return []
|
||||||
|
|
||||||
|
|
||||||
@ -409,26 +414,21 @@ def spifi_sector_erase(openocd: OpenOcdTclRpc, address: int):
|
|||||||
SPIFI_Frameform.OPCODE_3ADDR, SPIFI_Fieldform.ALL_SERIAL, address=address)
|
SPIFI_Frameform.OPCODE_3ADDR, SPIFI_Fieldform.ALL_SERIAL, address=address)
|
||||||
|
|
||||||
|
|
||||||
def spifi_read_data(openocd: OpenOcdTclRpc, address: int, byte_count: int, bin_data: List[int]) -> int:
|
def spifi_read_data(openocd: OpenOcdTclRpc, address: int, byte_count: int, bin_data: List[int], dma: Union[DMA, None] = None) -> int:
|
||||||
read_data: List[int] = []
|
read_data: List[int] = []
|
||||||
|
|
||||||
spifi_init_memory(openocd)
|
read_data = spifi_send_command(openocd, READ_DATA_COMMAND, SPIFI_Frameform.OPCODE_3ADDR, SPIFI_Fieldform.ALL_SERIAL, byte_count=byte_count, address=address, dma=dma)
|
||||||
read_data = openocd.read_memory(0x80000000 + address, 8, 1)
|
|
||||||
read_data = openocd.read_memory(0x80000000 + address, 8, 256)
|
|
||||||
|
|
||||||
# read_data = spifi_send_command(openocd, READ_DATA_COMMAND, SPIFI_Frameform.OPCODE_3ADDR,
|
|
||||||
# SPIFI_Fieldform.ALL_SERIAL, byte_count=byte_count, address=address)
|
|
||||||
|
|
||||||
for i in range(byte_count):
|
for i in range(byte_count):
|
||||||
if read_data[i] != bin_data[i]:
|
if read_data[i] != bin_data[i]:
|
||||||
print(
|
print(
|
||||||
f"DATA[{i+address}] = {read_data[i]:#0x} expect {bin_data[i]:#0x}", flush=True)
|
f"DATA[{i+address}] = {read_data[i]:#0x} expect {bin_data[i]:#0x}", flush=True)
|
||||||
|
|
||||||
spifi_init_periphery(openocd)
|
# spifi_init_periphery(openocd)
|
||||||
read_periph = spifi_send_command(openocd, READ_DATA_COMMAND, SPIFI_Frameform.OPCODE_3ADDR,
|
# read_periph = spifi_send_command(openocd, READ_DATA_COMMAND, SPIFI_Frameform.OPCODE_3ADDR,
|
||||||
SPIFI_Fieldform.ALL_SERIAL, byte_count=1, address=(i+address))
|
# SPIFI_Fieldform.ALL_SERIAL, byte_count=1, address=(i+address))
|
||||||
print(
|
# print(
|
||||||
f"DATA[{i+address}] = {read_periph[0]:#0x} expect {bin_data[i]:#0x}", flush=True)
|
# f"DATA[{i+address}] = {read_periph[0]:#0x} expect {bin_data[i]:#0x}", flush=True)
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
@ -447,8 +447,6 @@ def spifi_page_program(
|
|||||||
if byte_count > 256:
|
if byte_count > 256:
|
||||||
raise Exception("Byte count more than 256")
|
raise Exception("Byte count more than 256")
|
||||||
|
|
||||||
spifi_init_periphery(openocd)
|
|
||||||
|
|
||||||
spifi_write_enable(openocd)
|
spifi_write_enable(openocd)
|
||||||
spifi_send_command(openocd, PAGE_PROGRAM_COMMAND, SPIFI_Frameform.OPCODE_3ADDR,
|
spifi_send_command(openocd, PAGE_PROGRAM_COMMAND, SPIFI_Frameform.OPCODE_3ADDR,
|
||||||
SPIFI_Fieldform.ALL_SERIAL, byte_count=byte_count, address=ByteAddress,
|
SPIFI_Fieldform.ALL_SERIAL, byte_count=byte_count, address=ByteAddress,
|
||||||
@ -569,18 +567,37 @@ def write_pages(pages: Dict[int, List[int]], openocd: OpenOcdTclRpc, use_quad_sp
|
|||||||
|
|
||||||
dma.channels[0].read_mode = ChannelMode.MEMORY
|
dma.channels[0].read_mode = ChannelMode.MEMORY
|
||||||
dma.channels[0].read_increment = ChannelIncrement.ENABLE
|
dma.channels[0].read_increment = ChannelIncrement.ENABLE
|
||||||
dma.channels[0].read_size = ChannelSize.BYTE
|
dma.channels[0].read_size = ChannelSize.WORD
|
||||||
dma.channels[0].read_burst_size = 0
|
dma.channels[0].read_burst_size = 2
|
||||||
dma.channels[0].read_request = ChannelRequest.SPIFI_REQUEST
|
dma.channels[0].read_request = ChannelRequest.SPIFI_REQUEST
|
||||||
dma.channels[0].read_ack = ChannelAck.DISABLE
|
dma.channels[0].read_ack = ChannelAck.DISABLE
|
||||||
|
|
||||||
dma.channels[0].write_mode = ChannelMode.PERIPHERY
|
dma.channels[0].write_mode = ChannelMode.PERIPHERY
|
||||||
dma.channels[0].write_increment = ChannelIncrement.DISABLE
|
dma.channels[0].write_increment = ChannelIncrement.DISABLE
|
||||||
dma.channels[0].write_size = ChannelSize.BYTE
|
dma.channels[0].write_size = ChannelSize.WORD
|
||||||
dma.channels[0].write_burst_size = 0
|
dma.channels[0].write_burst_size = 2
|
||||||
dma.channels[0].write_request = ChannelRequest.SPIFI_REQUEST
|
dma.channels[0].write_request = ChannelRequest.SPIFI_REQUEST
|
||||||
dma.channels[0].write_ack = ChannelAck.DISABLE
|
dma.channels[0].write_ack = ChannelAck.DISABLE
|
||||||
|
|
||||||
|
dma.channels[1].write_buffer = 0
|
||||||
|
|
||||||
|
dma.channels[1].channel = ChannelIndex.CHANNEL_1
|
||||||
|
dma.channels[1].priority = ChannelPriority.VERY_HIGH
|
||||||
|
|
||||||
|
dma.channels[1].write_mode = ChannelMode.MEMORY
|
||||||
|
dma.channels[1].write_increment = ChannelIncrement.ENABLE
|
||||||
|
dma.channels[1].write_size = ChannelSize.WORD
|
||||||
|
dma.channels[1].write_burst_size = 2
|
||||||
|
dma.channels[1].write_request = ChannelRequest.SPIFI_REQUEST
|
||||||
|
dma.channels[1].write_ack = ChannelAck.DISABLE
|
||||||
|
|
||||||
|
dma.channels[1].read_mode = ChannelMode.PERIPHERY
|
||||||
|
dma.channels[1].read_increment = ChannelIncrement.DISABLE
|
||||||
|
dma.channels[1].read_size = ChannelSize.WORD
|
||||||
|
dma.channels[1].read_burst_size = 2
|
||||||
|
dma.channels[1].read_request = ChannelRequest.SPIFI_REQUEST
|
||||||
|
dma.channels[1].read_ack = ChannelAck.DISABLE
|
||||||
|
|
||||||
if use_chip_erase:
|
if use_chip_erase:
|
||||||
spifi_erase(openocd, EraseType.CHIP_ERASE)
|
spifi_erase(openocd, EraseType.CHIP_ERASE)
|
||||||
else:
|
else:
|
||||||
@ -599,8 +616,6 @@ def write_pages(pages: Dict[int, List[int]], openocd: OpenOcdTclRpc, use_quad_sp
|
|||||||
for index, page_offset in enumerate(pages_offsets):
|
for index, page_offset in enumerate(pages_offsets):
|
||||||
page_bytes = pages[page_offset]
|
page_bytes = pages[page_offset]
|
||||||
|
|
||||||
# start_time = time.perf_counter()
|
|
||||||
|
|
||||||
if (use_quad_spi):
|
if (use_quad_spi):
|
||||||
spifi_quad_page_program(
|
spifi_quad_page_program(
|
||||||
openocd, page_offset, page_bytes, 256, f"{(index*100)//pages_offsets.__len__()}%")
|
openocd, page_offset, page_bytes, 256, f"{(index*100)//pages_offsets.__len__()}%")
|
||||||
@ -608,13 +623,7 @@ def write_pages(pages: Dict[int, List[int]], openocd: OpenOcdTclRpc, use_quad_sp
|
|||||||
spifi_page_program(openocd, page_offset, page_bytes,
|
spifi_page_program(openocd, page_offset, page_bytes,
|
||||||
256, f"{(index*100)//pages_offsets.__len__()}%", dma=dma)
|
256, f"{(index*100)//pages_offsets.__len__()}%", dma=dma)
|
||||||
|
|
||||||
# page_program_time = time.perf_counter() - start_time
|
result = spifi_read_data(openocd, page_offset, 256, page_bytes, dma=dma)
|
||||||
# print(f"page program time {page_program_time:.2f}")
|
|
||||||
|
|
||||||
# start_time = time.perf_counter()
|
|
||||||
result = spifi_read_data(openocd, page_offset, 256, page_bytes)
|
|
||||||
# page_program_time = time.perf_counter() - start_time
|
|
||||||
# print(f"page check time {page_program_time:.2f}")
|
|
||||||
|
|
||||||
if result == 1:
|
if result == 1:
|
||||||
print("Data error")
|
print("Data error")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user