Skip to content

Commit

Permalink
tools/psoc6/mpy-psoc6.py: Added openocd fw-loader error handling.
Browse files Browse the repository at this point in the history
Signed-off-by: enriquezgarc <enriquezgarcia.external@infineon.com>
  • Loading branch information
jaenrig-ifx committed Nov 22, 2023
1 parent 0d1db1f commit 80f1a25
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions tools/psoc6/mpy-psoc6.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,17 +135,30 @@ def fwloader_setup():


def fwloader_update_kitprog():
def parse_output_for_error(fwloader_stdout):
fwloader_out_lines = fwloader_stdout.decode().split("\n")
print(fwloader_out_lines)
for line in fwloader_out_lines:
if "Error" in line:
raise Exception(colour_str_error(line))

print("Updating kitprog3 firmware...")
fwloader_cmd = "fw-loader --update-kp3 all"
print(fwloader_cmd)
fwloader_args = shlex.split(fwloader_cmd)

fwl_proc = subprocess.Popen(fwloader_args, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
try:
fwl_proc = subprocess.Popen(fwloader_args)
fwl_proc.wait()
out, err = fwl_proc.communicate(timeout=15)
except:
fwl_proc.kill()
raise Exception(colour_str_error("fwloader error"))

if err:
raise Exception(colour_str_error(err.decode()))

parse_output_for_error(out)

print(colour_str_success("Debugger kitprog3 firmware updated successfully"))


Expand Down Expand Up @@ -262,12 +275,16 @@ def openocd_program(board, hex_file, serial_adapter_sn=None):
)
openocd_args = shlex.split(openocd_cmd)

ocd_proc = subprocess.Popen(openocd_args, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
try:
ocd_proc = subprocess.Popen(openocd_args)
ocd_proc.wait()
out, err = ocd_proc.communicate(timeout=15)
except:
ocd_proc.kill()
raise Exception(colour_str_error("openocd error"))

if err:
raise Exception(colour_str_error(err.decode()))


def openocd_remove():
if opsys == "linux":
Expand Down

0 comments on commit 80f1a25

Please sign in to comment.