implement simple error return

This commit is contained in:
Sergey Shchelkanov 2023-04-07 12:35:14 +03:00
parent 0399d3110c
commit 834952254b
3 changed files with 20 additions and 10 deletions

View File

@ -152,7 +152,7 @@ def eeprom_write_page(openocd: OpenOcdTclRpc, address:int, data:list[int]):
openocd.write_word(EEPROM_REGS_EECON, (1 << EEPROM_EX_S) | (1 << EEPROM_BWE_S) | (EEPROM_OP_PR << EEPROM_OP_S))
time.sleep(0.001)
def eeprom_check_data_apb(openocd: OpenOcdTclRpc, words: list[int]):
def eeprom_check_data_apb(openocd: OpenOcdTclRpc, words: list[int]) -> int:
print("EEPROM check through APB...")
openocd.write_word(EEPROM_REGS_EEA, 0x00000000)
word_num = 0
@ -162,6 +162,7 @@ def eeprom_check_data_apb(openocd: OpenOcdTclRpc, words: list[int]):
value:int = openocd.read_word(EEPROM_REGS_EEDAT)
if words[word_num] != value:
print(f"Unexpect value at {word_num} word, expect {word:#0x}, get {value:#0x}")
return 1
word_num += 1
curr_progress = int((word_num * 50) / len(words))
if curr_progress > progress:
@ -169,8 +170,9 @@ def eeprom_check_data_apb(openocd: OpenOcdTclRpc, words: list[int]):
progress = curr_progress
print("]")
print("EEPROM check through APB done!")
return 0
def eeprom_check_data_ahb_lite(openocd: OpenOcdTclRpc, words: list[int]):
def eeprom_check_data_ahb_lite(openocd: OpenOcdTclRpc, words: list[int]) -> int:
print("EEPROM check through AHB-Lite...")
mem_array = openocd.read_memory(0x01000000, 32, len(words))
if len(words) != len(mem_array):
@ -181,15 +183,17 @@ def eeprom_check_data_ahb_lite(openocd: OpenOcdTclRpc, words: list[int]):
if words[word_num] != mem_array[word_num]:
print(f"Unexpect value at {word_num} word, expect {words[word_num]:#0x}, \
get {mem_array[word_num]:#0x}")
return 1
curr_progress = int((word_num * 50) / len(words))
if curr_progress > progress:
print("#"*(curr_progress - progress), end="", flush=True)
progress = curr_progress
print("]")
print("EEPROM check through APB done!")
return 0
def write_words(words: list[int], write_by_word = False, read_through_apb = False):
def write_words(words: list[int], write_by_word = False, read_through_apb = False) -> int:
"""
Write words in MIK32 EEPROM through APB bus
@ -242,8 +246,10 @@ def write_words(words: list[int], write_by_word = False, read_through_apb = Fals
eeprom_write_page(openocd, page_num*page_size*4, page)
print("]")
if read_through_apb:
eeprom_check_data_apb(openocd, words)
result = eeprom_check_data_apb(openocd, words)
else:
eeprom_check_data_ahb_lite(openocd, words)
result = eeprom_check_data_ahb_lite(openocd, words)
openocd.resume(0)
if result == 0:
print("EEPROM write file done!")
return result

View File

@ -396,7 +396,7 @@ def spifi_page_program(openocd: OpenOcdTclRpc, ByteAddress: int, data: list[int]
(byte_count << SPIFI_CONFIG_CMD_DATALEN_S))
for i in range(ByteAddress, ByteAddress + byte_count, 1):
# openocd.write_word(SPIFI_CONFIG_DATA32, data[i+ByteAddress])
print(data[i])
# print(data[i])
openocd.write_memory(SPIFI_CONFIG_DATA32, 8, [data[i]])
# spifi_intrq_clear(openocd)
openocd.write_word(SPIFI_CONFIG_STAT, openocd.read_word(

View File

@ -32,7 +32,7 @@ def test_connection():
raise Exception("ERROR: no regs found, check MCU connection")
def upload_file(filename: str, boot_source: str = "eeprom"):
def upload_file(filename: str, boot_source: str = "eeprom") -> int:
"""
Write ihex or binary file into MIK32 EEPROM or external flash memory
@ -53,17 +53,21 @@ def upload_file(filename: str, boot_source: str = "eeprom"):
print("ERROR: File %s does not exist" % filename)
exit(1)
cmd = shlex.split("%s -s %s -f interface/ftdi/m-link.cfg -f target/mcu32.cfg" % (DEFAULT_OPENOCD_EXEC_FILE_PATH, DEFAULT_OPENOCD_SCRIPTS_PATH), posix=0)
cmd = shlex.split("%s -s %s -f interface/ftdi/m-link.cfg -f target/mcu32.cfg" % (DEFAULT_OPENOCD_EXEC_FILE_PATH, DEFAULT_OPENOCD_SCRIPTS_PATH), posix=False)
with subprocess.Popen(cmd, shell=True, stdout=subprocess.DEVNULL) as proc:
if boot_source == "eeprom":
mik32_eeprom.write_words(bytes2words(get_content(filename)))
result = mik32_eeprom.write_words(bytes2words(get_content(filename)))
elif boot_source == "spifi":
mik32_spifi.spifi_write_file(get_content(filename))
result = 0 # TODO
elif boot_source == "ram":
mik32_ram.write_file(filename)
result = 0 # TODO
else:
raise Exception("Unsupported boot source, use eeprom or spifi")
result = 1
proc.kill()
return result