Skip to content

Commit 4ad9fd3

Browse files
committed
scripts: runners: Add wrapper for WCHISPTool
`WCHISPTool_CMD` is the commandline version of WCHISPTool, which is a USB flashing tool for WCH series MCUs. Signed-off-by: Chen Xingyu <[email protected]>
1 parent 128f202 commit 4ad9fd3

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed

boards/common/wchisp.board.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Copyright (c) 2023-2024 Chen Xingyu <[email protected]>
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
board_set_flasher_ifnset(wchisp)
5+
board_finalize_runner_args(wchisp)

scripts/west_commands/runners/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def _import_runner_module(runner_name):
5959
'teensy',
6060
'trace32',
6161
'uf2',
62+
'wchisp',
6263
'xtensa',
6364
# Keep this list sorted by runner name; don't add to the end.
6465
]
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Copyright (c) 2023-2024 Chen Xingyu <[email protected]>
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
'''Runner for flashing WCH devices with WCHISPTool_CMD.'''
5+
6+
from runners.core import ZephyrBinaryRunner, RunnerCaps
7+
8+
class WchIspBinaryRunner(ZephyrBinaryRunner):
9+
'''Runner front-end for WCHISPTool_CMD'''
10+
11+
def __init__(self, cfg, device, cfg_file):
12+
super().__init__(cfg)
13+
self.app_bin = cfg.bin_file
14+
self.device = device
15+
self.cfg_file = cfg_file
16+
17+
@classmethod
18+
def name(cls):
19+
return 'wchisp'
20+
21+
@classmethod
22+
def capabilities(cls):
23+
return RunnerCaps(commands={'flash'})
24+
25+
@classmethod
26+
def do_add_parser(cls, parser):
27+
parser.add_argument('--device', required=True,
28+
help='port of the USB ISP device')
29+
parser.add_argument('--cfg-file', required=True,
30+
help='configuration file generated by WCHISPTool')
31+
32+
@classmethod
33+
def do_create(cls, cfg, args):
34+
return WchIspBinaryRunner(cfg, args.device, args.cfg_file)
35+
36+
def do_run(self, command, **kwargs):
37+
self.check_call([
38+
'WCHISPTool_CMD',
39+
'--device', self.device,
40+
'--configure', self.cfg_file,
41+
'--operation', 'program',
42+
'--flash', self.app_bin,
43+
])

scripts/west_commands/tests/test_imports.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,6 @@ def test_runner_imports():
4949
'trace32',
5050
'teensy',
5151
'uf2',
52+
'wchisp',
5253
'xtensa'))
5354
assert runner_names == expected

0 commit comments

Comments
 (0)