mirror of
https://github.com/MikronMIK32/mik32-uploader.git
synced 2026-01-01 21:37:05 +03:00
use python 3.8 typing syntax
This commit is contained in:
parent
0978eed36d
commit
02de7b066b
@ -1,4 +1,4 @@
|
|||||||
|
from typing import List
|
||||||
import time
|
import time
|
||||||
from .tclrpc import TclException
|
from .tclrpc import TclException
|
||||||
from .tclrpc import OpenOcdTclRpc
|
from .tclrpc import OpenOcdTclRpc
|
||||||
@ -139,7 +139,7 @@ def eeprom_write_word(openocd: OpenOcdTclRpc, address:int, word:int):
|
|||||||
openocd.write_word(EEPROM_REGS_EECON, (1 << EEPROM_EX_S) | (1 << EEPROM_BWE_S) | (EEPROM_OP_PR << EEPROM_OP_S))
|
openocd.write_word(EEPROM_REGS_EECON, (1 << EEPROM_EX_S) | (1 << EEPROM_BWE_S) | (EEPROM_OP_PR << EEPROM_OP_S))
|
||||||
time.sleep(0.001)
|
time.sleep(0.001)
|
||||||
|
|
||||||
def eeprom_write_page(openocd: OpenOcdTclRpc, address:int, data:list[int]):
|
def eeprom_write_page(openocd: OpenOcdTclRpc, address:int, data:List[int]):
|
||||||
openocd.write_word(EEPROM_REGS_EECON, 1 << EEPROM_BWE_S)
|
openocd.write_word(EEPROM_REGS_EECON, 1 << EEPROM_BWE_S)
|
||||||
openocd.write_word(EEPROM_REGS_EEA, address)
|
openocd.write_word(EEPROM_REGS_EEA, address)
|
||||||
page_address = address & EEPROM_PAGE_MASK
|
page_address = address & EEPROM_PAGE_MASK
|
||||||
@ -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))
|
openocd.write_word(EEPROM_REGS_EECON, (1 << EEPROM_EX_S) | (1 << EEPROM_BWE_S) | (EEPROM_OP_PR << EEPROM_OP_S))
|
||||||
time.sleep(0.001)
|
time.sleep(0.001)
|
||||||
|
|
||||||
def eeprom_check_data_apb(openocd: OpenOcdTclRpc, words: list[int]) -> int:
|
def eeprom_check_data_apb(openocd: OpenOcdTclRpc, words: List[int]) -> int:
|
||||||
print("EEPROM check through APB...")
|
print("EEPROM check through APB...")
|
||||||
openocd.write_word(EEPROM_REGS_EEA, 0x00000000)
|
openocd.write_word(EEPROM_REGS_EEA, 0x00000000)
|
||||||
word_num = 0
|
word_num = 0
|
||||||
@ -172,7 +172,7 @@ def eeprom_check_data_apb(openocd: OpenOcdTclRpc, words: list[int]) -> int:
|
|||||||
print("EEPROM check through APB done!")
|
print("EEPROM check through APB done!")
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def eeprom_check_data_ahb_lite(openocd: OpenOcdTclRpc, words: list[int]) -> int:
|
def eeprom_check_data_ahb_lite(openocd: OpenOcdTclRpc, words: List[int]) -> int:
|
||||||
print("EEPROM check through AHB-Lite...")
|
print("EEPROM check through AHB-Lite...")
|
||||||
mem_array = openocd.read_memory(0x01000000, 32, len(words))
|
mem_array = openocd.read_memory(0x01000000, 32, len(words))
|
||||||
if len(words) != len(mem_array):
|
if len(words) != len(mem_array):
|
||||||
@ -193,7 +193,7 @@ def eeprom_check_data_ahb_lite(openocd: OpenOcdTclRpc, words: list[int]) -> int:
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
def write_words(words: list[int], write_by_word = False, read_through_apb = False, is_resume=True) -> int:
|
def write_words(words: List[int], write_by_word = False, read_through_apb = False, is_resume=True) -> int:
|
||||||
"""
|
"""
|
||||||
Write words in MIK32 EEPROM through APB bus
|
Write words in MIK32 EEPROM through APB bus
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
|
from typing import List, Dict
|
||||||
|
|
||||||
def parse_hex(file: str) -> dict:
|
def parse_hex(file: str) -> Dict:
|
||||||
"""
|
"""
|
||||||
TODO: Implement support for more record types
|
TODO: Implement support for more record types
|
||||||
"""
|
"""
|
||||||
@ -30,7 +31,7 @@ def parse_hex(file: str) -> dict:
|
|||||||
reclen = int(line[1:3], base=16) # Record length
|
reclen = int(line[1:3], base=16) # Record length
|
||||||
load_offset = int(line[3:7], base=16) # Initial address of data byte
|
load_offset = int(line[3:7], base=16) # Initial address of data byte
|
||||||
rectype = int(line[7:9], base=16) # Record type
|
rectype = int(line[7:9], base=16) # Record type
|
||||||
data_bytes: list[str] = []
|
data_bytes: List[str] = []
|
||||||
|
|
||||||
data_bytes_line = line[9:reclen*2 + 9]
|
data_bytes_line = line[9:reclen*2 + 9]
|
||||||
for i in range(reclen):
|
for i in range(reclen):
|
||||||
@ -95,15 +96,15 @@ def parse_hex(file: str) -> dict:
|
|||||||
return memory_blocks
|
return memory_blocks
|
||||||
|
|
||||||
|
|
||||||
def parse_bin(filename: str) -> list[int]:
|
def parse_bin(filename: str) -> List[int]:
|
||||||
arr: list[int] = []
|
arr: List[int] = []
|
||||||
with open(filename, "rb") as f:
|
with open(filename, "rb") as f:
|
||||||
while byte := f.read(1):
|
while byte := f.read(1):
|
||||||
arr.append(byte[0])
|
arr.append(byte[0])
|
||||||
return arr
|
return arr
|
||||||
|
|
||||||
|
|
||||||
def bytes2words(arr: list[int]) -> list[int]:
|
def bytes2words(arr: List[int]) -> List[int]:
|
||||||
word = []
|
word = []
|
||||||
words = []
|
words = []
|
||||||
for byte in arr:
|
for byte in arr:
|
||||||
@ -113,8 +114,8 @@ def bytes2words(arr: list[int]) -> list[int]:
|
|||||||
word = []
|
word = []
|
||||||
return words
|
return words
|
||||||
|
|
||||||
def get_content(filename: str) -> list[int]:
|
def get_content(filename: str) -> List[int]:
|
||||||
content: list[int] = []
|
content: List[int] = []
|
||||||
|
|
||||||
if filename.endswith(".bin"):
|
if filename.endswith(".bin"):
|
||||||
content = parse_bin(filename)
|
content = parse_bin(filename)
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
from typing import List
|
||||||
import time
|
import time
|
||||||
from .tclrpc import TclException
|
from .tclrpc import TclException
|
||||||
from .tclrpc import OpenOcdTclRpc
|
from .tclrpc import OpenOcdTclRpc
|
||||||
@ -333,9 +334,9 @@ def spifi_chip_erase(openocd: OpenOcdTclRpc):
|
|||||||
spifi_wait_intrq_timeout(openocd, "Timeout executing chip erase command")
|
spifi_wait_intrq_timeout(openocd, "Timeout executing chip erase command")
|
||||||
|
|
||||||
|
|
||||||
def spifi_read_data(openocd: OpenOcdTclRpc, address: int, byte_count: int, bin_data: list[int]):
|
def spifi_read_data(openocd: OpenOcdTclRpc, address: int, byte_count: int, bin_data: List[int]):
|
||||||
print("read data")
|
print("read data")
|
||||||
read_data: list[int] = []
|
read_data: List[int] = []
|
||||||
openocd.write_word(SPIFI_CONFIG_ADDR, address)
|
openocd.write_word(SPIFI_CONFIG_ADDR, address)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@ -375,7 +376,7 @@ def spifi_read_data(openocd: OpenOcdTclRpc, address: int, byte_count: int, bin_d
|
|||||||
print(f"DATA[{i+address}] = {read_data[i]:#0x} - ошибка")
|
print(f"DATA[{i+address}] = {read_data[i]:#0x} - ошибка")
|
||||||
|
|
||||||
|
|
||||||
def spifi_page_program(openocd: OpenOcdTclRpc, ByteAddress: int, data: list[int], byte_count: int):
|
def spifi_page_program(openocd: OpenOcdTclRpc, ByteAddress: int, data: List[int], byte_count: int):
|
||||||
if byte_count > 256:
|
if byte_count > 256:
|
||||||
raise Exception("Byte count more than 256")
|
raise Exception("Byte count more than 256")
|
||||||
|
|
||||||
@ -409,7 +410,7 @@ def spifi_erase(openocd):
|
|||||||
spifi_wait_busy(openocd)
|
spifi_wait_busy(openocd)
|
||||||
|
|
||||||
|
|
||||||
def spifi_write(openocd: OpenOcdTclRpc, address: int, data: list[int], data_len: int):
|
def spifi_write(openocd: OpenOcdTclRpc, address: int, data: List[int], data_len: int):
|
||||||
if data_len > 256:
|
if data_len > 256:
|
||||||
raise Exception("Byte count more than 256")
|
raise Exception("Byte count more than 256")
|
||||||
|
|
||||||
@ -420,7 +421,7 @@ def spifi_write(openocd: OpenOcdTclRpc, address: int, data: list[int], data_len:
|
|||||||
print("written")
|
print("written")
|
||||||
|
|
||||||
|
|
||||||
def spifi_write_file(bytes: list[int], is_resume=True):
|
def spifi_write_file(bytes: List[int], is_resume=True):
|
||||||
"""
|
"""
|
||||||
Write bytes in MIK32 External SPIFI Flash memory
|
Write bytes in MIK32 External SPIFI Flash memory
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user