mirror of
https://github.com/MikronMIK32/mik32-uploader.git
synced 2026-01-01 13:37:03 +03:00
add more console info and checking erase
This commit is contained in:
parent
9c184971ca
commit
9f9c6f2a3c
@ -307,6 +307,32 @@ def spifi_sector_erase(openocd: OpenOcdTclRpc, address: int):
|
||||
spifi_wait_intrq_timeout(openocd, "Timeout executing chip erase command")
|
||||
|
||||
|
||||
def spifi_check_erase(openocd: OpenOcdTclRpc, address: int, byte_count: int):
|
||||
print(f"Checking erase from {address:#0x} to {(byte_count-1):#0x}")
|
||||
|
||||
read_data: List[int] = []
|
||||
openocd.write_word(SPIFI_CONFIG_ADDR, address)
|
||||
|
||||
spifi_intrq_clear(openocd)
|
||||
openocd.write_word(SPIFI_CONFIG_CMD, (READ_DATA_COMMAND << SPIFI_CONFIG_CMD_OPCODE_S) |
|
||||
(SPIFI_CONFIG_CMD_FRAMEFORM_OPCODE_3ADDR << SPIFI_CONFIG_CMD_FRAMEFORM_S) |
|
||||
(SPIFI_CONFIG_CMD_FIELDFORM_ALL_SERIAL << SPIFI_CONFIG_CMD_FIELDFORM_S) |
|
||||
(byte_count << SPIFI_CONFIG_CMD_DATALEN_S))
|
||||
# spifi_wait_intrq_timeout(openocd, "Timeout executing read data command")
|
||||
for i in range(byte_count):
|
||||
data8 = openocd.read_memory(SPIFI_CONFIG_DATA32, 8, 1)[0]
|
||||
read_data.append(data8)
|
||||
if config.is_verbose:
|
||||
print(f"DATA[{i+address}] = {read_data[i]:#0x}")
|
||||
|
||||
for i in range(byte_count):
|
||||
if read_data[i] != 0:
|
||||
print(f"DATA[{(i+address):#0x}] = {read_data[i]:#0x}, expected {0:#0x}")
|
||||
return 1
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
def spifi_read_data(openocd: OpenOcdTclRpc, address: int, byte_count: int, bin_data: List[int]) -> int:
|
||||
read_data: List[int] = []
|
||||
openocd.write_word(SPIFI_CONFIG_ADDR, address)
|
||||
@ -326,7 +352,7 @@ 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[i]:
|
||||
print(f"DATA[{(i+address):#0x}] = {read_data[i]:#0x}, expected {bin_data[i]:#0x}")
|
||||
# return 1
|
||||
return 1
|
||||
|
||||
return 0
|
||||
|
||||
@ -335,6 +361,7 @@ def spifi_page_program(openocd: OpenOcdTclRpc, ByteAddress: int, data: List[int]
|
||||
if byte_count > 256:
|
||||
raise Exception("Byte count more than 256")
|
||||
|
||||
print("Writing page %s..." % hex(ByteAddress))
|
||||
# spifi_intrq_clear(openocd)
|
||||
openocd.write_word(SPIFI_CONFIG_STAT, openocd.read_word(
|
||||
SPIFI_CONFIG_STAT) | SPIFI_CONFIG_STAT_INTRQ_M)
|
||||
@ -366,11 +393,13 @@ def spifi_erase(openocd, erase_type: EraseType = EraseType.CHIP_ERASE, sectors:
|
||||
spifi_write_enable(openocd)
|
||||
spifi_chip_erase(openocd)
|
||||
spifi_wait_busy(openocd)
|
||||
spifi_check_erase(openocd, 0, 65536)
|
||||
elif erase_type == EraseType.SECTOR_ERASE:
|
||||
for sector in sectors:
|
||||
spifi_write_enable(openocd)
|
||||
spifi_sector_erase(openocd, sector)
|
||||
spifi_wait_busy(openocd)
|
||||
spifi_check_erase(openocd, 0, 4096)
|
||||
|
||||
|
||||
def spifi_write(openocd: OpenOcdTclRpc, address: int, data: List[int], data_len: int):
|
||||
@ -419,6 +448,7 @@ def spifi_quad_page_program(openocd: OpenOcdTclRpc, ByteAddress: int, data: List
|
||||
if byte_count > 256:
|
||||
raise Exception("Byte count more than 256")
|
||||
|
||||
print("Writing page %s..." % hex(ByteAddress))
|
||||
# spifi_intrq_clear(openocd)
|
||||
openocd.write_word(SPIFI_CONFIG_STAT, openocd.read_word(
|
||||
SPIFI_CONFIG_STAT) | SPIFI_CONFIG_STAT_INTRQ_M)
|
||||
@ -494,7 +524,6 @@ def write_pages(pages: Dict[int, List[int]], openocd: OpenOcdTclRpc, is_resume=T
|
||||
spifi_quad_enable(openocd)
|
||||
|
||||
for page_offset in list(pages):
|
||||
print("Writing page %s..." % hex(page_offset))
|
||||
page_bytes = pages[page_offset]
|
||||
|
||||
spifi_write_enable(openocd)
|
||||
|
||||
@ -200,7 +200,7 @@ def upload_file(
|
||||
openocd_path, scripts_path), posix=False)
|
||||
print(cmd)
|
||||
proc = subprocess.Popen(
|
||||
cmd)
|
||||
cmd, creationflags=subprocess.CREATE_NEW_CONSOLE | subprocess.SW_HIDE)
|
||||
|
||||
with OpenOcdTclRpc() as openocd:
|
||||
pages_eeprom = segments_to_pages(list(filter(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user