Skip to content

Commit 5fa74d4

Browse files
EasyDevKitsborneoa
authored andcommitted
jtag/ch347: Refine driver and configs for EasyDevKits adapters
This commit improves support for CH347-based JTAG adapters: - configure.ac: removed "Mode3" restriction (CH347F does not require mode). - configs: added board config for ESP32-WROVER-E WCH JTAG DevKit and ESP32-WROVER-E FTDI JTAG DevKit - ch347 driver: removed `ch347 activity_led` command; activity LED is now controlled via the generic `adapter gpio led` command. - doc/openocd.texi: updated documentation accordingly. Change-Id: I5524290297adcc004e00af919181868d2b6303af Signed-off-by: EasyDevKits <[email protected]> Reviewed-on: https://review.openocd.org/c/openocd/+/9015 Reviewed-by: zapb <[email protected]> Tested-by: jenkins Reviewed-by: Tomas Vanek <[email protected]> Reviewed-by: Antonio Borneo <[email protected]>
1 parent 8b43a96 commit 5fa74d4

File tree

5 files changed

+100
-45
lines changed

5 files changed

+100
-45
lines changed

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ m4_define([ADAPTER_OPT], [m4_translit(ADAPTER_ARG($1), [_], [-])])
129129

130130
m4_define([USB1_ADAPTERS],
131131
[[[ftdi], [MPSSE mode of FTDI based devices], [FTDI]],
132-
[[ch347], [Mode 3 of CH347 based devices], [CH347]],
132+
[[ch347], [CH347 based devices], [CH347]],
133133
[[stlink], [ST-Link Programmer], [HLADAPTER_STLINK]],
134134
[[ti_icdi], [TI ICDI JTAG Programmer], [HLADAPTER_ICDI]],
135135
[[ulink], [Keil ULINK JTAG Programmer], [ULINK]],

doc/openocd.texi

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2590,6 +2590,9 @@ mitigates the problem.
25902590
@end itemize
25912591
@end itemize
25922592

2593+
The driver supports activity LED through the generic
2594+
command @ref{adapter gpio, @command{adapter gpio led}}.
2595+
25932596
This driver has these driver-specific command:
25942597

25952598
@deffn {Config Command} {ch347 vid_pid} [vid pid]+
@@ -2609,17 +2612,6 @@ and product ID will be connected.
26092612
ch347 device_desc "EasyDevKit"
26102613
@end example
26112614
@end deffn
2612-
2613-
@deffn {Config Command} {ch347 activity_led} [n]gpio_number
2614-
If specified the drive let an activity LED blink during JTAG operations.
2615-
The number is the GPIO number of the CH347T chip. If prefixed with "n",
2616-
then this GPIO should be low active. The example configures GPIO4 as
2617-
low active activity LED. For the CH347T chip only GPIO3 (Pin11 / SCL),
2618-
GPIO4 (Pin15 / ACT), GPIO5 (Pin9 / TRST) and GPIO6 (Pin2 / CTS1) are possible.
2619-
@example
2620-
ch347 activity_led n4
2621-
@end example
2622-
@end deffn
26232615
@end deffn
26242616

26252617
@deffn {Interface Driver} {cmsis-dap}

src/jtag/drivers/ch347.c

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#include <jtag/interface.h>
4949
#include <jtag/commands.h>
5050
#include <jtag/swd.h>
51+
#include <jtag/adapter.h>
5152
#include <helper/time_support.h>
5253
#include <helper/replacements.h>
5354
#include <helper/list.h>
@@ -1805,32 +1806,6 @@ COMMAND_HANDLER(ch347_handle_device_desc_command)
18051806
return ERROR_OK;
18061807
}
18071808

1808-
/**
1809-
* @brief The command handler for configuring which GPIO pin is used as activity LED
1810-
*
1811-
* @return ERROR_OK at success; ERROR_COMMAND_SYNTAX_ERROR otherwise
1812-
*/
1813-
COMMAND_HANDLER(ch347_handle_activity_led_command)
1814-
{
1815-
if (CMD_ARGC != 1)
1816-
return ERROR_COMMAND_SYNTAX_ERROR;
1817-
1818-
uint8_t gpio;
1819-
if (CMD_ARGV[0][0] == 'n') {
1820-
COMMAND_PARSE_NUMBER(u8, &CMD_ARGV[0][1], gpio);
1821-
ch347_activity_led_active_high = false;
1822-
} else {
1823-
COMMAND_PARSE_NUMBER(u8, CMD_ARGV[0], gpio);
1824-
ch347_activity_led_active_high = true;
1825-
}
1826-
1827-
if (gpio >= GPIO_CNT || (BIT(gpio) & USEABLE_GPIOS) == 0)
1828-
return ERROR_COMMAND_ARGUMENT_INVALID;
1829-
1830-
ch347_activity_led_gpio_pin = gpio;
1831-
return ERROR_OK;
1832-
}
1833-
18341809
static const struct command_registration ch347_subcommand_handlers[] = {
18351810
{
18361811
.name = "vid_pid",
@@ -1846,13 +1821,6 @@ static const struct command_registration ch347_subcommand_handlers[] = {
18461821
.help = "set the USB device description of the CH347 device",
18471822
.usage = "description_string",
18481823
},
1849-
{
1850-
.name = "activity_led",
1851-
.handler = &ch347_handle_activity_led_command,
1852-
.mode = COMMAND_CONFIG,
1853-
.help = "if set this CH347 GPIO pin is the JTAG activity LED; start with n for active low output",
1854-
.usage = "[n]gpio_number",
1855-
},
18561824
COMMAND_REGISTRATION_DONE
18571825
};
18581826

@@ -1867,6 +1835,25 @@ static const struct command_registration ch347_command_handlers[] = {
18671835
COMMAND_REGISTRATION_DONE
18681836
};
18691837

1838+
/**
1839+
* @brief Configure which GPIO pin is used as the activity LED.
1840+
*
1841+
* Updates the global activity LED GPIO pin and polarity settings
1842+
* based on the provided configuration. If the given GPIO is not
1843+
* usable, the function returns without making changes.
1844+
*
1845+
* @param led_config Pointer to the GPIO configuration structure for the LED pin
1846+
*/
1847+
static void ch347_configure_activity_led(const struct adapter_gpio_config *led_config)
1848+
{
1849+
uint8_t gpio = led_config->gpio_num;
1850+
if (gpio >= GPIO_CNT || (BIT(gpio) & USEABLE_GPIOS) == 0)
1851+
return;
1852+
1853+
ch347_activity_led_gpio_pin = gpio;
1854+
ch347_activity_led_active_high = !led_config->active_low;
1855+
}
1856+
18701857
/**
18711858
* @brief CH347 Initialization function
18721859
*
@@ -1893,6 +1880,8 @@ static int ch347_init(void)
18931880

18941881
ch347.pack_size = UNSET;
18951882

1883+
ch347_configure_activity_led(&adapter_gpio_get_config()[ADAPTER_GPIO_IDX_LED]);
1884+
18961885
if (!swd_mode) {
18971886
tap_set_state(TAP_RESET);
18981887
} else {
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# SPDX-License-Identifier: GPL-2.0-or-later
2+
#
3+
# Example OpenOCD configuration file for the EasyDevKits ESP32-WROVER-E FTDI JTAG DevKit.
4+
#
5+
# For example, OpenOCD can be started for ESP32 debugging on
6+
#
7+
# openocd -f board/esp32-wrover-e-ftdi-jtag-devkit.cfg
8+
#
9+
10+
# Select the FTDI JTAG driver
11+
adapter driver ftdi
12+
13+
# Identify the device
14+
ftdi device_desc "EasyDevKit"
15+
ftdi vid_pid 0x0403 0x6010
16+
# interface 0 is JTAG; interface 1 is the uart
17+
ftdi channel 0
18+
19+
# TCK, TDI, TDO, TMS: ADBUS0-3
20+
# activity LED: ADBUS4
21+
ftdi layout_init 0x0008 0x001b
22+
ftdi layout_signal LED -data 0x0010
23+
24+
# Source the ESP32 configuration file
25+
source [find target/esp32.cfg]
26+
27+
# ---------------------------------------------------------------------------
28+
# JTAG speed (in kHz)
29+
#
30+
# If you encounter DSR/DIR errors that are not caused by OpenOCD
31+
# attempting to read unmapped memory regions, try lowering this value.
32+
#
33+
# Recommended settings for EasyDevKits:
34+
# - Do not exceed 20 MHz.
35+
# - Best results are typically achieved at 20 MHz.
36+
# ---------------------------------------------------------------------------
37+
adapter speed 20000
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# SPDX-License-Identifier: GPL-2.0-or-later
2+
#
3+
# Example OpenOCD configuration file for the EasyDevKits ESP32-WROVER-E WCH JTAG DevKit.
4+
#
5+
# For example, OpenOCD can be started for ESP32 debugging on
6+
#
7+
# openocd -f board/esp32-wrover-e-wch-jtag-devkit.cfg
8+
#
9+
10+
# Select the CH347 JTAG driver
11+
adapter driver ch347
12+
13+
# Identify the device
14+
ch347 device_desc "EasyDevKit"
15+
ch347 vid_pid 0x1a86 0x55dd
16+
17+
# Configure activity LED
18+
# Note: The LED is active-low on GPIO4.
19+
adapter gpio led 4 -active-low
20+
21+
# Source the ESP32 configuration file
22+
source [find target/esp32.cfg]
23+
24+
# ---------------------------------------------------------------------------
25+
# JTAG speed (in kHz)
26+
#
27+
# If you encounter DSR/DIR errors that are not caused by OpenOCD
28+
# attempting to read unmapped memory regions, try lowering this value.
29+
#
30+
# Recommended settings for EasyDevKits:
31+
# - Do not exceed 30 MHz.
32+
# - Best results are typically achieved at 15 MHz.
33+
#
34+
# Supported frequencies (kHz):
35+
# 469, 938, 1875, 3750, 7500, 15000, 30000, 60000
36+
# ---------------------------------------------------------------------------
37+
adapter speed 15000

0 commit comments

Comments
 (0)