mirror of
https://github.com/MikronMIK32/mik32-uploader.git
synced 2026-01-01 13:37:03 +03:00
fix circular dependency, add ram upload
This commit is contained in:
parent
e6c8d763b9
commit
583249b2c2
@ -1,7 +1,7 @@
|
|||||||
from typing import Dict, List
|
from typing import Dict, List
|
||||||
import time
|
import time
|
||||||
from tclrpc import OpenOcdTclRpc
|
from tclrpc import OpenOcdTclRpc
|
||||||
from mik32_upload import Segment, MemorySection, bytes2words
|
from utils import bytes2words
|
||||||
|
|
||||||
# --------------------------
|
# --------------------------
|
||||||
# PM register offset
|
# PM register offset
|
||||||
|
|||||||
14
mik32_ram.py
14
mik32_ram.py
@ -1,7 +1,11 @@
|
|||||||
|
from typing import List
|
||||||
|
from mik32_upload import Segment
|
||||||
from tclrpc import TclException
|
from tclrpc import TclException
|
||||||
from tclrpc import OpenOcdTclRpc
|
from tclrpc import OpenOcdTclRpc
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
from utils import bytes2words
|
||||||
|
|
||||||
def write_file(filename, is_resume=True):
|
def write_file(filename, is_resume=True):
|
||||||
|
|
||||||
with OpenOcdTclRpc() as openocd:
|
with OpenOcdTclRpc() as openocd:
|
||||||
@ -10,3 +14,13 @@ def write_file(filename, is_resume=True):
|
|||||||
if is_resume:
|
if is_resume:
|
||||||
openocd.resume(0)
|
openocd.resume(0)
|
||||||
print("RAM write file maybe done")
|
print("RAM write file maybe done")
|
||||||
|
|
||||||
|
|
||||||
|
def write_segments(segments: List[Segment], openocd: OpenOcdTclRpc, is_resume=True):
|
||||||
|
openocd.reset_halt()
|
||||||
|
for segment in segments:
|
||||||
|
print("Writing segment %s with size %d..." % (hex(segment.offset), segment.data.__len__()))
|
||||||
|
segment_words = bytes2words(segment.data)
|
||||||
|
openocd.write_memory(segment.offset, 32, segment_words)
|
||||||
|
if is_resume:
|
||||||
|
openocd.resume(0)
|
||||||
|
|||||||
@ -193,12 +193,17 @@ def upload_file(filename: str, host: str = '127.0.0.1', port: int = OpenOcdTclRp
|
|||||||
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)
|
||||||
pages_spifi = segments_to_pages(list(filter(
|
pages_spifi = segments_to_pages(list(filter(
|
||||||
lambda segment: (segment.memory is not None) and (segment.memory.type == MemoryType.SPIFI), segments)), 256)
|
lambda segment: (segment.memory is not None) and (segment.memory.type == MemoryType.SPIFI), segments)), 256)
|
||||||
|
segments_ram = list(filter(
|
||||||
|
lambda segment: (segment.memory is not None) and (segment.memory.type == MemoryType.RAM), segments))
|
||||||
|
|
||||||
if (pages_eeprom.__len__() > 0):
|
if (pages_eeprom.__len__() > 0):
|
||||||
result |= mik32_eeprom.write_pages(pages_eeprom, openocd, is_resume)
|
result |= mik32_eeprom.write_pages(pages_eeprom, openocd, is_resume)
|
||||||
if (pages_spifi.__len__() > 0):
|
if (pages_spifi.__len__() > 0):
|
||||||
# print(pages_spifi)
|
# print(pages_spifi)
|
||||||
result |= mik32_spifi.write_pages(pages_spifi, openocd, is_resume, use_quad_spi)
|
result |= mik32_spifi.write_pages(pages_spifi, openocd, is_resume, use_quad_spi)
|
||||||
|
if (segments_ram.__len__() > 0):
|
||||||
|
mik32_ram.write_segments(segments_ram, openocd, is_resume)
|
||||||
|
result |= 0
|
||||||
|
|
||||||
if run_openocd and proc is not None:
|
if run_openocd and proc is not None:
|
||||||
proc.kill()
|
proc.kill()
|
||||||
@ -206,19 +211,6 @@ def upload_file(filename: str, host: str = '127.0.0.1', port: int = OpenOcdTclRp
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def bytes2words(arr: List[int]) -> List[int]:
|
|
||||||
bytes = []
|
|
||||||
words = []
|
|
||||||
for byte in arr:
|
|
||||||
bytes.append(byte)
|
|
||||||
if bytes.__len__() == 4:
|
|
||||||
words.append(bytes[0]+2**8*bytes[1]+2**16*bytes[2]+2**24*bytes[3])
|
|
||||||
bytes = []
|
|
||||||
if bytes.__len__() != 0:
|
|
||||||
print("WARNING: skipping not-word-aligned byte")
|
|
||||||
return words
|
|
||||||
|
|
||||||
|
|
||||||
def createParser():
|
def createParser():
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('filepath', nargs='?')
|
parser.add_argument('filepath', nargs='?')
|
||||||
|
|||||||
14
utils.py
Normal file
14
utils.py
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
from typing import List
|
||||||
|
|
||||||
|
|
||||||
|
def bytes2words(arr: List[int]) -> List[int]:
|
||||||
|
bytes = []
|
||||||
|
words = []
|
||||||
|
for byte in arr:
|
||||||
|
bytes.append(byte)
|
||||||
|
if bytes.__len__() == 4:
|
||||||
|
words.append(bytes[0]+2**8*bytes[1]+2**16*bytes[2]+2**24*bytes[3])
|
||||||
|
bytes = []
|
||||||
|
if bytes.__len__() != 0:
|
||||||
|
print("WARNING: skipping not-word-aligned byte")
|
||||||
|
return words
|
||||||
Loading…
Reference in New Issue
Block a user