Skip to content

Commit 4444a99

Browse files
committed
jtag/drivers: Add general support for CH347 based interfaces
I found that there is no support for CH347 based JTAG adapters. A WCH CH347T chip in mode 3 has one UART and one JTAG interface. Like an FTDI FT2232 chip, you can use the CH347T chip for UART and JTAG. With this change I add support for CH347T based JTAG adapters. The WCH datasheet mention also a CH347F chip which wasn't available for testing. So, this driver is only tested for CH347T chip. The ch347 driver source code is adopted from https://github.com/WCHSoftGroup/ch347 I've done some bug fixing in the ch347 driver code to get it working and applied the openocd style guide to it. Finally I've added the new ch347 driver in the build files. I found the USB packet format by looking at public available source code at GitHub and I've documented here: https://www.easydevkits.com/wch-ch347-jtag-interface/ Change-Id: I5fca9dd015111e4410fea029611fdeedbb228fdb Signed-off-by: EasyDevKits <info@easydevkits.com>
1 parent 83e0293 commit 4444a99

File tree

8 files changed

+2307
-1
lines changed

8 files changed

+2307
-1
lines changed

configure.ac

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ m4_define([ADAPTER_OPT], [m4_translit(ADAPTER_ARG($1), [_], [-])])
121121

122122
m4_define([USB1_ADAPTERS],
123123
[[[ftdi], [MPSSE mode of FTDI based devices], [FTDI]],
124+
[[ch347], [Mode 3 of CH347 based devices], [CH347]],
124125
[[stlink], [ST-Link Programmer], [HLADAPTER_STLINK]],
125126
[[ti_icdi], [TI ICDI JTAG Programmer], [HLADAPTER_ICDI]],
126127
[[ulink], [Keil ULINK JTAG Programmer], [ULINK]],
@@ -408,6 +409,10 @@ AC_ARG_ENABLE([remote-bitbang],
408409
AS_HELP_STRING([--enable-remote-bitbang], [Enable building support for the Remote Bitbang driver]),
409410
[build_remote_bitbang=$enableval], [build_remote_bitbang=no])
410411

412+
AC_ARG_ENABLE([ch347],
413+
AS_HELP_STRING([--enable-ch347], [Enable building support for CH347]),
414+
[build_ch347=$enableval], [build_ch347=no])
415+
411416
AS_CASE(["${host_cpu}"],
412417
[i?86|x86*], [],
413418
[
@@ -635,6 +640,12 @@ AS_IF([test "x$build_sysfsgpio" = "xyes"], [
635640
AC_DEFINE([BUILD_SYSFSGPIO], [0], [0 if you don't want SysfsGPIO driver.])
636641
])
637642

643+
AS_IF([test "x$build_ch347" = "xyes"], [
644+
AC_DEFINE([BUILD_CH347], [1], [1 if you want CH347.])
645+
], [
646+
AC_DEFINE([BUILD_CH347], [0], [0 if you don't want CH347.])
647+
])
648+
638649
PKG_CHECK_MODULES([LIBUSB1], [libusb-1.0], [
639650
use_libusb1=yes
640651
AC_DEFINE([HAVE_LIBUSB1], [1], [Define if you have libusb-1.x])
@@ -803,6 +814,8 @@ AM_CONDITIONAL([HAVE_CAPSTONE], [test "x$enable_capstone" != "xno"])
803814
AM_CONDITIONAL([INTERNAL_JIMTCL], [test "x$use_internal_jimtcl" = "xyes"])
804815
AM_CONDITIONAL([HAVE_JIMTCL_PKG_CONFIG], [test "x$have_jimtcl_pkg_config" = "xyes"])
805816
AM_CONDITIONAL([INTERNAL_LIBJAYLINK], [test "x$use_internal_libjaylink" = "xyes"])
817+
AM_CONDITIONAL([BUILD_CH347], [test "x$build_ch347" = "xyes"])
818+
806819

807820
AM_CONDITIONAL([USE_GCOV], [test "x$enable_gcov" = "xyes"])
808821

contrib/60-openocd.rules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,9 @@ ATTRS{idVendor}=="16c0", ATTRS{idProduct}=="06ad", MODE="660", GROUP="plugdev",
216216
# USBprog with OpenOCD firmware
217217
ATTRS{idVendor}=="1781", ATTRS{idProduct}=="0c63", MODE="660", GROUP="plugdev", TAG+="uaccess"
218218

219+
# WCH CH347 chip in mode 3
220+
ATTRS{idVendor}=="1a86", ATTRS{idProduct}=="55dd", MODE="660", GROUP="plugdev", TAG+="uaccess"
221+
219222
# TI/Luminary Stellaris In-Circuit Debug Interface (ICDI) Board
220223
ATTRS{idVendor}=="1cbe", ATTRS{idProduct}=="00fd", MODE="660", GROUP="plugdev", TAG+="uaccess"
221224

doc/openocd.texi

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,10 @@ This is deprecated from Linux v5.3; prefer using @b{linuxgpiod}.
627627
@item @b{esp_usb_jtag}
628628
@* A JTAG driver to communicate with builtin debug modules of Espressif ESP32-C3 and ESP32-S3 chips using OpenOCD.
629629

630+
@item @b{ch347}
631+
@* A JTAG driver which uses the WCH CH347T JTAG chip which works in mode 3 as UART + JTAG interface.
632+
The WCH datasheet for CH347 mention also a CH347F version. But this version was not available for testing.
633+
630634
@end itemize
631635

632636
@node About Jim-Tcl
@@ -2539,6 +2543,28 @@ and a specific set of GPIOs is used.
25392543
@c chooses among list of bit configs ... only one option
25402544
@end deffn
25412545

2546+
@deffn {Interface Driver} {ch347}
2547+
Driver for WCH CH347T chips in mode 3 (UART + JTAG).
2548+
This driver has these driver-specific command:
2549+
2550+
@deffn {Config Command} {ch347 vid_pid} vid pid
2551+
The vendor ID and product ID of the CH347T device in mode 3. If not specified
2552+
the driver will use vendor ID 0x1a86 and product ID 0x55dd.
2553+
@example
2554+
ch347 vid_pid 0x1a86 0x55dd
2555+
@end example
2556+
@end deffn
2557+
2558+
@deffn {Config Command} {ch347 device_desc} description
2559+
If specified connect to a device which exactly has this product description
2560+
string. If not specified the first found device with the correct vendor
2561+
and product ID will be connected.
2562+
@example
2563+
ch347 device_desc "EasyDevKit"
2564+
@end example
2565+
@end deffn
2566+
@end deffn
2567+
25422568
@deffn {Interface Driver} {cmsis-dap}
25432569
ARM CMSIS-DAP compliant based adapter v1 (USB HID based)
25442570
or v2 (USB bulk).
@@ -13575,4 +13601,4 @@ foreach who @{A B C D E@}
1357513601
@unnumbered Command and Driver Index
1357613602
@printindex fn
1357713603

13578-
@bye
13604+
@bye
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
# SPDX-License-Identifier: GPL-2.0-or-later OR GFDL-1.2-no-invariants-or-later
2+
3+
# Link: https://www.easydevkits.com
4+
# PCB: ESP32-WROVER-E WCH JTAG DevKit v0.1
5+
# Chip: CH347T in mode 3 (UART+JTAG mode)
6+
# Product id of 0x55dd is only valid if the chip is started in mode 3
7+
# These are the other product ids: mode 0 = 0x55da, mode 1 = 0x55db, mode 2 = 0x55dc
8+
# The similar chip CH347F has no modes and always product id 0x55de
9+
10+
Bus 001 Device 013: ID 1a86:55dd QinHeng Electronics EasyDevKit
11+
Device Descriptor:
12+
bLength 18
13+
bDescriptorType 1
14+
bcdUSB 2.00
15+
bDeviceClass 0
16+
bDeviceSubClass 0
17+
bDeviceProtocol 0
18+
bMaxPacketSize0 64
19+
idVendor 0x1a86 QinHeng Electronics
20+
idProduct 0x55dd
21+
bcdDevice 4.41
22+
iManufacturer 1 EasyDevKits
23+
iProduct 2 EasyDevKit
24+
iSerial 3 ACBACJGAAB
25+
bNumConfigurations 1
26+
Configuration Descriptor:
27+
bLength 9
28+
bDescriptorType 2
29+
wTotalLength 0x0062
30+
bNumInterfaces 3
31+
bConfigurationValue 1
32+
iConfiguration 0
33+
bmAttributes 0x80
34+
(Bus Powered)
35+
MaxPower 500mA
36+
Interface Association:
37+
bLength 8
38+
bDescriptorType 11
39+
bFirstInterface 0
40+
bInterfaceCount 2
41+
bFunctionClass 2 Communications
42+
bFunctionSubClass 2 Abstract (modem)
43+
bFunctionProtocol 1 AT-commands (v.25ter)
44+
iFunction 0
45+
Interface Descriptor:
46+
bLength 9
47+
bDescriptorType 4
48+
bInterfaceNumber 0
49+
bAlternateSetting 0
50+
bNumEndpoints 1
51+
bInterfaceClass 2 Communications
52+
bInterfaceSubClass 2 Abstract (modem)
53+
bInterfaceProtocol 1 AT-commands (v.25ter)
54+
iInterface 0
55+
CDC Header:
56+
bcdCDC 1.10
57+
CDC Call Management:
58+
bmCapabilities 0x00
59+
bDataInterface 1
60+
CDC ACM:
61+
bmCapabilities 0x02
62+
line coding and serial state
63+
CDC Union:
64+
bMasterInterface 0
65+
bSlaveInterface 1
66+
Endpoint Descriptor:
67+
bLength 7
68+
bDescriptorType 5
69+
bEndpointAddress 0x83 EP 3 IN
70+
bmAttributes 3
71+
Transfer Type Interrupt
72+
Synch Type None
73+
Usage Type Data
74+
wMaxPacketSize 0x0040 1x 64 bytes
75+
bInterval 1
76+
Interface Descriptor:
77+
bLength 9
78+
bDescriptorType 4
79+
bInterfaceNumber 1
80+
bAlternateSetting 0
81+
bNumEndpoints 2
82+
bInterfaceClass 10 CDC Data
83+
bInterfaceSubClass 0
84+
bInterfaceProtocol 0
85+
iInterface 0
86+
Endpoint Descriptor:
87+
bLength 7
88+
bDescriptorType 5
89+
bEndpointAddress 0x04 EP 4 OUT
90+
bmAttributes 2
91+
Transfer Type Bulk
92+
Synch Type None
93+
Usage Type Data
94+
wMaxPacketSize 0x0200 1x 512 bytes
95+
bInterval 0
96+
Endpoint Descriptor:
97+
bLength 7
98+
bDescriptorType 5
99+
bEndpointAddress 0x84 EP 4 IN
100+
bmAttributes 2
101+
Transfer Type Bulk
102+
Synch Type None
103+
Usage Type Data
104+
wMaxPacketSize 0x0200 1x 512 bytes
105+
bInterval 0
106+
Interface Descriptor:
107+
bLength 9
108+
bDescriptorType 4
109+
bInterfaceNumber 2
110+
bAlternateSetting 0
111+
bNumEndpoints 2
112+
bInterfaceClass 255 Vendor Specific Class
113+
bInterfaceSubClass 0
114+
bInterfaceProtocol 0
115+
iInterface 0
116+
Endpoint Descriptor:
117+
bLength 7
118+
bDescriptorType 5
119+
bEndpointAddress 0x06 EP 6 OUT
120+
bmAttributes 2
121+
Transfer Type Bulk
122+
Synch Type None
123+
Usage Type Data
124+
wMaxPacketSize 0x0200 1x 512 bytes
125+
bInterval 0
126+
Endpoint Descriptor:
127+
bLength 7
128+
bDescriptorType 5
129+
bEndpointAddress 0x86 EP 6 IN
130+
bmAttributes 2
131+
Transfer Type Bulk
132+
Synch Type None
133+
Usage Type Data
134+
wMaxPacketSize 0x0200 1x 512 bytes
135+
bInterval 0
136+
Device Qualifier (for other device speed):
137+
bLength 10
138+
bDescriptorType 6
139+
bcdUSB 2.00
140+
bDeviceClass 255 Vendor Specific Class
141+
bDeviceSubClass 0
142+
bDeviceProtocol 255
143+
bMaxPacketSize0 64
144+
bNumConfigurations 1
145+
Device Status: 0x0000
146+
(Bus Powered)

src/jtag/drivers/Makefile.am

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,9 @@ endif
210210
if AM335XGPIO
211211
DRIVERFILES += %D%/am335xgpio.c
212212
endif
213+
if CH347
214+
DRIVERFILES += %D%/ch347.c
215+
endif
213216

214217
DRIVERHEADERS = \
215218
%D%/bitbang.h \

0 commit comments

Comments
 (0)