Skip to content

Commit

Permalink
scripts: runners: Add wrapper for WCHISPTool
Browse files Browse the repository at this point in the history
`WCHISPTool_CMD` is the commandline version of WCHISPTool, which is a USB
flashing tool for WCH series MCUs.

Signed-off-by: Chen Xingyu <hi@xingrz.me>
  • Loading branch information
xingrz committed Sep 4, 2024
1 parent 128f202 commit 4ad9fd3
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
5 changes: 5 additions & 0 deletions boards/common/wchisp.board.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright (c) 2023-2024 Chen Xingyu <hi@xingrz.me>
# SPDX-License-Identifier: Apache-2.0

board_set_flasher_ifnset(wchisp)
board_finalize_runner_args(wchisp)
1 change: 1 addition & 0 deletions scripts/west_commands/runners/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def _import_runner_module(runner_name):
'teensy',
'trace32',
'uf2',
'wchisp',
'xtensa',
# Keep this list sorted by runner name; don't add to the end.
]
Expand Down
43 changes: 43 additions & 0 deletions scripts/west_commands/runners/wchisp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright (c) 2023-2024 Chen Xingyu <hi@xingrz.me>
# SPDX-License-Identifier: Apache-2.0

'''Runner for flashing WCH devices with WCHISPTool_CMD.'''

from runners.core import ZephyrBinaryRunner, RunnerCaps

class WchIspBinaryRunner(ZephyrBinaryRunner):
'''Runner front-end for WCHISPTool_CMD'''

def __init__(self, cfg, device, cfg_file):
super().__init__(cfg)
self.app_bin = cfg.bin_file
self.device = device
self.cfg_file = cfg_file

@classmethod
def name(cls):
return 'wchisp'

@classmethod
def capabilities(cls):
return RunnerCaps(commands={'flash'})

@classmethod
def do_add_parser(cls, parser):
parser.add_argument('--device', required=True,
help='port of the USB ISP device')
parser.add_argument('--cfg-file', required=True,
help='configuration file generated by WCHISPTool')

@classmethod
def do_create(cls, cfg, args):
return WchIspBinaryRunner(cfg, args.device, args.cfg_file)

def do_run(self, command, **kwargs):
self.check_call([
'WCHISPTool_CMD',
'--device', self.device,
'--configure', self.cfg_file,
'--operation', 'program',
'--flash', self.app_bin,
])
1 change: 1 addition & 0 deletions scripts/west_commands/tests/test_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,6 @@ def test_runner_imports():
'trace32',
'teensy',
'uf2',
'wchisp',
'xtensa'))
assert runner_names == expected

0 comments on commit 4ad9fd3

Please sign in to comment.