catch openocd connection and tcl exceptions

This commit is contained in:
Sergey Shchelkanov 2023-06-23 17:19:36 +03:00
parent 754d47e201
commit 9d52559b5f

View File

@ -4,7 +4,7 @@ import subprocess
import os import os
from enum import Enum from enum import Enum
from typing import List, Dict, NamedTuple, Union from typing import List, Dict, NamedTuple, Union
from tclrpc import OpenOcdTclRpc from tclrpc import OpenOcdTclRpc, TclException
import mik32_eeprom import mik32_eeprom
import mik32_spifi import mik32_spifi
import mik32_ram import mik32_ram
@ -157,7 +157,7 @@ class FirmwareFile:
elif record.type == RecordType.EXTADDR: elif record.type == RecordType.EXTADDR:
lba = record.address lba = record.address
elif record.type == RecordType.LINEARSTARTADDR: elif record.type == RecordType.LINEARSTARTADDR:
print("Start Linear Address:", record.address) print(f"Start Linear Address: {record.address:#10x}", )
elif record.type == RecordType.EOF: elif record.type == RecordType.EOF:
break break
@ -288,7 +288,7 @@ def upload_file(
if is_run_openocd: if is_run_openocd:
proc = run_openocd(openocd_exec, openocd_scripts, proc = run_openocd(openocd_exec, openocd_scripts,
openocd_interface, openocd_target, is_open_console) openocd_interface, openocd_target, is_open_console)
try:
with OpenOcdTclRpc(host, port) as openocd: with OpenOcdTclRpc(host, port) as openocd:
openocd.run(f"adapter speed {adapter_speed}") openocd.run(f"adapter speed {adapter_speed}")
openocd.run(f"log_output \"{log_path}\"") openocd.run(f"log_output \"{log_path}\"")
@ -308,6 +308,11 @@ def upload_file(
result |= 0 result |= 0
openocd.run(post_action) openocd.run(post_action)
except ConnectionRefusedError:
print("ERROR: The connection to OpenOCD is not established. Check the settings and connection of the debugger")
except TclException as e:
print(f"ERROR: TclException {e.code} \n {e.msg}")
if proc is not None: if proc is not None:
proc.kill() proc.kill()
@ -344,6 +349,8 @@ def createParser():
default=default_log_path) default=default_log_path)
parser.add_argument('--post-action', dest='post_action', parser.add_argument('--post-action', dest='post_action',
default=default_post_action) default=default_post_action)
parser.add_argument('--no-color', dest='no_color',
action='store_true', default=False)
return parser return parser