mirror of
https://github.com/MikronMIK32/mik32-uploader.git
synced 2026-01-01 13:37:03 +03:00
Поддержка частичного стирания EEPROM для прошивки с драйвером
This commit is contained in:
parent
0670b71ee7
commit
c9c2fd8fa5
@ -33,8 +33,9 @@ def combine_pages(pages: Dict[int, List[int]]) -> List[int]:
|
||||
class EEPROM():
|
||||
openocd: OpenOcdTclRpc
|
||||
|
||||
def __init__(self, openocd: OpenOcdTclRpc):
|
||||
def __init__(self, openocd: OpenOcdTclRpc, full_erase: bool = True):
|
||||
self.openocd = openocd
|
||||
self.full_erase = full_erase
|
||||
|
||||
self.eeprom_sysinit()
|
||||
|
||||
@ -195,7 +196,7 @@ class EEPROM():
|
||||
if self.eeprom_check_data_ahb_lite([0]*2048, 0, False):
|
||||
print("EEPROM global erase failed", flush=True)
|
||||
return 1
|
||||
|
||||
|
||||
# configure cycles duration
|
||||
self.eeprom_configure_cycles(1, 3, 1, 100000, 1000)
|
||||
time.sleep(0.1)
|
||||
@ -234,16 +235,32 @@ class EEPROM():
|
||||
RAM_BUFFER_OFFSET = 0x02001800
|
||||
RAM_DRIVER_STATUS = 0x02003800
|
||||
|
||||
STATUS_CODE_S = 0
|
||||
STATUS_CODE_M = 0x7F
|
||||
|
||||
STATUS_CODE_OK = 0
|
||||
STATUS_CODE_START = 1
|
||||
STATUS_CODE_MISMATCH = 2
|
||||
|
||||
STATUS_CODE_ERASE_S = 7
|
||||
STATUS_CODE_ERASE_M = (1 << STATUS_CODE_ERASE_S)
|
||||
STATUS_CODE_ERASE_FULL = 0
|
||||
STATUS_CODE_ERASE_USED = STATUS_CODE_ERASE_M
|
||||
|
||||
bytes_list = combine_pages(pages)
|
||||
self.openocd.halt()
|
||||
# Отключение прерываний
|
||||
self.openocd.run("riscv.cpu set_reg {mstatus 0 mie 0}")
|
||||
|
||||
STATUS_CODE_M = 0xFF
|
||||
|
||||
max_address = len(bytes_list) // 128
|
||||
self.openocd.write_memory(RAM_DRIVER_STATUS, 32, [
|
||||
1 | (max_address << 8)])
|
||||
(STATUS_CODE_START << STATUS_CODE_S) |
|
||||
(max_address << 8) |
|
||||
(
|
||||
STATUS_CODE_ERASE_FULL if self.full_erase
|
||||
else STATUS_CODE_ERASE_USED << STATUS_CODE_ERASE_S
|
||||
)
|
||||
])
|
||||
|
||||
pathname = os.path.dirname(sys.argv[0])
|
||||
|
||||
@ -281,7 +298,7 @@ class EEPROM():
|
||||
|
||||
result = self.openocd.read_memory(RAM_DRIVER_STATUS, 32, 1)[0]
|
||||
|
||||
if (result & STATUS_CODE_M) == 0:
|
||||
if (result & STATUS_CODE_M) == STATUS_CODE_OK:
|
||||
print(f"EEPROM writing successfully completed!", flush=True)
|
||||
else:
|
||||
miss_page = (result >> 8) & (64 - 1)
|
||||
|
||||
@ -195,6 +195,7 @@ def upload_file(
|
||||
post_action=default_post_action,
|
||||
mik_version=MIK32_Version.MIK32V2,
|
||||
use_driver=True,
|
||||
eeprom_full_erase=True,
|
||||
) -> int:
|
||||
"""
|
||||
Запись прошивки в формате Intel HEX или бинарном в память MIK32.
|
||||
@ -264,7 +265,7 @@ def upload_file(
|
||||
logging.debug("PM configured!")
|
||||
|
||||
if (pages.pages_eeprom.__len__() > 0):
|
||||
eeprom = EEPROM(openocd)
|
||||
eeprom = EEPROM(openocd, full_erase=eeprom_full_erase)
|
||||
|
||||
start_time = time.perf_counter()
|
||||
|
||||
@ -462,6 +463,13 @@ def createParser():
|
||||
default=True,
|
||||
help='Отключает прошивку с использованием драйвера в ОЗУ'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--eeprom-partial-erase',
|
||||
dest='eeprom_full_erase',
|
||||
action='store_false',
|
||||
default=True,
|
||||
help='Включает режим очистки EEPROM по страницам для режима с использованием драйвера в ОЗУ'
|
||||
)
|
||||
return parser
|
||||
|
||||
|
||||
@ -492,6 +500,7 @@ if __name__ == '__main__':
|
||||
post_action=namespace.post_action,
|
||||
mik_version=namespace.mcu_type,
|
||||
use_driver=namespace.use_driver,
|
||||
eeprom_full_erase=namespace.eeprom_full_erase,
|
||||
)
|
||||
)
|
||||
else:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user