mirror of
https://github.com/MikronMIK32/mik32-uploader.git
synced 2026-01-01 21:37:05 +03:00
Merge branch 'master' into dev
This commit is contained in:
commit
d6dd2f51aa
@ -264,6 +264,7 @@ class DMA:
|
|||||||
self.current_value = CurrentValue.ENABLE
|
self.current_value = CurrentValue.ENABLE
|
||||||
|
|
||||||
self.write_buffer = 0
|
self.write_buffer = 0
|
||||||
|
self.openocd.write_memory(0x40000, 32, [0] * 16)
|
||||||
self.clear_irq()
|
self.clear_irq()
|
||||||
self.set_current_value(self.current_value)
|
self.set_current_value(self.current_value)
|
||||||
|
|
||||||
|
|||||||
@ -140,7 +140,6 @@ SPIFI_CONFIG_STAT_VERSION_M = (0xFF << SPIFI_CONFIG_STAT_VERSION_S)
|
|||||||
# --------------------------
|
# --------------------------
|
||||||
SREG1_BUSY = 1
|
SREG1_BUSY = 1
|
||||||
|
|
||||||
READ_SREG_LEN = 1
|
|
||||||
READ_LEN = 256
|
READ_LEN = 256
|
||||||
TIMEOUT = 1000
|
TIMEOUT = 1000
|
||||||
|
|
||||||
@ -158,11 +157,8 @@ READ_DATA_COMMAND = 0x03
|
|||||||
FAST_READ_QUAD_OUTPUT_COMMAND = 0x6B
|
FAST_READ_QUAD_OUTPUT_COMMAND = 0x6B
|
||||||
|
|
||||||
READ_SREG1_COMMAND = 0x05
|
READ_SREG1_COMMAND = 0x05
|
||||||
WRITE_SREG1_COMMAND = 0x01
|
|
||||||
READ_SREG2_COMMAND = 0x35
|
READ_SREG2_COMMAND = 0x35
|
||||||
WRITE_SREG2_COMMAND = 0x31
|
WRITE_SREG_COMMAND = 0x01
|
||||||
READ_SREG3_COMMAND = 0x15
|
|
||||||
WRITE_SREG3_COMMAND = 0x11
|
|
||||||
|
|
||||||
SREG2_QUAD_ENABLE = 9
|
SREG2_QUAD_ENABLE = 9
|
||||||
SREG2_QUAD_ENABLE_S = (SREG2_QUAD_ENABLE-8)
|
SREG2_QUAD_ENABLE_S = (SREG2_QUAD_ENABLE-8)
|
||||||
@ -176,7 +172,6 @@ QUAD_PAGE_PROGRAM_COMMAND = 0x32
|
|||||||
class SREG_Num(Enum):
|
class SREG_Num(Enum):
|
||||||
SREG1 = 0x00
|
SREG1 = 0x00
|
||||||
SREG2 = 0x30
|
SREG2 = 0x30
|
||||||
SREG3 = 0x10
|
|
||||||
|
|
||||||
|
|
||||||
def spifi_intrq_clear(openocd: OpenOcdTclRpc):
|
def spifi_intrq_clear(openocd: OpenOcdTclRpc):
|
||||||
@ -349,14 +344,31 @@ def spifi_write_enable(openocd: OpenOcdTclRpc):
|
|||||||
|
|
||||||
|
|
||||||
def spifi_read_sreg(openocd: OpenOcdTclRpc, sreg: SREG_Num) -> int:
|
def spifi_read_sreg(openocd: OpenOcdTclRpc, sreg: SREG_Num) -> int:
|
||||||
read_sreg: int = 0
|
|
||||||
|
|
||||||
return spifi_send_command(
|
return spifi_send_command(
|
||||||
openocd, READ_SREG1_COMMAND | sreg.value, SPIFI_Frameform.OPCODE_NOADDR,
|
openocd,
|
||||||
SPIFI_Fieldform.ALL_SERIAL, byte_count=READ_SREG_LEN
|
READ_SREG1_COMMAND | sreg.value,
|
||||||
|
SPIFI_Frameform.OPCODE_NOADDR,
|
||||||
|
SPIFI_Fieldform.ALL_SERIAL,
|
||||||
|
byte_count=1
|
||||||
)[0]
|
)[0]
|
||||||
|
|
||||||
|
|
||||||
|
def spifi_write_sreg(openocd: OpenOcdTclRpc, sreg1: int, sreg2: int):
|
||||||
|
spifi_send_command(openocd, 0xFF,
|
||||||
|
SPIFI_Frameform.OPCODE_NOADDR, SPIFI_Fieldform.ALL_PARALLEL)
|
||||||
|
spifi_write_enable(openocd)
|
||||||
|
spifi_send_command(
|
||||||
|
openocd,
|
||||||
|
WRITE_SREG_COMMAND,
|
||||||
|
SPIFI_Frameform.OPCODE_NOADDR,
|
||||||
|
SPIFI_Fieldform.ALL_SERIAL,
|
||||||
|
byte_count=2,
|
||||||
|
direction=SPIFI_Direction.WRITE,
|
||||||
|
data=[sreg1, sreg2]
|
||||||
|
)
|
||||||
|
spifi_wait_busy(openocd)
|
||||||
|
|
||||||
|
|
||||||
def spifi_wait_busy(openocd: OpenOcdTclRpc):
|
def spifi_wait_busy(openocd: OpenOcdTclRpc):
|
||||||
while 1:
|
while 1:
|
||||||
sreg1 = spifi_read_sreg(openocd, SREG_Num.SREG1)
|
sreg1 = spifi_read_sreg(openocd, SREG_Num.SREG1)
|
||||||
@ -491,24 +503,23 @@ def spifi_quad_page_program(
|
|||||||
|
|
||||||
|
|
||||||
def spifi_quad_enable(openocd):
|
def spifi_quad_enable(openocd):
|
||||||
sreg2 = spifi_read_sreg(openocd, SREG_Num.SREG2)
|
spifi_write_sreg(
|
||||||
|
openocd,
|
||||||
spifi_write_enable(openocd)
|
spifi_read_sreg(openocd, SREG_Num.SREG1),
|
||||||
spifi_send_command(openocd, WRITE_SREG2_COMMAND, SPIFI_Frameform.OPCODE_3ADDR,
|
spifi_read_sreg(openocd, SREG_Num.SREG2) | SREG2_QUAD_ENABLE_M
|
||||||
SPIFI_Fieldform.ALL_SERIAL, byte_count=1,
|
)
|
||||||
idata=0, cache_limit=0, direction=SPIFI_Direction.WRITE, data=[sreg2 | SREG2_QUAD_ENABLE_M])
|
|
||||||
spifi_wait_busy(openocd)
|
|
||||||
|
|
||||||
|
|
||||||
def spifi_quad_disable(openocd):
|
def spifi_quad_disable(openocd):
|
||||||
sreg2 = spifi_read_sreg(openocd, SREG_Num.SREG2)
|
spifi_write_sreg(
|
||||||
|
openocd,
|
||||||
|
spifi_read_sreg(openocd, SREG_Num.SREG1),
|
||||||
|
spifi_read_sreg(openocd, SREG_Num.SREG2) & (0xFF ^ SREG2_QUAD_ENABLE_M)
|
||||||
|
)
|
||||||
|
|
||||||
spifi_write_enable(openocd)
|
|
||||||
spifi_send_command(openocd, WRITE_SREG2_COMMAND, SPIFI_Frameform.OPCODE_3ADDR,
|
def spifi_check_quad_enable(openocd):
|
||||||
SPIFI_Fieldform.ALL_SERIAL, byte_count=1,
|
return (spifi_read_sreg(openocd, SREG_Num.SREG2) & SREG2_QUAD_ENABLE_M) != 0
|
||||||
idata=0, cache_limit=0, direction=SPIFI_Direction.WRITE, data=[
|
|
||||||
sreg2 & (~SREG2_QUAD_ENABLE_M)])
|
|
||||||
spifi_wait_busy(openocd)
|
|
||||||
|
|
||||||
|
|
||||||
def get_segments_list(pages_offsets: List[int], segment_size: int) -> List[int]:
|
def get_segments_list(pages_offsets: List[int], segment_size: int) -> List[int]:
|
||||||
@ -666,12 +677,18 @@ def write_pages(pages: Dict[int, List[int]], openocd: OpenOcdTclRpc, use_quad_sp
|
|||||||
# print("Data error")
|
# print("Data error")
|
||||||
# return result
|
# return result
|
||||||
|
|
||||||
|
print("Quad Enable", spifi_check_quad_enable(openocd))
|
||||||
|
|
||||||
if (use_quad_spi):
|
if (use_quad_spi):
|
||||||
print("Quad Enable")
|
print("Using Quad SPI")
|
||||||
spifi_quad_enable(openocd)
|
spifi_quad_enable(openocd)
|
||||||
else:
|
else:
|
||||||
|
print("Using Single SPI")
|
||||||
spifi_quad_disable(openocd)
|
spifi_quad_disable(openocd)
|
||||||
|
|
||||||
|
# print("SREG1", spifi_read_sreg(openocd, SREG_Num.SREG1))
|
||||||
|
# print("SREG2", spifi_read_sreg(openocd, SREG_Num.SREG2))
|
||||||
|
|
||||||
pages_offsets = list(pages)
|
pages_offsets = list(pages)
|
||||||
|
|
||||||
for index, page_offset in enumerate(pages_offsets):
|
for index, page_offset in enumerate(pages_offsets):
|
||||||
|
|||||||
@ -26,9 +26,13 @@ import sys
|
|||||||
# BOLD = '\033[1m'
|
# BOLD = '\033[1m'
|
||||||
# UNDERLINE = '\033[4m'
|
# UNDERLINE = '\033[4m'
|
||||||
|
|
||||||
|
if os.name == 'nt':
|
||||||
|
openocd_exec = "openocd.exe"
|
||||||
|
else:
|
||||||
|
openocd_exec = "openocd"
|
||||||
|
|
||||||
default_openocd_host = '127.0.0.1'
|
default_openocd_host = '127.0.0.1'
|
||||||
openocd_exec_path = os.path.join("openocd", "bin", "openocd.exe")
|
openocd_exec_path = os.path.join("openocd", "bin", openocd_exec)
|
||||||
openocd_scripts_path = os.path.join("openocd", "share", "openocd", "scripts")
|
openocd_scripts_path = os.path.join("openocd", "share", "openocd", "scripts")
|
||||||
openocd_interface_path = os.path.join("interface", "ftdi", "m-link.cfg")
|
openocd_interface_path = os.path.join("interface", "ftdi", "m-link.cfg")
|
||||||
openocd_target_path = os.path.join("target", "mik32.cfg")
|
openocd_target_path = os.path.join("target", "mik32.cfg")
|
||||||
@ -129,12 +133,15 @@ def run_openocd(
|
|||||||
cmd = [openocd_exec, "-s", openocd_scripts,
|
cmd = [openocd_exec, "-s", openocd_scripts,
|
||||||
"-f", openocd_interface, "-f", openocd_target]
|
"-f", openocd_interface, "-f", openocd_target]
|
||||||
|
|
||||||
creation_flags = subprocess.SW_HIDE
|
if os.name == 'nt':
|
||||||
if is_open_console:
|
creation_flags = subprocess.SW_HIDE
|
||||||
creation_flags |= subprocess.CREATE_NEW_CONSOLE
|
if is_open_console:
|
||||||
|
creation_flags |= subprocess.CREATE_NEW_CONSOLE
|
||||||
|
|
||||||
proc = subprocess.Popen(
|
proc = subprocess.Popen(
|
||||||
cmd, creationflags=creation_flags)
|
cmd, creationflags=creation_flags)
|
||||||
|
else:
|
||||||
|
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)
|
||||||
|
|
||||||
return proc
|
return proc
|
||||||
|
|
||||||
@ -228,6 +235,7 @@ def upload_file(
|
|||||||
except OSError as e:
|
except OSError as e:
|
||||||
raise OpenOCDStartupException(e)
|
raise OpenOCDStartupException(e)
|
||||||
try:
|
try:
|
||||||
|
time.sleep(0.1)
|
||||||
with OpenOcdTclRpc(host, port) as openocd:
|
with OpenOcdTclRpc(host, port) as openocd:
|
||||||
if (all(openocd_interface.find(i) == -1 for i in adapter_speed_not_supported)):
|
if (all(openocd_interface.find(i) == -1 for i in adapter_speed_not_supported)):
|
||||||
openocd.run(f"adapter speed {adapter_speed}")
|
openocd.run(f"adapter speed {adapter_speed}")
|
||||||
|
|||||||
16
tclrpc.py
16
tclrpc.py
@ -1,6 +1,7 @@
|
|||||||
import re
|
import re
|
||||||
import socket
|
import socket
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
|
import time
|
||||||
from typing import List
|
from typing import List
|
||||||
logger = getLogger(__name__)
|
logger = getLogger(__name__)
|
||||||
|
|
||||||
@ -52,9 +53,8 @@ class OpenOcdTclRpc:
|
|||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
self.sock.settimeout(5.0)
|
|
||||||
try:
|
try:
|
||||||
self.sock.connect((self.host, self.port))
|
self.wait_for_port()
|
||||||
except socket.timeout:
|
except socket.timeout:
|
||||||
logger.debug("Test connection timed out, try again")
|
logger.debug("Test connection timed out, try again")
|
||||||
self.sock.close()
|
self.sock.close()
|
||||||
@ -88,6 +88,18 @@ class OpenOcdTclRpc:
|
|||||||
raise Exception('Unhandled extra bytes after %r'.format(self.SEPARATOR_BYTES))
|
raise Exception('Unhandled extra bytes after %r'.format(self.SEPARATOR_BYTES))
|
||||||
return data[:-1]
|
return data[:-1]
|
||||||
|
|
||||||
|
def wait_for_port(self, timeout: float = 5.0):
|
||||||
|
sock = None
|
||||||
|
start_time = time.perf_counter()
|
||||||
|
while time.perf_counter() - start_time < timeout:
|
||||||
|
try:
|
||||||
|
sock = self.sock.connect((self.host, self.port))
|
||||||
|
break
|
||||||
|
except OSError as ex:
|
||||||
|
time.sleep(0.01)
|
||||||
|
if sock != None:
|
||||||
|
self.sock = sock
|
||||||
|
|
||||||
def run(self, cmd):
|
def run(self, cmd):
|
||||||
"""Run a command and raise an error if it returns an error"""
|
"""Run a command and raise an error if it returns an error"""
|
||||||
wrap = 'set _code [catch {%s} _msg];expr {"$_code $_msg"}' % tcl_quote_cmd(cmd)
|
wrap = 'set _code [catch {%s} _msg];expr {"$_code $_msg"}' % tcl_quote_cmd(cmd)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user