runners: add minichlink
This commit adds a runner wrapper for the 'minichlink' program which offers a free, open mechanism to use the CH-LinkE programming dongle for the CH32V003. https://github.com/cnlohr/ch32v003fun/tree/master/minichlink Signed-off-by: Michael Hope <michaelh@juju.nz> Signed-off-by: Dhiru Kholia <dhiru.kholia@gmail.com>
This commit is contained in:
parent
ab66361f4d
commit
de19a13c34
5 changed files with 105 additions and 0 deletions
5
boards/common/minichlink.board.cmake
Normal file
5
boards/common/minichlink.board.cmake
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# Copyright (c) 2024 Dhiru Kholia
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
board_set_flasher_ifnset(minichlink)
|
||||||
|
board_finalize_runner_args(minichlink)
|
|
@ -3,3 +3,6 @@
|
||||||
|
|
||||||
board_runner_args(openocd "--use-elf" "--cmd-reset-halt" "halt")
|
board_runner_args(openocd "--use-elf" "--cmd-reset-halt" "halt")
|
||||||
include(${ZEPHYR_BASE}/boards/common/openocd.board.cmake)
|
include(${ZEPHYR_BASE}/boards/common/openocd.board.cmake)
|
||||||
|
|
||||||
|
board_runner_args(minichlink)
|
||||||
|
include(${ZEPHYR_BASE}/boards/common/minichlink.board.cmake)
|
||||||
|
|
|
@ -40,6 +40,7 @@ _names = [
|
||||||
'jlink',
|
'jlink',
|
||||||
'linkserver',
|
'linkserver',
|
||||||
'mdb',
|
'mdb',
|
||||||
|
'minichlink',
|
||||||
'misc',
|
'misc',
|
||||||
'native',
|
'native',
|
||||||
'nios2',
|
'nios2',
|
||||||
|
|
95
scripts/west_commands/runners/minichlink.py
Normal file
95
scripts/west_commands/runners/minichlink.py
Normal file
|
@ -0,0 +1,95 @@
|
||||||
|
# Copyright (c) 2024 Google LLC.
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
"""WCH CH32V00x specific runner."""
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
from runners.core import RunnerCaps, RunnerConfig, ZephyrBinaryRunner
|
||||||
|
|
||||||
|
|
||||||
|
class MiniChLinkBinaryRunner(ZephyrBinaryRunner):
|
||||||
|
"""Runner for CH32V00x based devices using minichlink."""
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
cfg: RunnerConfig,
|
||||||
|
minichlink: str,
|
||||||
|
erase: bool,
|
||||||
|
reset: bool,
|
||||||
|
dt_flash: bool,
|
||||||
|
terminal: bool,
|
||||||
|
):
|
||||||
|
super().__init__(cfg)
|
||||||
|
|
||||||
|
self.minichlink = minichlink
|
||||||
|
self.erase = erase
|
||||||
|
self.reset = reset
|
||||||
|
self.dt_flash = dt_flash
|
||||||
|
self.terminal = terminal
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def name(cls):
|
||||||
|
return "minichlink"
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def capabilities(cls) -> RunnerCaps:
|
||||||
|
return RunnerCaps(commands={"flash"}, flash_addr=True, erase=True, reset=True)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def do_add_parser(cls, parser: argparse.ArgumentParser):
|
||||||
|
parser.add_argument(
|
||||||
|
"--minichlink", default="minichlink", help="path to the minichlink binary"
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--terminal",
|
||||||
|
default=False,
|
||||||
|
action=argparse.BooleanOptionalAction,
|
||||||
|
help="open the terminal after flashing. Implies --reset.",
|
||||||
|
)
|
||||||
|
parser.set_defaults(reset=True)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def do_create(cls, cfg: RunnerConfig, args: argparse.Namespace):
|
||||||
|
return MiniChLinkBinaryRunner(
|
||||||
|
cfg,
|
||||||
|
minichlink=args.minichlink,
|
||||||
|
erase=args.erase,
|
||||||
|
reset=args.reset,
|
||||||
|
dt_flash=(args.dt_flash == "y"),
|
||||||
|
terminal=args.terminal,
|
||||||
|
)
|
||||||
|
|
||||||
|
def do_run(self, command: str, **kwargs):
|
||||||
|
self.require(self.minichlink)
|
||||||
|
|
||||||
|
if command == "flash":
|
||||||
|
self.flash()
|
||||||
|
else:
|
||||||
|
raise ValueError("BUG: unhandled command f{command}")
|
||||||
|
|
||||||
|
def flash(self):
|
||||||
|
self.ensure_output("bin")
|
||||||
|
|
||||||
|
cmd = [self.minichlink, "-a"]
|
||||||
|
|
||||||
|
if self.erase:
|
||||||
|
cmd.append("-E")
|
||||||
|
|
||||||
|
flash_addr = 0
|
||||||
|
if self.dt_flash:
|
||||||
|
flash_addr = self.flash_address_from_build_conf(self.build_conf)
|
||||||
|
|
||||||
|
cmd.extend(["-w", self.cfg.bin_file or "", f"0x{flash_addr:x}"])
|
||||||
|
|
||||||
|
if self.reset or self.terminal:
|
||||||
|
cmd.append("-b")
|
||||||
|
|
||||||
|
if self.terminal:
|
||||||
|
cmd.append("-T")
|
||||||
|
|
||||||
|
if self.terminal:
|
||||||
|
self.check_call(cmd)
|
||||||
|
else:
|
||||||
|
self.check_output(cmd)
|
|
@ -32,6 +32,7 @@ def test_runner_imports():
|
||||||
'linkserver',
|
'linkserver',
|
||||||
'mdb-hw',
|
'mdb-hw',
|
||||||
'mdb-nsim',
|
'mdb-nsim',
|
||||||
|
'minichlink',
|
||||||
'misc-flasher',
|
'misc-flasher',
|
||||||
'native',
|
'native',
|
||||||
'nios2',
|
'nios2',
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue