zephyr/scripts/west_commands/runners/probe_rs.py
Pieter De Gendt bf7f41d880 scripts: west_commands: runners: Sort and format imports (I001)
Apply sorting and formatting rules on imports.

See
https://docs.astral.sh/ruff/rules/unsorted-imports/

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2024-11-22 17:40:37 +01:00

82 lines
2.4 KiB
Python

# Copyright (c) 2024 Chen Xingyu <hi@xingrz.me>
# SPDX-License-Identifier: Apache-2.0
'''Runner for probe-rs.'''
from runners.core import RunnerCaps, ZephyrBinaryRunner
class ProbeRsBinaryRunner(ZephyrBinaryRunner):
'''Runner front-end for probe-rs.'''
def __init__(self, cfg, chip,
probe_rs='probe-rs',
dev_id=None,
erase=False,
tool_opt=None):
super().__init__(cfg)
self.probe_rs = probe_rs
self.erase = erase
self.args = ['--chip', chip]
if dev_id is not None:
self.args += ['--probe', dev_id]
if tool_opt is not None:
self.args += tool_opt
self.elf_name = cfg.elf_file
@classmethod
def name(cls):
return 'probe-rs'
@classmethod
def capabilities(cls):
return RunnerCaps(commands={'flash'},
dev_id=True,
erase=True,
tool_opt=True)
@classmethod
def do_add_parser(cls, parser):
parser.add_argument('--chip', required=True,
help='chip name')
parser.add_argument('--probe-rs', default='probe-rs',
help='path to probe-rs tool, default is probe-rs')
@classmethod
def dev_id_help(cls) -> str:
return '''select a specific probe, in the form `VID:PID:<Serial>`'''
@classmethod
def tool_opt_help(cls) -> str:
return '''additional options for probe-rs,
e.g. --chip-description-path=/path/to/chip.yml'''
@classmethod
def do_create(cls, cfg, args):
return ProbeRsBinaryRunner(cfg, args.chip,
probe_rs=args.probe_rs,
dev_id=args.dev_id,
erase=args.erase,
tool_opt=args.tool_opt)
def do_run(self, command, **kwargs):
self.require(self.probe_rs)
if command == 'flash':
self.do_flash(**kwargs)
def do_flash(self, **kwargs):
download_args = []
if self.erase:
download_args += ['--chip-erase']
download_args += [self.elf_name]
self.check_call([self.probe_rs, 'download']
+ self.args + download_args)
self.check_call([self.probe_rs, 'reset']
+ self.args)