mirror of
https://github.com/MikronMIK32/mik32-uploader.git
synced 2026-01-01 13:37:03 +03:00
write flash by pages
This commit is contained in:
parent
ba101bbac1
commit
eb6d32a981
@ -1,4 +1,4 @@
|
|||||||
from typing import List
|
from typing import Dict, List
|
||||||
import time
|
import time
|
||||||
from tclrpc import TclException
|
from tclrpc import TclException
|
||||||
from tclrpc import OpenOcdTclRpc
|
from tclrpc import OpenOcdTclRpc
|
||||||
@ -398,9 +398,10 @@ def spifi_page_program(openocd: OpenOcdTclRpc, ByteAddress: int, data: List[int]
|
|||||||
(1 << SPIFI_CONFIG_CMD_DOUT_S) |
|
(1 << SPIFI_CONFIG_CMD_DOUT_S) |
|
||||||
(0 << SPIFI_CONFIG_CMD_POLL_S) |
|
(0 << SPIFI_CONFIG_CMD_POLL_S) |
|
||||||
(byte_count << SPIFI_CONFIG_CMD_DATALEN_S))
|
(byte_count << SPIFI_CONFIG_CMD_DATALEN_S))
|
||||||
for i in range(ByteAddress, ByteAddress + byte_count, 1):
|
for i in range(byte_count):
|
||||||
# openocd.write_word(SPIFI_CONFIG_DATA32, data[i+ByteAddress])
|
# openocd.write_word(SPIFI_CONFIG_DATA32, data[i+ByteAddress])
|
||||||
# print(data[i])
|
print(i)
|
||||||
|
print(data[i])
|
||||||
openocd.write_memory(SPIFI_CONFIG_DATA32, 8, [data[i]])
|
openocd.write_memory(SPIFI_CONFIG_DATA32, 8, [data[i]])
|
||||||
# spifi_intrq_clear(openocd)
|
# spifi_intrq_clear(openocd)
|
||||||
openocd.write_word(SPIFI_CONFIG_STAT, openocd.read_word(
|
openocd.write_word(SPIFI_CONFIG_STAT, openocd.read_word(
|
||||||
@ -461,3 +462,39 @@ def spifi_write_file(bytes: List[int], openocd: OpenOcdTclRpc, is_resume=True):
|
|||||||
openocd.resume(0)
|
openocd.resume(0)
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
def write_pages(pages: Dict[int, List[int]], openocd: OpenOcdTclRpc, is_resume=True):
|
||||||
|
"""
|
||||||
|
Write bytes in MIK32 External SPIFI Flash memory
|
||||||
|
|
||||||
|
@bytes: list of bytes to write at offset 0x0
|
||||||
|
|
||||||
|
TODO: implement setting byte array offset, add error handling,
|
||||||
|
improve progress visualisation
|
||||||
|
"""
|
||||||
|
result = 0
|
||||||
|
|
||||||
|
openocd.halt()
|
||||||
|
spifi_init(openocd)
|
||||||
|
spifi_erase(openocd)
|
||||||
|
address = 0
|
||||||
|
|
||||||
|
for page_offset in list(pages):
|
||||||
|
print("Writing page %s, " % hex(page_offset))
|
||||||
|
page_bytes = pages[page_offset]
|
||||||
|
|
||||||
|
spifi_write_enable(openocd)
|
||||||
|
spifi_page_program(openocd, page_offset, page_bytes, 256)
|
||||||
|
spifi_wait_busy(openocd)
|
||||||
|
|
||||||
|
# result = spifi_read_data(openocd, page_offset, 256, page_bytes)
|
||||||
|
|
||||||
|
if result == 1:
|
||||||
|
print("Page mismatch!")
|
||||||
|
return result
|
||||||
|
|
||||||
|
if is_resume:
|
||||||
|
openocd.resume(0)
|
||||||
|
|
||||||
|
return 0
|
||||||
|
|||||||
@ -163,7 +163,7 @@ def upload_file(filename: str, host: str = '127.0.0.1', port: int = OpenOcdTclRp
|
|||||||
# print(DEFAULT_OPENOCD_EXEC_FILE_PATH)
|
# print(DEFAULT_OPENOCD_EXEC_FILE_PATH)
|
||||||
# print(DEFAULT_OPENOCD_SCRIPTS_PATH)
|
# print(DEFAULT_OPENOCD_SCRIPTS_PATH)
|
||||||
|
|
||||||
result = 1
|
result = 0
|
||||||
|
|
||||||
if not os.path.exists(filename):
|
if not os.path.exists(filename):
|
||||||
print("ERROR: File %s does not exist" % filename)
|
print("ERROR: File %s does not exist" % filename)
|
||||||
@ -191,9 +191,14 @@ def upload_file(filename: str, host: str = '127.0.0.1', port: int = OpenOcdTclRp
|
|||||||
with OpenOcdTclRpc() as openocd:
|
with OpenOcdTclRpc() as openocd:
|
||||||
pages_eeprom = segments_to_pages(list(filter(
|
pages_eeprom = segments_to_pages(list(filter(
|
||||||
lambda segment: (segment.memory is not None) and (segment.memory.type == MemoryType.EEPROM), segments)), 128)
|
lambda segment: (segment.memory is not None) and (segment.memory.type == MemoryType.EEPROM), segments)), 128)
|
||||||
result = mik32_eeprom.write_pages(pages_eeprom, openocd, is_resume)
|
pages_spifi = segments_to_pages(list(filter(
|
||||||
# elif segment_section.type == MemoryType.SPIFI:
|
lambda segment: (segment.memory is not None) and (segment.memory.type == MemoryType.SPIFI), segments)), 256)
|
||||||
# result = mik32_spifi.spifi_write_file(segment.data, openocd, is_resume)
|
|
||||||
|
if (pages_eeprom.__len__() > 0):
|
||||||
|
result |= mik32_eeprom.write_pages(pages_eeprom, openocd, is_resume)
|
||||||
|
if (pages_spifi.__len__() > 0):
|
||||||
|
# print(pages_spifi)
|
||||||
|
result |= mik32_spifi.write_pages(pages_spifi, openocd, is_resume)
|
||||||
|
|
||||||
if run_openocd and proc is not None:
|
if run_openocd and proc is not None:
|
||||||
proc.kill()
|
proc.kill()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user