You can subscribe to this list here.
| 2008 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(75) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2009 |
Jan
(70) |
Feb
(20) |
Mar
(52) |
Apr
(149) |
May
(387) |
Jun
(466) |
Jul
(133) |
Aug
(87) |
Sep
(122) |
Oct
(140) |
Nov
(185) |
Dec
(105) |
| 2010 |
Jan
(85) |
Feb
(45) |
Mar
(75) |
Apr
(17) |
May
(41) |
Jun
(52) |
Jul
(33) |
Aug
(29) |
Sep
(36) |
Oct
(15) |
Nov
(26) |
Dec
(34) |
| 2011 |
Jan
(26) |
Feb
(25) |
Mar
(26) |
Apr
(29) |
May
(20) |
Jun
(27) |
Jul
(15) |
Aug
(32) |
Sep
(13) |
Oct
(64) |
Nov
(60) |
Dec
(10) |
| 2012 |
Jan
(64) |
Feb
(63) |
Mar
(39) |
Apr
(43) |
May
(54) |
Jun
(11) |
Jul
(30) |
Aug
(45) |
Sep
(11) |
Oct
(70) |
Nov
(24) |
Dec
(23) |
| 2013 |
Jan
(17) |
Feb
(8) |
Mar
(35) |
Apr
(40) |
May
(20) |
Jun
(24) |
Jul
(36) |
Aug
(25) |
Sep
(42) |
Oct
(40) |
Nov
(9) |
Dec
(21) |
| 2014 |
Jan
(29) |
Feb
(24) |
Mar
(60) |
Apr
(22) |
May
(22) |
Jun
(46) |
Jul
(11) |
Aug
(23) |
Sep
(26) |
Oct
(10) |
Nov
(14) |
Dec
(2) |
| 2015 |
Jan
(28) |
Feb
(47) |
Mar
(33) |
Apr
(58) |
May
(5) |
Jun
(1) |
Jul
|
Aug
(8) |
Sep
(12) |
Oct
(25) |
Nov
(58) |
Dec
(21) |
| 2016 |
Jan
(12) |
Feb
(40) |
Mar
(2) |
Apr
(1) |
May
(67) |
Jun
(2) |
Jul
(5) |
Aug
(36) |
Sep
|
Oct
(24) |
Nov
(17) |
Dec
(50) |
| 2017 |
Jan
(14) |
Feb
(16) |
Mar
(2) |
Apr
(35) |
May
(14) |
Jun
(16) |
Jul
(3) |
Aug
(3) |
Sep
|
Oct
(19) |
Nov
|
Dec
(16) |
| 2018 |
Jan
(55) |
Feb
(11) |
Mar
(34) |
Apr
(14) |
May
(4) |
Jun
(20) |
Jul
(39) |
Aug
(16) |
Sep
(17) |
Oct
(16) |
Nov
(20) |
Dec
(30) |
| 2019 |
Jan
(29) |
Feb
(24) |
Mar
(37) |
Apr
(26) |
May
(19) |
Jun
(21) |
Jul
(2) |
Aug
(3) |
Sep
(9) |
Oct
(12) |
Nov
(12) |
Dec
(12) |
| 2020 |
Jan
(47) |
Feb
(36) |
Mar
(54) |
Apr
(44) |
May
(37) |
Jun
(19) |
Jul
(32) |
Aug
(13) |
Sep
(16) |
Oct
(24) |
Nov
(32) |
Dec
(11) |
| 2021 |
Jan
(14) |
Feb
(5) |
Mar
(40) |
Apr
(32) |
May
(42) |
Jun
(31) |
Jul
(29) |
Aug
(47) |
Sep
(38) |
Oct
(17) |
Nov
(74) |
Dec
(33) |
| 2022 |
Jan
(11) |
Feb
(15) |
Mar
(40) |
Apr
(21) |
May
(39) |
Jun
(44) |
Jul
(19) |
Aug
(46) |
Sep
(79) |
Oct
(35) |
Nov
(21) |
Dec
(15) |
| 2023 |
Jan
(56) |
Feb
(13) |
Mar
(43) |
Apr
(28) |
May
(60) |
Jun
(15) |
Jul
(29) |
Aug
(28) |
Sep
(32) |
Oct
(21) |
Nov
(42) |
Dec
(39) |
| 2024 |
Jan
(35) |
Feb
(17) |
Mar
(28) |
Apr
(7) |
May
(14) |
Jun
(35) |
Jul
(30) |
Aug
(35) |
Sep
(30) |
Oct
(28) |
Nov
(38) |
Dec
(18) |
| 2025 |
Jan
(21) |
Feb
(28) |
Mar
(36) |
Apr
(35) |
May
(34) |
Jun
(58) |
Jul
(9) |
Aug
(54) |
Sep
(47) |
Oct
(15) |
Nov
(42) |
Dec
|
|
From: openocd-gerrit <ope...@us...> - 2025-09-06 08:19:54
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Main OpenOCD repository".
The branch, master has been updated
via 7bc74de62d8b3d4fa90b9fe6dc32f7084342121d (commit)
from 3bec165e2590ae72bb67ba4913b92e18b1275600 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 7bc74de62d8b3d4fa90b9fe6dc32f7084342121d
Author: Marc Schink <de...@za...>
Date: Thu Feb 20 20:58:08 2025 +0000
adapter: Rework parallel port driver
Make the driver more flexible and define adapter-specific configurations
in Tcl instead of C using the adapter GPIO subsystem.
The rework also includes coding style fixes and improvements of the
documentation. All modifications are done such that backwards
compatibility is ensured.
Tested with Olimex ARM-JTAG cable [1] and APM32F103 target device on
Linux and FreeBSD. The driver works on Linux using direct I/O and PPDEV.
On FreeBSD, only PPDEV works. The build with direct I/O already failed
before the patch. This problem will be fixed in a subsequent patch.
The patch is not tested on Windows because there is no documentation
for it.
[1] https://www.olimex.com/Products/ARM/JTAG/ARM-JTAG/
Change-Id: Ib671d52a919eaf2959cf6365f2c8004257ae074c
Signed-off-by: Marc Schink <de...@za...>
Reviewed-on: https://review.openocd.org/c/openocd/+/8943
Reviewed-by: Antonio Borneo <bor...@gm...>
Tested-by: jenkins
diff --git a/doc/openocd.texi b/doc/openocd.texi
index 1e9f80dce..bfcdc857e 100644
--- a/doc/openocd.texi
+++ b/doc/openocd.texi
@@ -529,9 +529,8 @@ debuggers to ARM Cortex based targets @url{http://www.keil.com/support/man/docs/
@section IBM PC Parallel Printer Port Based
-The two well-known ``JTAG Parallel Ports'' cables are the Xilinx DLC5
-and the Macraigor Wiggler. There are many clones and variations of
-these on the market.
+The two well-known JTAG parallel port cables are the Xilinx DLC5 and the Macraigor Wiggler.
+There are many clones and variations of these on the market.
Note that parallel ports are becoming much less common, so if you
have the choice you should probably avoid these adapters in favor
@@ -553,7 +552,7 @@ produced, PDF schematics are easily found and it is easy to make.
@* Link: @url{http://www.ccac.rwth-aachen.de/~michaels/index.php/hardware/armjtag}
@item @b{Wiggler_ntrst_inverted}
-@* Yet another variation - See the source code, src/jtag/parport.c
+@* Yet another variation, see configuration in @file{interface/parport/wiggler-ntrst-inverted.cfg}
@item @b{old_amt_wiggler}
@* Unknown - probably not on the market today
@@ -3193,61 +3192,64 @@ version, and target voltage.
@end deffn
@deffn {Interface Driver} {parport}
-Supports PC parallel port bit-banging cables:
-Wigglers, PLD download cable, and more.
-These interfaces have several commands, used to configure the driver
-before initializing the JTAG scan chain:
-
-@deffn {Config Command} {parport cable} name
-Set the layout of the parallel port cable used to connect to the target.
-This is a write-once setting.
-Currently valid cable @var{name} values include:
-@itemize @minus
-@item @b{altium} Altium Universal JTAG cable.
-@item @b{arm-jtag} Same as original wiggler except SRST and
-TRST connections reversed and TRST is also inverted.
-@item @b{chameleon} The Amontec Chameleon's CPLD when operated
-in configuration mode. This is only used to
-program the Chameleon itself, not a connected target.
-@item @b{dlc5} The Xilinx Parallel cable III.
-@item @b{flashlink} The ST Parallel cable.
-@item @b{lattice} Lattice ispDOWNLOAD Cable
-@item @b{old_amt_wiggler} The Wiggler configuration that comes with
-some versions of
-Amontec's Chameleon Programmer. The new version available from
-the website uses the original Wiggler layout ('@var{wiggler}')
-@item @b{triton} The parallel port adapter found on the
-``Karo Triton 1 Development Board''.
-This is also the layout used by the HollyGates design
-(see @uref{http://www.lartmaker.nl/projects/jtag/}).
-@item @b{wiggler} The original Wiggler layout, also supported by
-several clones, such as the Olimex ARM-JTAG
-@item @b{wiggler2} Same as original wiggler except an led is fitted on D5.
-@item @b{wiggler_ntrst_inverted} Same as original wiggler except TRST is inverted.
-@end itemize
+This driver supports PC parallel port bit-banging adapters.
+Only JTAG is supported as transport protocol.
+The driver supports Linux, FreeBSD, and Windows.
+However, the Windows support is untested and unmaintained.
+
+The pin configuration is handled by the generic command @ref{adapter gpio, @command{adapter gpio}}.
+In addition to the JTAG signals, the driver also supports the activity LED signal.
+
+The data and status pins of the parallel port are used as output and input pins, respectively.
+The pin direction is given in the following table.
+
+@multitable @columnfractions .2 .1 .1 .1 .1 .1 .1 .1 .1
+@headitem Pin direction
+@item Input
+@tab ~11
+@tab 10
+@tab 12
+@tab 13
+@tab 15
+@tab -
+@tab -
+@tab -
+@item Output
+@tab 9
+@tab 8
+@tab 7
+@tab 6
+@tab 5
+@tab 4
+@tab 3
+@tab 2
+@end multitable
+
+@deffn {Config Command} {parport port} port_number
+Configure the number of the parallel port.
+
+When using PPDEV to access the parallel port, use the number of the parallel port file @file{/dev/parport} (Linux) or @file{/dev/ppi} (FreeBSD).
+The default port number is 0.
+
+When using direct I/O, the number is the I/O port number.
+The default port number is 0x378 (LTP1).
@end deffn
-@deffn {Config Command} {parport port} [port_number]
-Display either the address of the I/O port
-(default: 0x378 for LPT1) or the number of the @file{/dev/parport} device.
-If a parameter is provided, first switch to use that port.
-This is a write-once setting.
+@deffn {Config Command} {parport write_on_exit} (@option{on}|@option{off})
+@b{Note:} This command is deprecated and will be removed in the future.
+Use the command @command{adapter gpio} to configure the pin states before the adapter terminates its operation.
-When using PPDEV to access the parallel port, use the number of the parallel port:
-@option{parport port 0} (the default). If @option{parport port 0x378} is specified
-you may encounter a problem.
+Configure whether the driver sets the value specified by @command{adapter gpio} to the output pins on shutdown.
@end deffn
-@deffn {Config Command} {parport toggling_time} [nanoseconds]
-Displays how many nanoseconds the hardware needs to toggle TCK;
-the parport driver uses this value to obey the
-@command{adapter speed} configuration.
-When the optional @var{nanoseconds} parameter is given,
-that setting is changed before displaying the current value.
+@deffn {Config Command} {parport toggling_time} time
+Configure how many nanoseconds the hardware needs to toggle TCK.
+The driver uses this value to obey the @command{adapter speed} configuration.
The default setting should work reasonably well on commodity PC hardware.
However, you may want to calibrate for your specific hardware.
+
@quotation Tip
To measure the toggling time with a logic analyzer or a digital storage
oscilloscope, follow the procedure below:
@@ -3255,15 +3257,18 @@ oscilloscope, follow the procedure below:
> parport toggling_time 1000
> adapter speed 500
@end example
+
This sets the maximum JTAG clock speed of the hardware, but
the actual speed probably deviates from the requested 500 kHz.
Now, measure the time between the two closest spaced TCK transitions.
You can use @command{runtest 1000} or something similar to generate a
large set of samples.
Update the setting to match your measurement:
+
@example
> parport toggling_time <measured nanoseconds>
@end example
+
Now the clock speed will be a better match for @command{adapter speed}
command given in OpenOCD scripts and event handlers.
@@ -3275,20 +3280,6 @@ match with the rate you specified in the @command{adapter speed} command;
be conservative.
@end quotation
@end deffn
-
-@deffn {Config Command} {parport write_on_exit} (@option{on}|@option{off})
-This will configure the parallel driver to write a known
-cable-specific value to the parallel interface on exiting OpenOCD.
-@end deffn
-
-For example, the interface configuration file for a
-classic ``Wiggler'' cable on LPT2 might look something like this:
-
-@example
-adapter driver parport
-parport port 0x278
-parport cable wiggler
-@end example
@end deffn
@deffn {Interface Driver} {presto}
diff --git a/src/jtag/drivers/parport.c b/src/jtag/drivers/parport.c
index 433c20c89..09e312ec2 100644
--- a/src/jtag/drivers/parport.c
+++ b/src/jtag/drivers/parport.c
@@ -20,7 +20,7 @@
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
#include <machine/sysarch.h>
#include <machine/cpufunc.h>
-#define ioperm(startport, length, enable)\
+#define ioperm(startport, length, enable) \
i386_set_ioperm((startport), (length), (enable))
#endif /* __FreeBSD__ */
@@ -45,67 +45,14 @@
#include <windows.h>
#endif
-// Parallel port cable description.
-struct cable {
- const char *name;
- // Status port bit containing current TDO value.
- uint8_t tdo_mask;
- // Data port bit for TRST.
- uint8_t trst_mask;
- // Data port bit for TMD.
- uint8_t tms_mask;
- // Data port bit for TCK.
- uint8_t tck_mask;
- // Data port bit for TDI.
- uint8_t tdi_mask;
- // Data port bit for SRST.
- uint8_t srst_mask;
- // Data port bits that should be inverted.
- uint8_t output_invert;
- // Status port that should be inverted.
- uint8_t input_invert;
- // Initialize data port with this value.
- uint8_t port_init;
- // De-initialize data port with this value.
- uint8_t port_exit;
- // Data port bit for LED.
- uint8_t led_mask;
-};
-
-static const struct cable cables[] = {
- /* name tdo trst tms tck tdi srst o_inv i_inv init exit led */
- { "wiggler", 0x80, 0x10, 0x02, 0x04, 0x08, 0x01, 0x01, 0x80, 0x80, 0x80, 0x00 },
- { "wiggler2", 0x80, 0x10, 0x02, 0x04, 0x08, 0x01, 0x01, 0x80, 0x80, 0x00, 0x20 },
- { "wiggler_ntrst_inverted", 0x80, 0x10, 0x02, 0x04, 0x08, 0x01, 0x11, 0x80, 0x80, 0x80, 0x00 },
- { "old_amt_wiggler", 0x80, 0x01, 0x02, 0x04, 0x08, 0x10, 0x11, 0x80, 0x80, 0x80, 0x00 },
- { "arm-jtag", 0x80, 0x01, 0x02, 0x04, 0x08, 0x10, 0x01, 0x80, 0x80, 0x80, 0x00 },
- { "chameleon", 0x80, 0x00, 0x04, 0x01, 0x02, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00 },
- { "dlc5", 0x10, 0x00, 0x04, 0x02, 0x01, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00 },
- { "triton", 0x80, 0x08, 0x04, 0x01, 0x02, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00 },
- { "lattice", 0x40, 0x10, 0x04, 0x02, 0x01, 0x08, 0x00, 0x00, 0x18, 0x18, 0x00 },
- { "flashlink", 0x20, 0x10, 0x02, 0x01, 0x04, 0x20, 0x30, 0x20, 0x00, 0x00, 0x00 },
-/* Altium Universal JTAG cable. Set the cable to Xilinx Mode and wire to target as follows:
- HARD TCK - Target TCK
- HARD TMS - Target TMS
- HARD TDI - Target TDI
- HARD TDO - Target TDO
- SOFT TCK - Target TRST
- SOFT TDI - Target SRST
-*/
- { "altium", 0x10, 0x20, 0x04, 0x02, 0x01, 0x80, 0x00, 0x00, 0x10, 0x00, 0x08 },
- { "aspo", 0x10, 0x01, 0x04, 0x08, 0x02, 0x10, 0x17, 0x00, 0x17, 0x17, 0x00 },
- { NULL, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
-};
+static const struct adapter_gpio_config *adapter_gpio_config;
-// Configuration variables.
-static char *parport_cable;
static uint16_t parport_port;
-static bool parport_exit;
+static bool parport_write_exit_state;
static uint32_t parport_toggling_time_ns = 1000;
static int wait_states;
// Interface variables.
-static const struct cable *cable;
static uint8_t dataport_value;
#if PARPORT_USE_PPDEV == 1
@@ -115,6 +62,20 @@ static unsigned long dataport;
static unsigned long statusport;
#endif
+// Bitmask map for the input pins.
+static struct {
+ uint8_t mask;
+} input_pin_bitmask_map[] = {
+ [10] = {0x40},
+ [11] = {0x80},
+ [12] = {0x20},
+ [13] = {0x10},
+ [15] = {0x08},
+};
+
+// Generate an output pin bitmask for an adapter signal.
+#define OUTPUT_BITMASK(gpio_index) BIT((adapter_gpio_config[(gpio_index)].gpio_num - 2))
+
static enum bb_value parport_read(void)
{
int data = 0;
@@ -125,16 +86,15 @@ static enum bb_value parport_read(void)
data = inb(statusport);
#endif
- if ((data ^ cable->input_invert) & cable->tdo_mask)
- return BB_HIGH;
- else
- return BB_LOW;
+ const struct adapter_gpio_config *gpio_config = &adapter_gpio_config[ADAPTER_GPIO_IDX_TDO];
+ const bool tdo_state = data & input_pin_bitmask_map[gpio_config->gpio_num].mask;
+
+ return (tdo_state ^ gpio_config->active_low) ? BB_HIGH : BB_LOW;
}
-static inline void parport_write_data(void)
+static void parport_write_data(void)
{
- uint8_t output;
- output = dataport_value ^ cable->output_invert;
+ const uint8_t output = dataport_value;
#if PARPORT_USE_PPDEV == 1
ioctl(device_handle, PPWDATA, &output);
@@ -147,26 +107,27 @@ static inline void parport_write_data(void)
#endif
}
-static int parport_write(int tck, int tms, int tdi)
+static bool is_gpio_configured(enum adapter_gpio_config_index gpio_index)
{
- int i = wait_states + 1;
-
- if (tck)
- dataport_value |= cable->tck_mask;
- else
- dataport_value &= ~cable->tck_mask;
+ return adapter_gpio_config[gpio_index].gpio_num != ADAPTER_GPIO_NOT_SET;
+}
- if (tms)
- dataport_value |= cable->tms_mask;
+static void set_pin_state(enum adapter_gpio_config_index gpio_index,
+ bool state)
+{
+ if (state ^ adapter_gpio_config[gpio_index].active_low)
+ dataport_value |= OUTPUT_BITMASK(gpio_index);
else
- dataport_value &= ~cable->tms_mask;
+ dataport_value &= ~OUTPUT_BITMASK(gpio_index);
+}
- if (tdi)
- dataport_value |= cable->tdi_mask;
- else
- dataport_value &= ~cable->tdi_mask;
+static int parport_write(int tck, int tms, int tdi)
+{
+ set_pin_state(ADAPTER_GPIO_IDX_TCK, tck == 1);
+ set_pin_state(ADAPTER_GPIO_IDX_TMS, tms == 1);
+ set_pin_state(ADAPTER_GPIO_IDX_TDI, tdi == 1);
- while (i-- > 0)
+ for (int i = 0; i < wait_states + 1; i++)
parport_write_data();
return ERROR_OK;
@@ -177,15 +138,11 @@ static int parport_reset(int trst, int srst)
{
LOG_DEBUG("trst: %i, srst: %i", trst, srst);
- if (trst == 0)
- dataport_value |= cable->trst_mask;
- else if (trst == 1)
- dataport_value &= ~cable->trst_mask;
+ if (is_gpio_configured(ADAPTER_GPIO_IDX_TRST))
+ set_pin_state(ADAPTER_GPIO_IDX_TRST, trst == 0);
- if (srst == 0)
- dataport_value |= cable->srst_mask;
- else if (srst == 1)
- dataport_value &= ~cable->srst_mask;
+ if (is_gpio_configured(ADAPTER_GPIO_IDX_SRST))
+ set_pin_state(ADAPTER_GPIO_IDX_SRST, srst == 0);
parport_write_data();
@@ -194,11 +151,10 @@ static int parport_reset(int trst, int srst)
static int parport_led(bool on)
{
- if (on)
- dataport_value |= cable->led_mask;
- else
- dataport_value &= ~cable->led_mask;
+ if (!is_gpio_configured(ADAPTER_GPIO_IDX_LED))
+ return ERROR_OK;
+ set_pin_state(ADAPTER_GPIO_IDX_LED, on);
parport_write_data();
return ERROR_OK;
@@ -213,11 +169,12 @@ static int parport_speed(int speed)
static int parport_khz(int khz, int *jtag_speed)
{
if (!khz) {
- LOG_DEBUG("RCLK not supported");
+ LOG_ERROR("RCLK is not supported by the adapter");
return ERROR_FAIL;
}
*jtag_speed = 499999 / (khz * parport_toggling_time_ns);
+
return ERROR_OK;
}
@@ -226,32 +183,35 @@ static int parport_speed_div(int speed, int *khz)
uint32_t denominator = (speed + 1) * parport_toggling_time_ns;
*khz = (499999 + denominator) / denominator;
+
return ERROR_OK;
}
#if PARPORT_USE_GIVEIO == 1
-static int parport_get_giveio_access(void)
+static bool parport_get_giveio_access(void)
{
- HANDLE h;
OSVERSIONINFO version;
version.dwOSVersionInfoSize = sizeof(version);
if (!GetVersionEx(&version)) {
errno = EINVAL;
- return -1;
+ return false;
}
+
if (version.dwPlatformId != VER_PLATFORM_WIN32_NT)
- return 0;
+ return true;
+
+ HANDLE h = CreateFile("\\\\.\\giveio", GENERIC_READ, 0, NULL, OPEN_EXISTING,
+ FILE_ATTRIBUTE_NORMAL, NULL);
- h = CreateFile("\\\\.\\giveio", GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (h == INVALID_HANDLE_VALUE) {
errno = ENODEV;
- return -1;
+ return false;
}
CloseHandle(h);
- return 0;
+ return true;
}
#endif
@@ -261,80 +221,121 @@ static const struct bitbang_interface parport_bitbang = {
.blink = &parport_led,
};
+static const struct {
+ enum adapter_gpio_config_index gpio_index;
+ bool required;
+} all_signals[] = {
+ { ADAPTER_GPIO_IDX_TDO, true },
+ { ADAPTER_GPIO_IDX_TDI, true },
+ { ADAPTER_GPIO_IDX_TMS, true },
+ { ADAPTER_GPIO_IDX_TCK, true },
+ { ADAPTER_GPIO_IDX_TRST, false },
+ { ADAPTER_GPIO_IDX_SRST, false },
+ { ADAPTER_GPIO_IDX_LED, false },
+ { ADAPTER_GPIO_IDX_USER0, false },
+};
+
static int parport_init(void)
{
- const struct cable *cur_cable;
-#if PARPORT_USE_PPDEV == 1
- char buffer[256];
-#endif
+ adapter_gpio_config = adapter_gpio_get_config();
- cur_cable = cables;
+ // Check if all signals are configured properly.
+ for (size_t i = 0; i < ARRAY_SIZE(all_signals); i++) {
+ const enum adapter_gpio_config_index gpio_index = all_signals[i].gpio_index;
+ const struct adapter_gpio_config gpio = adapter_gpio_config[gpio_index];
- if (!parport_cable) {
- parport_cable = strdup("wiggler");
- LOG_WARNING("No parport cable specified, using default 'wiggler'");
- }
+ if (gpio.gpio_num == ADAPTER_GPIO_NOT_SET) {
+ if (all_signals[i].required) {
+ LOG_ERROR("The signal '%s' is required and must be configured",
+ adapter_gpio_get_name(gpio_index));
+ return ERROR_FAIL;
+ }
- while (cur_cable->name) {
- if (!strcmp(cur_cable->name, parport_cable)) {
- cable = cur_cable;
- break;
+ continue;
}
- cur_cable++;
- }
- if (!cable) {
- LOG_ERROR("No matching cable found for %s", parport_cable);
- return ERROR_JTAG_INIT_FAILED;
+ if (gpio_index == ADAPTER_GPIO_IDX_TDO) {
+ if (gpio.gpio_num < 10 || gpio.gpio_num > 15 || gpio.gpio_num == 14) {
+ LOG_ERROR("The '%s' signal pin must be 10, 11, 12, 13, or 15",
+ adapter_gpio_get_name(gpio_index));
+ return ERROR_FAIL;
+ }
+ } else {
+ if (gpio.gpio_num < 2 || gpio.gpio_num > 9) {
+ LOG_ERROR("The '%s' signal pin must be 2, 3, 4, 5, 6, 7, 8, or 9",
+ adapter_gpio_get_name(gpio_index));
+ return ERROR_FAIL;
+ }
+ }
}
- dataport_value = cable->port_init;
+ // Initialize signal pin states.
+ for (size_t i = 0; i < ARRAY_SIZE(all_signals); i++) {
+ const enum adapter_gpio_config_index gpio_index = all_signals[i].gpio_index;
+ const struct adapter_gpio_config gpio = adapter_gpio_config[gpio_index];
+
+ // The TDO (input) and LED (controlled by the adapter) pins cannot be
+ // initialized.
+ if (gpio_index == ADAPTER_GPIO_IDX_TDO || gpio_index == ADAPTER_GPIO_IDX_LED)
+ continue;
+
+ // Do not initialize unconfigured GPIO pins.
+ if (gpio.gpio_num == ADAPTER_GPIO_NOT_SET)
+ continue;
+
+ if (gpio.init_state == ADAPTER_GPIO_INIT_STATE_ACTIVE)
+ set_pin_state(gpio_index, true);
+ else if (gpio.init_state == ADAPTER_GPIO_INIT_STATE_INACTIVE)
+ set_pin_state(gpio_index, false);
+ }
#if PARPORT_USE_PPDEV == 1
if (device_handle > 0) {
- LOG_ERROR("device is already opened");
+ LOG_ERROR("Parallel port is already open");
return ERROR_JTAG_INIT_FAILED;
}
+ char device_path[256];
+
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
- LOG_DEBUG("opening /dev/ppi%d...", parport_port);
+ snprintf(device_path, sizeof(device_path), "/dev/ppi%d", parport_port);
+#else
+ snprintf(device_path, sizeof(device_path), "/dev/parport%d", parport_port);
+#endif /* __FreeBSD__, __FreeBSD_kernel__ */
- snprintf(buffer, 256, "/dev/ppi%d", parport_port);
- device_handle = open(buffer, O_WRONLY);
-#else /* not __FreeBSD__, __FreeBSD_kernel__ */
- LOG_DEBUG("opening /dev/parport%d...", parport_port);
+ LOG_DEBUG("Using parallel port %s", device_path);
- snprintf(buffer, 256, "/dev/parport%d", parport_port);
- device_handle = open(buffer, O_WRONLY);
-#endif /* __FreeBSD__, __FreeBSD_kernel__ */
+ device_handle = open(device_path, O_WRONLY);
if (device_handle < 0) {
int err = errno;
- LOG_ERROR("cannot open device. check it exists and that user read and write rights are set. errno=%d", err);
+ LOG_ERROR("Failed to open parallel port %s (errno = %d)", device_path,
+ err);
+ LOG_ERROR("Check whether the device exists and if you have the required access rights");
return ERROR_JTAG_INIT_FAILED;
}
- LOG_DEBUG("...open");
-
#if !defined(__FreeBSD__) && !defined(__FreeBSD_kernel__)
- int i = ioctl(device_handle, PPCLAIM);
+ int retval = ioctl(device_handle, PPCLAIM);
- if (i < 0) {
- LOG_ERROR("cannot claim device");
+ if (retval < 0) {
+ LOG_ERROR("Failed to claim parallel port %s", device_path);
return ERROR_JTAG_INIT_FAILED;
}
- i = PARPORT_MODE_COMPAT;
- i = ioctl(device_handle, PPSETMODE, &i);
- if (i < 0) {
- LOG_ERROR(" cannot set compatible mode to device");
+ int value = PARPORT_MODE_COMPAT;
+ retval = ioctl(device_handle, PPSETMODE, &value);
+
+ if (retval < 0) {
+ LOG_ERROR("Cannot set compatible mode to device");
return ERROR_JTAG_INIT_FAILED;
}
- i = IEEE1284_MODE_COMPAT;
- i = ioctl(device_handle, PPNEGOT, &i);
- if (i < 0) {
- LOG_ERROR("cannot set compatible 1284 mode to device");
+ value = IEEE1284_MODE_COMPAT;
+ retval = ioctl(device_handle, PPNEGOT, &value);
+
+ if (retval < 0) {
+ LOG_ERROR("Cannot set compatible 1284 mode to device");
return ERROR_JTAG_INIT_FAILED;
}
#endif /* not __FreeBSD__, __FreeBSD_kernel__ */
@@ -342,24 +343,24 @@ static int parport_init(void)
#else /* not PARPORT_USE_PPDEV */
if (!parport_port) {
parport_port = 0x378;
- LOG_WARNING("No parport port specified, using default '0x378' (LPT1)");
+ LOG_WARNING("No parallel port specified, using default 0x378 (LPT1)");
}
+ LOG_DEBUG("Using parallel port 0x%x", parport_port);
+
dataport = parport_port;
statusport = parport_port + 1;
- LOG_DEBUG("requesting privileges for parallel port 0x%lx...", dataport);
#if PARPORT_USE_GIVEIO == 1
- if (parport_get_giveio_access() != 0) {
+ if (!parport_get_giveio_access()) {
#else /* PARPORT_USE_GIVEIO */
if (ioperm(dataport, 3, 1) != 0) {
#endif /* PARPORT_USE_GIVEIO */
- LOG_ERROR("missing privileges for direct i/o");
+ LOG_ERROR("Missing privileges for direct I/O");
return ERROR_JTAG_INIT_FAILED;
}
- LOG_DEBUG("...privileges granted");
- // Make sure parallel port is in right mode (clear tristate and interrupt.
+ // Make sure parallel port is in right mode (clear tristate and interrupt).
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
outb(parport_port + 2, 0x0);
#else
@@ -370,8 +371,10 @@ static int parport_init(void)
if (parport_reset(0, 0) != ERROR_OK)
return ERROR_FAIL;
+
if (parport_write(0, 0, 0) != ERROR_OK)
return ERROR_FAIL;
+
if (parport_led(true) != ERROR_OK)
return ERROR_FAIL;
@@ -382,56 +385,59 @@ static int parport_init(void)
static int parport_quit(void)
{
- if (parport_led(false) != ERROR_OK)
- return ERROR_FAIL;
+ // Deinitialize signal pin states.
+ for (size_t i = 0; i < ARRAY_SIZE(all_signals); i++) {
+ const enum adapter_gpio_config_index gpio_index = all_signals[i].gpio_index;
+ const struct adapter_gpio_config gpio = adapter_gpio_config[gpio_index];
+
+ // The TDO (input) and LED (controlled by the adapter) pins cannot be
+ // deinitialized.
+ if (gpio_index == ADAPTER_GPIO_IDX_TDO || gpio_index == ADAPTER_GPIO_IDX_LED)
+ continue;
+
+ // Do not deinitialize unconfigured GPIO pins.
+ if (gpio.gpio_num == ADAPTER_GPIO_NOT_SET)
+ continue;
+
+ if (gpio.exit_state == ADAPTER_GPIO_EXIT_STATE_ACTIVE)
+ set_pin_state(gpio_index, true);
+ else if (gpio.exit_state == ADAPTER_GPIO_EXIT_STATE_INACTIVE)
+ set_pin_state(gpio_index, false);
+ }
- if (parport_exit) {
- dataport_value = cable->port_exit;
+ if (parport_write_exit_state)
parport_write_data();
- }
- free(parport_cable);
- parport_cable = NULL;
+ if (parport_led(false) != ERROR_OK)
+ return ERROR_FAIL;
return ERROR_OK;
}
COMMAND_HANDLER(parport_handle_port_command)
{
- if (CMD_ARGC == 1) {
- // Only if the port wasn't overwritten by cmdline.
- if (!parport_port) {
- COMMAND_PARSE_NUMBER(u16, CMD_ARGV[0], parport_port);
- } else {
- LOG_ERROR("The parport port was already configured!");
- return ERROR_FAIL;
- }
+ if (CMD_ARGC != 1)
+ return ERROR_COMMAND_SYNTAX_ERROR;
+
+ // Only if the port wasn't overwritten by command-line.
+ if (parport_port > 0) {
+ command_print(CMD, "The parallel port is already configured");
+ return ERROR_FAIL;
}
- command_print(CMD, "parport port = 0x%" PRIx16, parport_port);
+ COMMAND_PARSE_NUMBER(u16, CMD_ARGV[0], parport_port);
return ERROR_OK;
}
+// This command is only for backward compatibility and will be removed in the
+// future.
COMMAND_HANDLER(parport_handle_cable_command)
{
- if (!CMD_ARGC)
- return ERROR_OK;
-
- // Only if the cable name wasn't overwritten by cmdline.
- if (!parport_cable) {
- // TODO: REVISIT first verify that it's listed in cables[].
- parport_cable = malloc(strlen(CMD_ARGV[0]) + sizeof(char));
- if (!parport_cable) {
- LOG_ERROR("Out of memory");
- return ERROR_FAIL;
- }
- strcpy(parport_cable, CMD_ARGV[0]);
- }
-
- // TODO: REVISIT it's probably worth returning the current value.
+ if (CMD_ARGC != 1)
+ return ERROR_COMMAND_SYNTAX_ERROR;
- return ERROR_OK;
+ return command_run_linef(CMD_CTX, "parport_select_cable %s", CMD_ARGV[0]);
}
COMMAND_HANDLER(parport_handle_write_on_exit_command)
@@ -439,40 +445,39 @@ COMMAND_HANDLER(parport_handle_write_on_exit_command)
if (CMD_ARGC != 1)
return ERROR_COMMAND_SYNTAX_ERROR;
- COMMAND_PARSE_ON_OFF(CMD_ARGV[0], parport_exit);
+ LOG_WARNING("DEPRECATED: 'parport write_on_exit' will be removed in the future, use the 'adapter gpio' command to configure the exit state for pins");
+
+ COMMAND_PARSE_ON_OFF(CMD_ARGV[0], parport_write_exit_state);
return ERROR_OK;
}
COMMAND_HANDLER(parport_handle_toggling_time_command)
{
- if (CMD_ARGC == 1) {
- uint32_t ns;
- int retval = parse_u32(CMD_ARGV[0], &ns);
+ if (CMD_ARGC != 1)
+ return ERROR_COMMAND_SYNTAX_ERROR;
- if (retval != ERROR_OK)
- return retval;
+ uint32_t toggling_time;
- if (!ns) {
- LOG_ERROR("0 ns is not a valid parport toggling time");
- return ERROR_FAIL;
- }
+ COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], toggling_time);
- parport_toggling_time_ns = ns;
- retval = adapter_get_speed(&wait_states);
- if (retval != ERROR_OK) {
- /*
- * If adapter_get_speed fails then the clock_mode has
- * not been configured, this happens if toggling_time is
- * called before the adapter speed is set.
- */
- LOG_INFO("no parport speed set - defaulting to zero wait states");
- wait_states = 0;
- }
+ if (!toggling_time) {
+ command_print(CMD, "toggling time must not be 0 ns");
+ return ERROR_COMMAND_ARGUMENT_INVALID;
}
- command_print(CMD, "parport toggling time = %" PRIu32 " ns",
- parport_toggling_time_ns);
+ parport_toggling_time_ns = toggling_time;
+ int retval = adapter_get_speed(&wait_states);
+
+ if (retval != ERROR_OK) {
+ /*
+ * If adapter_get_speed fails then the clock_mode has not been
+ * configured, this happens if toggling_time is called before the
+ * adapter speed is set.
+ */
+ LOG_INFO("No parallel port speed set, using zero wait states");
+ wait_states = 0;
+ }
return ERROR_OK;
}
@@ -482,35 +487,31 @@ static const struct command_registration parport_subcommand_handlers[] = {
.name = "port",
.handler = parport_handle_port_command,
.mode = COMMAND_CONFIG,
- .help = "Display the address of the I/O port (e.g. 0x378) "
- "or the number of the '/dev/parport' device used. "
- "If a parameter is provided, first change that port.",
- .usage = "[port_number]",
+ .help = "Configure the address of the I/O port (e.g. 0x378) "
+ "or the number of the '/dev/parport' (Linux) or '/dev/ppi' (FreeBSD) device used",
+ .usage = "port_number",
},
{
.name = "cable",
.handler = parport_handle_cable_command,
.mode = COMMAND_CONFIG,
.help = "Set the layout of the parallel port cable "
- "used to connect to the target.",
- // TODO: REVISIT there's no way to list layouts we know.
- .usage = "[layout]",
+ "used to connect to the target",
+ .usage = "cable",
},
{
.name = "write_on_exit",
.handler = parport_handle_write_on_exit_command,
.mode = COMMAND_CONFIG,
- .help = "Configure the parallel driver to write "
- "a known value to the parallel interface on exit.",
+ .help = "Configure the driver to write a value to the parallel port on shutdown",
.usage = "('on'|'off')",
},
{
.name = "toggling_time",
.handler = parport_handle_toggling_time_command,
.mode = COMMAND_CONFIG,
- .help = "Displays or assigns how many nanoseconds it "
- "takes for the hardware to toggle TCK.",
- .usage = "[nanoseconds]",
+ .help = "Configure how many nanoseconds it takes for the hardware to toggle TCK",
+ .usage = "time",
},
COMMAND_REGISTRATION_DONE
};
diff --git a/src/jtag/startup.tcl b/src/jtag/startup.tcl
index 88d802fcb..5c466c628 100644
--- a/src/jtag/startup.tcl
+++ b/src/jtag/startup.tcl
@@ -359,6 +359,27 @@ proc parport_cable args {
eval parport cable $args
}
+lappend _telnet_autocomplete_skip parport_select_cable
+proc parport_select_cable {cable} {
+ echo "DEPRECATED! Do not use 'parport cable' but use a cable configuration file in interface/parport"
+
+ switch $cable {
+ "wiggler" { source [find interface/parport/wiggler.cfg] }
+ "wiggler2" { source [find interface/parport/wiggler2.cfg] }
+ "wiggler_ntrst_inverted" { source [find interface/parport/wiggler-ntrst-inverted.cfg] }
+ "old_amt_wiggler" { source [find interface/parport/amt-wiggler-old.cfg ] }
+ "arm-jtag" { source [find interface/parport/arm-jtag.cfg] }
+ "chameleon" { source [find interface/parport/chameleon.cfg] }
+ "dlc5" { source [find interface/parport/dlc5.cfg] }
+ "triton" { source [find interface/parport/triton.cfg] }
+ "lattice" { source [find interface/parport/lattice.cfg] }
+ "flashlink" { source [find interface/parport/flashlink.cfg] }
+ "altium" { source [find interface/parport/altium.cfg] }
+ "aspo" { source [find interface/parport/aspo.cfg] }
+ default { error "invalid parallel port cable '$cable'" }
+ }
+}
+
lappend _telnet_autocomplete_skip parport_write_on_exit
proc parport_write_on_exit args {
echo "DEPRECATED! use 'parport write_on_exit' not 'parport_write_on_exit'"
diff --git a/tcl/interface/parport/altium.cfg b/tcl/interface/parport/altium.cfg
new file mode 100644
index 000000000..9389d47ef
--- /dev/null
+++ b/tcl/interface/parport/altium.cfg
@@ -0,0 +1,26 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+# Altium Universal JTAG cable. Set the cable to Xilinx Mode and wire to target as follows:
+#
+# HARD TCK - Target TCK
+# HARD TMS - Target TMS
+# HARD TDI - Target TDI
+# HARD TDO - Target TDO
+# SOFT TCK - Target TRST
+# SOFT TDI - Target SRST
+
+adapter driver parport
+
+adapter gpio tdo 13 -exit-inactive
+adapter gpio trst 7 -active-high -exit-inactive
+adapter gpio tms 4 -exit-inactive
+adapter gpio tck 3 -exit-inactive
+adapter gpio tdi 2 -exit-inactive
+adapter gpio srst 9 -active-high -exit-inactive
+adapter gpio led 5 -exit-inactive
+
+# Non-JTAG signal that is only necessary for the functionality of the adapter.
+# For details, refer to the documentation of the adapter.
+adapter gpio user0 6 -init-active -exit-inactive
+
+transport select jtag
diff --git a/tcl/interface/parport/amt-wiggler-old.cfg b/tcl/interface/parport/amt-wiggler-old.cfg
new file mode 100644
index 000000000..bba30c8b2
--- /dev/null
+++ b/tcl/interface/parport/amt-wiggler-old.cfg
@@ -0,0 +1,16 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+adapter driver parport
+
+adapter gpio tdo 11 -active-low -exit-inactive
+adapter gpio trst 2 -exit-inactive
+adapter gpio tms 3 -exit-inactive
+adapter gpio tck 4 -exit-inactive
+adapter gpio tdi 5 -exit-inactive
+adapter gpio srst 6 -exit-inactive
+
+# Non-JTAG signal that is only necessary for the functionality of the adapter.
+# For details, refer to the documentation of the adapter.
+adapter gpio user0 9 -init-active -exit-active
+
+transport select jtag
diff --git a/tcl/interface/parport/arm-jtag.cfg b/tcl/interface/parport/arm-jtag.cfg
new file mode 100644
index 000000000..3b2a10daa
--- /dev/null
+++ b/tcl/interface/parport/arm-jtag.cfg
@@ -0,0 +1,16 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+adapter driver parport
+
+adapter gpio tdo 11 -active-low -exit-inactive
+adapter gpio trst 2 -exit-inactive
+adapter gpio tms 3 -exit-inactive
+adapter gpio tck 4 -exit-inactive
+adapter gpio tdi 5 -exit-inactive
+adapter gpio srst 6 -active-high -exit-inactive
+
+# Non-JTAG signal that is only necessary for the functionality of the adapter.
+# For details, refer to the documentation of the adapter.
+adapter gpio user0 9 -init-active -exit-active
+
+transport select jtag
diff --git a/tcl/interface/parport/aspo.cfg b/tcl/interface/parport/aspo.cfg
new file mode 100644
index 000000000..0d14719db
--- /dev/null
+++ b/tcl/interface/parport/aspo.cfg
@@ -0,0 +1,12 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+adapter driver parport
+
+adapter gpio tdo 13 -exit-inactive
+adapter gpio trst 2 -init-active -exit-active
+adapter gpio tms 4 -active-low -exit-active
+adapter gpio tck 5 -exit-inactive
+adapter gpio tdi 3 -active-low -init-active -exit-active
+adapter gpio srst 6 -init-active -exit-active
+
+transport select jtag
diff --git a/tcl/interface/parport/chameleon.cfg b/tcl/interface/parport/chameleon.cfg
new file mode 100644
index 000000000..f0ebcdd50
--- /dev/null
+++ b/tcl/interface/parport/chameleon.cfg
@@ -0,0 +1,10 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+adapter driver parport
+
+adapter gpio tdo 11 -active-low -exit-inactive
+adapter gpio tms 4 -exit-inactive
+adapter gpio tck 2 -exit-inactive
+adapter gpio tdi 3 -exit-inactive
+
+transport select jtag
diff --git a/tcl/interface/parport/dlc5.cfg b/tcl/interface/parport/dlc5.cfg
index 24acea7a9..fb8494321 100644
--- a/tcl/interface/parport/dlc5.cfg
+++ b/tcl/interface/parport/dlc5.cfg
@@ -1,17 +1,16 @@
# SPDX-License-Identifier: GPL-2.0-or-later
-#
# Xilinx Parallel Cable III 'DLC 5' (and various clones)
-#
-# http://www.xilinx.com/itp/xilinx4/data/docs/pac/appendixb.html
-#
-
-if { [info exists PARPORTADDR] } {
- set _PARPORTADDR $PARPORTADDR
-} else {
- set _PARPORTADDR 0
-}
adapter driver parport
-parport port $_PARPORTADDR
-parport cable dlc5
+
+adapter gpio tdo 13 -exit-inactive
+adapter gpio tms 4 -exit-inactive
+adapter gpio tck 3 -exit-inactive
+adapter gpio tdi 2 -exit-inactive
+
+# Non-JTAG signal that is only necessary for the functionality of the adapter.
+# For details, refer to the documentation of the adapter.
+adapter gpio user0 6 -init-active -exit-active
+
+transport select jtag
diff --git a/tcl/interface/parport/flashlink.cfg b/tcl/interface/parport/flashlink.cfg
new file mode 100644
index 000000000..b1a261d0b
--- /dev/null
+++ b/tcl/interface/parport/flashlink.cfg
@@ -0,0 +1,12 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+adapter driver parport
+
+adapter gpio tdo 12 -active-low -exit-inactive
+adapter gpio trst 6 -exit-inactive
+adapter gpio tms 3 -exit-inactive
+adapter gpio tck 2 -exit-inactive
+adapter gpio tdi 4 -exit-inactive
+adapter gpio srst 7 -exit-inactive
+
+transport select jtag
diff --git a/tcl/interface/parport/lattice.cfg b/tcl/interface/parport/lattice.cfg
new file mode 100644
index 000000000..aa7322812
--- /dev/null
+++ b/tcl/interface/parport/lattice.cfg
@@ -0,0 +1,12 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+adapter driver parport
+
+adapter gpio tdo 10 -exit-inactive
+adapter gpio trst 6 -active-high -init-active -exit-active
+adapter gpio tms 4 -exit-inactive
+adapter gpio tck 3 -exit-inactive
+adapter gpio tdi 2 -exit-inactive
+adapter gpio srst 5 -active-high -init-active -exit-active
+
+transport select jtag
diff --git a/tcl/interface/parport/triton.cfg b/tcl/interface/parport/triton.cfg
new file mode 100644
index 000000000..b24d223a9
--- /dev/null
+++ b/tcl/interface/parport/triton.cfg
@@ -0,0 +1,11 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+adapter driver parport
+
+adapter gpio tdo 11 -active-low -exit-inactive
+adapter gpio trst 5 -active-high -exit-inactive
+adapter gpio tms 4 -exit-inactive
+adapter gpio tck 2 -exit-inactive
+adapter gpio tdi 3 -exit-inactive
+
+transport select jtag
diff --git a/tcl/interface/parport/wiggler-ntrst-inverted.cfg b/tcl/interface/parport/wiggler-ntrst-inverted.cfg
new file mode 100644
index 000000000..3b2fc0f28
--- /dev/null
+++ b/tcl/interface/parport/wiggler-ntrst-inverted.cfg
@@ -0,0 +1,16 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+adapter driver parport
+
+adapter gpio tdo 11 -active-low -exit-inactive
+adapter gpio trst 6 -exit-inactive
+adapter gpio tms 3 -exit-inactive
+adapter gpio tck 4 -exit-inactive
+adapter gpio tdi 5 -exit-inactive
+adapter gpio srst 2 -exit-inactive
+
+# Non-JTAG signal that is only necessary for the functionality of the adapter.
+# For details, refer to the documentation of the adapter.
+adapter gpio user0 9 -init-active -exit-active
+
+transport select jtag
diff --git a/tcl/interface/parport/wiggler.cfg b/tcl/interface/parport/wiggler.cfg
index b9fceeb85..84c1c8302 100644
--- a/tcl/interface/parport/wiggler.cfg
+++ b/tcl/interface/parport/wiggler.cfg
@@ -1,21 +1,16 @@
# SPDX-License-Identifier: GPL-2.0-or-later
-#
-# Parallel port wiggler (many clones available) on port 0x378
-#
-# Addresses: 0x378/LPT1 or 0x278/LPT2 ...
-#
+adapter driver parport
-if { [info exists PARPORTADDR] } {
- set _PARPORTADDR $PARPORTADDR
-} else {
- if {$tcl_platform(platform) eq "windows"} {
- set _PARPORTADDR 0x378
- } {
- set _PARPORTADDR 0
- }
-}
+adapter gpio tdo 11 -active-low -exit-inactive
+adapter gpio trst 6 -active-high -exit-inactive
+adapter gpio tms 3 -exit-inactive
+adapter gpio tck 4 -exit-inactive
+adapter gpio tdi 5 -exit-inactive
+adapter gpio srst 2 -exit-inactive
-adapter driver parport
-parport port $_PARPORTADDR
-parport cable wiggler
+# Non-JTAG signal that is only necessary for the functionality of the adapter.
+# For details, refer to the documentation of the adapter.
+adapter gpio user0 9 -init-active -exit-active
+
+transport select jtag
diff --git a/tcl/interface/parport/wiggler2.cfg b/tcl/interface/parport/wiggler2.cfg
new file mode 100644
index 000000000..839e7f9b4
--- /dev/null
+++ b/tcl/interface/parport/wiggler2.cfg
@@ -0,0 +1,17 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+adapter driver parport
+
+adapter gpio tdo 11 -active-low -exit-inactive
+adapter gpio trst 6 -active-high -exit-inactive
+adapter gpio tms 3 -exit-inactive
+adapter gpio tck 4 -exit-inactive
+adapter gpio tdi 5 -exit-inactive
+adapter gpio srst 2 -exit-inactive
+adapter gpio led 7 -exit-inactive
+
+# Non-JTAG signal that is only necessary for the functionality of the adapter.
+# For details, refer to the documentation of the adapter.
+adapter gpio user0 9 -init-active -exit-inactive
+
+transport select jtag
-----------------------------------------------------------------------
Summary of changes:
doc/openocd.texi | 119 +++----
src/jtag/drivers/parport.c | 427 ++++++++++++-----------
src/jtag/startup.tcl | 21 ++
tcl/interface/parport/altium.cfg | 26 ++
tcl/interface/parport/amt-wiggler-old.cfg | 16 +
tcl/interface/parport/arm-jtag.cfg | 16 +
tcl/interface/parport/aspo.cfg | 12 +
tcl/interface/parport/chameleon.cfg | 10 +
tcl/interface/parport/dlc5.cfg | 23 +-
tcl/interface/parport/flashlink.cfg | 12 +
tcl/interface/parport/lattice.cfg | 12 +
tcl/interface/parport/triton.cfg | 11 +
tcl/interface/parport/wiggler-ntrst-inverted.cfg | 16 +
tcl/interface/parport/wiggler.cfg | 29 +-
tcl/interface/parport/wiggler2.cfg | 17 +
15 files changed, 461 insertions(+), 306 deletions(-)
create mode 100644 tcl/interface/parport/altium.cfg
create mode 100644 tcl/interface/parport/amt-wiggler-old.cfg
create mode 100644 tcl/interface/parport/arm-jtag.cfg
create mode 100644 tcl/interface/parport/aspo.cfg
create mode 100644 tcl/interface/parport/chameleon.cfg
create mode 100644 tcl/interface/parport/flashlink.cfg
create mode 100644 tcl/interface/parport/lattice.cfg
create mode 100644 tcl/interface/parport/triton.cfg
create mode 100644 tcl/interface/parport/wiggler-ntrst-inverted.cfg
create mode 100644 tcl/interface/parport/wiggler2.cfg
hooks/post-receive
--
Main OpenOCD repository
|
|
From: openocd-gerrit <ope...@us...> - 2025-09-06 08:19:13
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Main OpenOCD repository".
The branch, master has been updated
via 3bec165e2590ae72bb67ba4913b92e18b1275600 (commit)
via d02389bbfaf0fe78e9944194e08a389447b8f84f (commit)
from fcff4b712c53a6169f0f96dd63f0adb1b12a1789 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 3bec165e2590ae72bb67ba4913b92e18b1275600
Author: Marc Schink <de...@za...>
Date: Thu Jul 31 07:48:46 2025 +0000
adapter: Add 'user0' GPIO signal
Add a user-specific signal 'user0' which can be used for custom
functionality.
For now, only a single user-specific signal is supported. Additional
signals 'userX' or a more generic handling can be added in the future.
Also, the signal state can only be configured during the adapter
initialization and termination. Commands to change the signal state at
run-time may be added in the future.
Change-Id: I3f31242f6a693e11565542c3bd4521a245b4ff95
Signed-off-by: Marc Schink <de...@za...>
Reviewed-on: https://review.openocd.org/c/openocd/+/9088
Reviewed-by: Antonio Borneo <bor...@gm...>
Tested-by: jenkins
diff --git a/doc/openocd.texi b/doc/openocd.texi
index 8ebb468d4..1e9f80dce 100644
--- a/doc/openocd.texi
+++ b/doc/openocd.texi
@@ -2440,7 +2440,7 @@ dict get [adapter list] ftdi
@deffn {Config Command} {adapter gpio [ @
@option{tdo} | @option{tdi} | @option{tms} | @option{tck} | @option{trst} | @
@option{swdio} | @option{swdio_dir} | @option{swclk} | @option{srst} | @
- @option{led} @
+ @option{led} | @option{user0} @
[ @
gpio_number | @option{-chip} chip_number | @
@option{-active-high} | @option{-active-low} | @
@@ -2460,6 +2460,7 @@ JTAG transport signals
@item @option{swdio_dir}: optional swdio buffer control signal
@item @option{srst}: system reset signal
@item @option{led}: optional activity led
+@item @option{user0}: optional, user-specific signal
@end itemize
diff --git a/src/jtag/adapter.c b/src/jtag/adapter.c
index 07560f0db..87c65719c 100644
--- a/src/jtag/adapter.c
+++ b/src/jtag/adapter.c
@@ -65,6 +65,7 @@ static const struct gpio_map {
[ADAPTER_GPIO_IDX_TRST] = { "trst", ADAPTER_GPIO_DIRECTION_OUTPUT, false, true, true },
[ADAPTER_GPIO_IDX_SRST] = { "srst", ADAPTER_GPIO_DIRECTION_OUTPUT, false, true, true },
[ADAPTER_GPIO_IDX_LED] = { "led", ADAPTER_GPIO_DIRECTION_OUTPUT, true, true, true },
+ [ADAPTER_GPIO_IDX_USER0] = { "user0", ADAPTER_GPIO_DIRECTION_BIDIRECTIONAL, true, true, true },
};
static int adapter_config_khz(unsigned int khz);
diff --git a/src/jtag/adapter.h b/src/jtag/adapter.h
index ed58fe5aa..d76ea5e32 100644
--- a/src/jtag/adapter.h
+++ b/src/jtag/adapter.h
@@ -60,6 +60,7 @@ enum adapter_gpio_config_index {
ADAPTER_GPIO_IDX_SWCLK,
ADAPTER_GPIO_IDX_SRST,
ADAPTER_GPIO_IDX_LED,
+ ADAPTER_GPIO_IDX_USER0,
ADAPTER_GPIO_IDX_NUM, /* must be the last item */
};
commit d02389bbfaf0fe78e9944194e08a389447b8f84f
Author: Marc Schink <de...@za...>
Date: Sun Jun 15 10:52:49 2025 +0000
adapter: Add support for 'exit state' of GPIO signal
In addition to a signal's 'init state', add support to configure its
'exit state'. This option determines the state and configuration of a
pin when the adapter terminates its operation.
Change-Id: I0577ed9e3bc79715290b4e6a21e3f64c66f2ff9a
Signed-off-by: Marc Schink <de...@za...>
Reviewed-on: https://review.openocd.org/c/openocd/+/9087
Tested-by: jenkins
Reviewed-by: Antonio Borneo <bor...@gm...>
diff --git a/doc/openocd.texi b/doc/openocd.texi
index 6c7aa86ec..8ebb468d4 100644
--- a/doc/openocd.texi
+++ b/doc/openocd.texi
@@ -2447,6 +2447,7 @@ dict get [adapter list] ftdi
@option{-push-pull} | @option{-open-drain} | @option{-open-source} | @
@option{-pull-none} | @option{-pull-up} | @option{-pull-down} | @
@option{-init-inactive} | @option{-init-active} | @option{-init-input} @
+ @option{-exit-inactive} | @option{-exit-active} | @option{-exit-input} | @option{-exit-no-change} @
] ]}
Define the GPIO mapping that the adapter will use. The following signals can be
@@ -2481,11 +2482,14 @@ equivalent to issuing the single command @command{gpio led 7 -chip 1
signals which are inputs. The drive mode for the srst and trst signals must be
set with the @command{adapter reset_config} command. It is not permissible to
set the initial state of swdio_dir as it is derived from the initial state of
-swdio. The command @command{adapter gpio} prints the current configuration for
-all GPIOs while the command @command{adapter gpio gpio_name} prints the current
-configuration for gpio_name. Not all adapters support this generic GPIO mapping,
-some require their own commands to define the GPIOs used. Adapters that support
-the generic mapping may not support all of the listed options.
+swdio. Accordingly, the final state before the adapter terminates its operation,
+so-called âexit stateâ, can be set. By default the state and configuration of an
+output pin is not changed when the driver terminates its operation. The
+command @command{adapter gpio} prints the current configuration for all GPIOs
+while the command @command{adapter gpio gpio_name} prints the current configuration
+for gpio_name. Not all adapters support this generic GPIO mapping, some require
+their own commands to define the GPIOs used. Adapters that support the generic
+mapping may not support all of the listed options.
@end deffn
@deffn {Command} {adapter name}
diff --git a/src/jtag/adapter.c b/src/jtag/adapter.c
index 6785a74ef..07560f0db 100644
--- a/src/jtag/adapter.c
+++ b/src/jtag/adapter.c
@@ -53,17 +53,18 @@ static const struct gpio_map {
enum adapter_gpio_direction direction;
bool permit_drive_option;
bool permit_init_state_option;
+ bool permit_exit_state_option;
} gpio_map[ADAPTER_GPIO_IDX_NUM] = {
- [ADAPTER_GPIO_IDX_TDO] = { "tdo", ADAPTER_GPIO_DIRECTION_INPUT, false, true, },
- [ADAPTER_GPIO_IDX_TDI] = { "tdi", ADAPTER_GPIO_DIRECTION_OUTPUT, true, true, },
- [ADAPTER_GPIO_IDX_TMS] = { "tms", ADAPTER_GPIO_DIRECTION_OUTPUT, true, true, },
- [ADAPTER_GPIO_IDX_TCK] = { "tck", ADAPTER_GPIO_DIRECTION_OUTPUT, true, true, },
- [ADAPTER_GPIO_IDX_SWDIO] = { "swdio", ADAPTER_GPIO_DIRECTION_BIDIRECTIONAL, true, true, },
- [ADAPTER_GPIO_IDX_SWDIO_DIR] = { "swdio_dir", ADAPTER_GPIO_DIRECTION_OUTPUT, true, false, },
- [ADAPTER_GPIO_IDX_SWCLK] = { "swclk", ADAPTER_GPIO_DIRECTION_OUTPUT, true, true, },
- [ADAPTER_GPIO_IDX_TRST] = { "trst", ADAPTER_GPIO_DIRECTION_OUTPUT, false, true, },
- [ADAPTER_GPIO_IDX_SRST] = { "srst", ADAPTER_GPIO_DIRECTION_OUTPUT, false, true, },
- [ADAPTER_GPIO_IDX_LED] = { "led", ADAPTER_GPIO_DIRECTION_OUTPUT, true, true, },
+ [ADAPTER_GPIO_IDX_TDO] = { "tdo", ADAPTER_GPIO_DIRECTION_INPUT, false, true, true },
+ [ADAPTER_GPIO_IDX_TDI] = { "tdi", ADAPTER_GPIO_DIRECTION_OUTPUT, true, true, true },
+ [ADAPTER_GPIO_IDX_TMS] = { "tms", ADAPTER_GPIO_DIRECTION_OUTPUT, true, true, true },
+ [ADAPTER_GPIO_IDX_TCK] = { "tck", ADAPTER_GPIO_DIRECTION_OUTPUT, true, true, true },
+ [ADAPTER_GPIO_IDX_SWDIO] = { "swdio", ADAPTER_GPIO_DIRECTION_BIDIRECTIONAL, true, true, true },
+ [ADAPTER_GPIO_IDX_SWDIO_DIR] = { "swdio_dir", ADAPTER_GPIO_DIRECTION_OUTPUT, true, false, false },
+ [ADAPTER_GPIO_IDX_SWCLK] = { "swclk", ADAPTER_GPIO_DIRECTION_OUTPUT, true, true, true },
+ [ADAPTER_GPIO_IDX_TRST] = { "trst", ADAPTER_GPIO_DIRECTION_OUTPUT, false, true, true },
+ [ADAPTER_GPIO_IDX_SRST] = { "srst", ADAPTER_GPIO_DIRECTION_OUTPUT, false, true, true },
+ [ADAPTER_GPIO_IDX_LED] = { "led", ADAPTER_GPIO_DIRECTION_OUTPUT, true, true, true },
};
static int adapter_config_khz(unsigned int khz);
@@ -850,6 +851,7 @@ static COMMAND_HELPER(helper_adapter_gpio_print_config, enum adapter_gpio_config
const char *drive = "";
const char *pull = "";
const char *init_state = "";
+ const char *exit_state = "";
if (gpio_config->gpio_num == ADAPTER_GPIO_NOT_SET) {
command_print(CMD, "adapter gpio %s: not configured", gpio_map[gpio_idx].name);
@@ -908,9 +910,27 @@ static COMMAND_HELPER(helper_adapter_gpio_print_config, enum adapter_gpio_config
}
}
- command_print(CMD, "adapter gpio %s (%s): num %u, chip %d, active-%s%s%s%s",
+ if (gpio_map[gpio_idx].permit_exit_state_option) {
+ switch (gpio_config->exit_state) {
+ case ADAPTER_GPIO_EXIT_STATE_NO_CHANGE:
+ exit_state = ", exit-state no-change";
+ break;
+ case ADAPTER_GPIO_EXIT_STATE_INACTIVE:
+ exit_state = ", exit-state inactive";
+ break;
+ case ADAPTER_GPIO_EXIT_STATE_ACTIVE:
+ exit_state = ", exit-state active";
+ break;
+ case ADAPTER_GPIO_EXIT_STATE_INPUT:
+ exit_state = ", exit-state input";
+ break;
+ }
+ }
+
+
+ command_print(CMD, "adapter gpio %s (%s): num %u, chip %d, active-%s%s%s%s%s",
gpio_map[gpio_idx].name, dir, gpio_config->gpio_num, (int)gpio_config->chip_num, active_state,
- drive, pull, init_state);
+ drive, pull, init_state, exit_state);
return ERROR_OK;
}
@@ -1031,6 +1051,31 @@ COMMAND_HANDLER(adapter_gpio_config_handler)
}
}
+ if (gpio_map[gpio_idx].permit_exit_state_option) {
+ if (strcmp(CMD_ARGV[i], "-exit-no-change") == 0) {
+ ++i;
+ gpio_config->exit_state = ADAPTER_GPIO_EXIT_STATE_NO_CHANGE;
+ continue;
+ }
+ if (strcmp(CMD_ARGV[i], "-exit-inactive") == 0) {
+ ++i;
+ gpio_config->exit_state = ADAPTER_GPIO_EXIT_STATE_INACTIVE;
+ continue;
+ }
+ if (strcmp(CMD_ARGV[i], "-exit-active") == 0) {
+ ++i;
+ gpio_config->exit_state = ADAPTER_GPIO_EXIT_STATE_ACTIVE;
+ continue;
+ }
+
+ if (gpio_map[gpio_idx].direction == ADAPTER_GPIO_DIRECTION_BIDIRECTIONAL &&
+ strcmp(CMD_ARGV[i], "-exit-input") == 0) {
+ ++i;
+ gpio_config->exit_state = ADAPTER_GPIO_EXIT_STATE_INPUT;
+ continue;
+ }
+ }
+
LOG_ERROR("illegal option for adapter %s %s: %s",
CMD_NAME, gpio_map[gpio_idx].name, CMD_ARGV[i]);
return ERROR_COMMAND_SYNTAX_ERROR;
@@ -1168,7 +1213,8 @@ static const struct command_registration adapter_command_handlers[] = {
"[-active-high|-active-low] "
"[-push-pull|-open-drain|-open-source] "
"[-pull-none|-pull-up|-pull-down]"
- "[-init-inactive|-init-active|-init-input] ]",
+ "[-init-inactive|-init-active|-init-input] ]"
+ "[-exit-no-change|-exit-inactive|-exit-active|-exit-input] ]",
},
COMMAND_REGISTRATION_DONE
};
diff --git a/src/jtag/adapter.h b/src/jtag/adapter.h
index 556952f8d..ed58fe5aa 100644
--- a/src/jtag/adapter.h
+++ b/src/jtag/adapter.h
@@ -33,6 +33,14 @@ enum adapter_gpio_init_state {
ADAPTER_GPIO_INIT_STATE_INPUT,
};
+/** Supported exit states for GPIO */
+enum adapter_gpio_exit_state {
+ ADAPTER_GPIO_EXIT_STATE_NO_CHANGE, /* Should be zero so it is the default state */
+ ADAPTER_GPIO_EXIT_STATE_INACTIVE,
+ ADAPTER_GPIO_EXIT_STATE_ACTIVE,
+ ADAPTER_GPIO_EXIT_STATE_INPUT,
+};
+
/** Supported pull directions for GPIO */
enum adapter_gpio_pull {
ADAPTER_GPIO_PULL_NONE,
@@ -61,6 +69,7 @@ struct adapter_gpio_config {
unsigned int chip_num;
enum adapter_gpio_drive_mode drive; /* For outputs only */
enum adapter_gpio_init_state init_state;
+ enum adapter_gpio_exit_state exit_state;
bool active_low;
enum adapter_gpio_pull pull;
};
-----------------------------------------------------------------------
Summary of changes:
doc/openocd.texi | 17 ++++++++-----
src/jtag/adapter.c | 73 ++++++++++++++++++++++++++++++++++++++++++++----------
src/jtag/adapter.h | 10 ++++++++
3 files changed, 81 insertions(+), 19 deletions(-)
hooks/post-receive
--
Main OpenOCD repository
|
|
From: openocd-gerrit <ope...@us...> - 2025-09-01 07:47:19
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Main OpenOCD repository".
The branch, master has been updated
via fcff4b712c53a6169f0f96dd63f0adb1b12a1789 (commit)
from 64ed1c74d5d4eb8808047881d074cb8e9579dbe3 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit fcff4b712c53a6169f0f96dd63f0adb1b12a1789
Author: Brian Kuschak <bku...@gm...>
Date: Wed Jun 11 12:41:04 2025 +0800
jtag/drivers/cmsis_dap: add new backend cmsis_dap_tcp
Create a new backend for cmsis_dap driver that allows CMSIS-DAP protocol
to run over TCP/IP instead of USB.
An example implementation of the firmware for an SWD programmer that
uses this cmsis_dap_tcp protocol can be found at the link below.
https://github.com/bkuschak/cmsis_dap_tcp_esp32
Using this cmsis_dap_tcp backend with the firmware above on an ESP32-C6
programmer and STM32F401RE target shows the following performance:
- loading 96KB image to RAM: 80 KB/sec
- dumping 96KB image from RAM: 72 KB/sec
- flashing 512KB image completes in about 13.5 seconds (including erase,
program, and verify).
Change-Id: I6e3e45016bd16ef2259561b1046788f5536b0687
Signed-off-by: Brian Kuschak <bku...@gm...>
Reviewed-on: https://review.openocd.org/c/openocd/+/8973
Reviewed-by: Tomas Vanek <va...@fb...>
Reviewed-by: Antonio Borneo <bor...@gm...>
Tested-by: jenkins
diff --git a/configure.ac b/configure.ac
index b508f2ade..01077847b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -204,6 +204,9 @@ m4_define([RSHIM_ADAPTER],
m4_define([AMTJTAGACCEL_ADAPTER],
[[[amtjtagaccel], [Amontec JTAG-Accelerator driver], [AMTJTAGACCEL]]])
+m4_define([CMSIS_DAP_TCP_ADAPTER],
+ [[[cmsis_dap_tcp], [CMSIS-DAP v2 compliant dongle (TCP)], [CMSIS_DAP_TCP]]])
+
m4_define([HOST_ARM_BITBANG_ADAPTERS],
[[[ep93xx], [Bitbanging on EP93xx-based SBCs], [EP93XX]],
[[at91rm9200], [Bitbanging on AT91RM9200-based SBCs], [AT91RM9200]]])
@@ -327,7 +330,8 @@ AC_ARG_ADAPTERS([
JTAG_VPI_ADAPTER,
RSHIM_ADAPTER,
XVC_ADAPTERS,
- LIBJAYLINK_ADAPTERS
+ LIBJAYLINK_ADAPTERS,
+ CMSIS_DAP_TCP_ADAPTER
],[auto])
AC_ARG_ADAPTERS([
@@ -623,6 +627,7 @@ PROCESS_ADAPTERS([LIBGPIOD_ADAPTERS], ["x$use_libgpiod" = "xyes"], [Linux libgpi
PROCESS_ADAPTERS([DMEM_ADAPTER], ["x$is_linux" = "xyes"], [Linux /dev/mem])
PROCESS_ADAPTERS([SYSFSGPIO_ADAPTER], ["x$is_linux" = "xyes"], [Linux sysfs])
PROCESS_ADAPTERS([REMOTE_BITBANG_ADAPTER], [true], [unused])
+PROCESS_ADAPTERS([CMSIS_DAP_TCP_ADAPTER], [true], [unused])
PROCESS_ADAPTERS([LIBJAYLINK_ADAPTERS], ["x$use_internal_libjaylink" = "xyes" -o "x$use_libjaylink" = "xyes"], [libjaylink-0.2])
PROCESS_ADAPTERS([XVC_ADAPTERS], ["x$is_linux" = "xyes" -a "x$ac_cv_header_linux_pci_h" = "xyes"], [Linux build])
PROCESS_ADAPTERS([SERIAL_PORT_ADAPTERS], ["x$can_build_buspirate" = "xyes"],
@@ -682,6 +687,8 @@ AS_IF([test "x$enable_stlink" != "xno" -o "x$enable_ti_icdi" != "xno" -o "x$enab
AM_CONDITIONAL([HLADAPTER_STLINK], [test "x$enable_stlink" != "xno"])
AM_CONDITIONAL([HLADAPTER_ICDI], [test "x$enable_ti_icdi" != "xno"])
AM_CONDITIONAL([HLADAPTER_NULINK], [test "x$enable_nulink" != "xno"])
+AM_CONDITIONAL([CMSIS_DAP_CORE],
+ [test "x$enable_cmsis_dap" != "xno" -o "x$enable_cmsis_dap_v2" != "xno" -o "x$enable_cmsis_dap_tcp" != "xno"])
AS_IF([test "x$enable_jlink" != "xno"], [
AS_IF([test "x$use_internal_libjaylink" = "xyes"], [
@@ -832,6 +839,7 @@ m4_foreach([adapterTuple], [USB1_ADAPTERS,
AMTJTAGACCEL_ADAPTER,
HOST_ARM_BITBANG_ADAPTERS,
HOST_ARM_OR_AARCH64_BITBANG_ADAPTERS,
+ CMSIS_DAP_TCP_ADAPTER,
DUMMY_ADAPTER,
OPTIONAL_LIBRARIES,
COVERAGE],
diff --git a/doc/openocd.texi b/doc/openocd.texi
index 4d8f79558..6c7aa86ec 100644
--- a/doc/openocd.texi
+++ b/doc/openocd.texi
@@ -2621,7 +2621,7 @@ ch347 activity_led n4
@deffn {Interface Driver} {cmsis-dap}
ARM CMSIS-DAP compliant based adapter v1 (USB HID based)
-or v2 (USB bulk).
+or v2 (USB bulk or TCP/IP).
@deffn {Config Command} {cmsis-dap vid_pid} [vid pid]+
The vendor ID and product ID of the CMSIS-DAP device. If not specified
@@ -2632,14 +2632,17 @@ cmsis-dap vid_pid 0xc251 0xf001 0x0d28 0x0204
@end example
@end deffn
-@deffn {Config Command} {cmsis-dap backend} [@option{auto}|@option{usb_bulk}|@option{hid}]
+@deffn {Config Command} {cmsis-dap backend} [@option{auto}|@option{usb_bulk}|@option{hid}|@option{tcp}]
Specifies how to communicate with the adapter:
@itemize @minus
-@item @option{hid} Use HID generic reports - CMSIS-DAP v1
+@item @option{hid} Use USB HID generic reports - CMSIS-DAP v1
@item @option{usb_bulk} Use USB bulk - CMSIS-DAP v2
-@item @option{auto} First try USB bulk CMSIS-DAP v2, if not found try HID CMSIS-DAP v1.
-This is the default if @command{cmsis-dap backend} is not specified.
+@item @option{tcp} Use TCP/IP instead of USB
+@item @option{auto} First try USB bulk CMSIS-DAP v2, if not found try USB HID
+CMSIS-DAP v1, if not found try TCP (if @command{cmsis-dap tcp host} is
+configured). This is the default if @command{cmsis-dap backend} is not
+specified.
@end itemize
@end deffn
@@ -2649,6 +2652,36 @@ In most cases need not to be specified and interfaces are searched by
interface string or for user class interface.
@end deffn
+@deffn {Config Command} {cmsis-dap tcp host} hostname
+Specifies the @var{hostname} or IP address of the remote programmer. For use
+with 'tcp' backend only.
+@example
+cmsis-dap backend tcp
+cmsis-dap tcp host 192.168.1.4
+@end example
+@end deffn
+
+@deffn {Config Command} {cmsis-dap tcp port} port
+Specifies the TCP @var{port} number used by the remote programmer for DAP
+commands. The default port is 4441. For use with 'tcp' backend only.
+@example
+cmsis-dap backend tcp
+cmsis-dap tcp host 192.168.1.4
+cmsis-dap tcp port 4441
+@end example
+@end deffn
+
+@deffn {Config Command} {cmsis-dap tcp min_timeout} milliseconds
+Sets a lower bound on the requested timeout in @var{milliseconds} to wait for
+response packets from the remote programmer when using the 'tcp' backend. The
+user may want to use a larger value on slower networks, to avoid getting
+command mismatch errors. Default value is 150 milliseconds. For use with 'tcp'
+backend only.
+@example
+cmsis-dap tcp min_timeout 200
+@end example
+@end deffn
+
@deffn {Command} {cmsis-dap quirk} [@option{enable}|@option{disable}]
Enables or disables the following workarounds of known CMSIS-DAP adapter
quirks:
diff --git a/src/helper/replacements.h b/src/helper/replacements.h
index ecc0e5e95..747c2ae09 100644
--- a/src/helper/replacements.h
+++ b/src/helper/replacements.h
@@ -225,6 +225,20 @@ static inline int socket_select(int max_fd,
#endif
}
+static inline int socket_recv_timeout(int fd, unsigned long timeout_msec)
+{
+#ifdef _WIN32
+ DWORD timeout = timeout_msec;
+ return setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, (const char *)&timeout,
+ sizeof(timeout));
+#else
+ struct timeval tv;
+ tv.tv_sec = timeout_msec / 1000;
+ tv.tv_usec = (timeout_msec % 1000) * 1000;
+ return setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, (const char *)&tv, sizeof(tv));
+#endif
+}
+
#ifndef HAVE_ELF_H
typedef uint32_t Elf32_Addr;
diff --git a/src/jtag/drivers/Makefile.am b/src/jtag/drivers/Makefile.am
index 3a3fe0772..5216e5d77 100644
--- a/src/jtag/drivers/Makefile.am
+++ b/src/jtag/drivers/Makefile.am
@@ -186,15 +186,17 @@ endif
if OPENJTAG
DRIVERFILES += %D%/openjtag.c
endif
+if CMSIS_DAP_CORE
+DRIVERFILES += %D%/cmsis_dap.c
+endif
if CMSIS_DAP_HID
DRIVERFILES += %D%/cmsis_dap_usb_hid.c
-DRIVERFILES += %D%/cmsis_dap.c
endif
if CMSIS_DAP_USB
DRIVERFILES += %D%/cmsis_dap_usb_bulk.c
-if !CMSIS_DAP_HID
-DRIVERFILES += %D%/cmsis_dap.c
endif
+if CMSIS_DAP_TCP
+DRIVERFILES += %D%/cmsis_dap_tcp.c
endif
if IMX_GPIO
DRIVERFILES += %D%/imx_gpio.c
diff --git a/src/jtag/drivers/cmsis_dap.c b/src/jtag/drivers/cmsis_dap.c
index b82647da7..3e1a3c5f0 100644
--- a/src/jtag/drivers/cmsis_dap.c
+++ b/src/jtag/drivers/cmsis_dap.c
@@ -52,9 +52,16 @@ const struct cmsis_dap_backend cmsis_dap_hid_backend = {
};
#endif
+#if BUILD_CMSIS_DAP_TCP == 0
+const struct cmsis_dap_backend cmsis_dap_tcp_backend = {
+ .name = "tcp"
+};
+#endif
+
static const struct cmsis_dap_backend *const cmsis_dap_backends[] = {
&cmsis_dap_usb_backend,
&cmsis_dap_hid_backend,
+ &cmsis_dap_tcp_backend,
};
/* USB Config */
@@ -2275,8 +2282,8 @@ static const struct command_registration cmsis_dap_subcommand_handlers[] = {
.name = "backend",
.handler = &cmsis_dap_handle_backend_command,
.mode = COMMAND_CONFIG,
- .help = "set the communication backend to use (USB bulk or HID).",
- .usage = "(auto | usb_bulk | hid)",
+ .help = "set the communication backend to use (USB bulk or HID, or TCP).",
+ .usage = "(auto | usb_bulk | hid | tcp)",
},
{
.name = "quirk",
@@ -2293,6 +2300,15 @@ static const struct command_registration cmsis_dap_subcommand_handlers[] = {
.help = "USB bulk backend-specific commands",
.usage = "<cmd>",
},
+#endif
+#if BUILD_CMSIS_DAP_TCP
+ {
+ .name = "tcp",
+ .chain = cmsis_dap_tcp_subcommand_handlers,
+ .mode = COMMAND_ANY,
+ .help = "TCP backend-specific commands",
+ .usage = "<cmd>",
+ },
#endif
COMMAND_REGISTRATION_DONE
};
diff --git a/src/jtag/drivers/cmsis_dap.h b/src/jtag/drivers/cmsis_dap.h
index 26dc6f0cf..880fc3350 100644
--- a/src/jtag/drivers/cmsis_dap.h
+++ b/src/jtag/drivers/cmsis_dap.h
@@ -77,7 +77,9 @@ struct cmsis_dap_backend {
extern const struct cmsis_dap_backend cmsis_dap_hid_backend;
extern const struct cmsis_dap_backend cmsis_dap_usb_backend;
+extern const struct cmsis_dap_backend cmsis_dap_tcp_backend;
extern const struct command_registration cmsis_dap_usb_subcommand_handlers[];
+extern const struct command_registration cmsis_dap_tcp_subcommand_handlers[];
#define REPORT_ID_SIZE 1
diff --git a/src/jtag/drivers/cmsis_dap_tcp.c b/src/jtag/drivers/cmsis_dap_tcp.c
new file mode 100644
index 000000000..a654c6bff
--- /dev/null
+++ b/src/jtag/drivers/cmsis_dap_tcp.c
@@ -0,0 +1,439 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+/***************************************************************************
+ * Provides CMSIS-DAP protocol over a TCP/IP socket. *
+ * UART and SWO are currently unsupported. *
+ * *
+ * Copyright (C) 2025 by Brian Kuschak <bku...@gm...> *
+ * *
+ * Adapted from cmsis_dap_usb_hid.c. Copyright (C) 2013-2018 by: *
+ * Mickaël Thomas <mic...@gm...> *
+ * Maksym Hilliaka <ot...@fr...> *
+ * Phillip Pearson <pp...@my...> *
+ * Paul Fertser <fer...@gm...> *
+ * mike brown <mi...@th...> *
+ * Spencer Oliver <sp...@sp...> *
+ * *
+ ***************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <hidapi.h>
+#ifdef HAVE_NETDB_H
+#include <netdb.h>
+#endif
+#ifdef HAVE_NETINET_TCP_H
+#include <netinet/tcp.h>
+#endif
+#include <stdbool.h>
+#include <string.h>
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+#include <sys/types.h>
+
+#include "helper/command.h"
+#include "helper/log.h"
+#include "helper/replacements.h"
+#include "helper/system.h"
+#include "cmsis_dap.h"
+
+#define STRINGIFY(x) #x
+
+// If the protocol changes in the future, the SIGNATURE should also be changed.
+#define DAP_PKT_HDR_SIGNATURE 0x00504144 // "DAP"
+#define DAP_PKT_TYPE_REQUEST 0x01
+#define DAP_PKT_TYPE_RESPONSE 0x02
+
+#define CMSIS_DAP_TCP_PORT 4441 // Default. Can be overridden.
+#define CMSIS_DAP_PACKET_SIZE 1024 // Max payload size not including
+ // header.
+
+/* When flushing after an error, the CMSIS-DAP driver assumes the pipeline is
+ * empty if it doesn't get a response after a short 10 msec timeout. While this
+ * works for USB, it may not work for TCP/IP due to higher network latency. TCP
+ * response packets may take longer to arrive. We set a lower bound on timeout
+ * for blocking reads, to give enough time for packets to arrive.
+ *
+ * The user may override this default value by setting the parameter
+ * 'cmsis-dap tcp min_timeout'
+ */
+#define DEFAULT_MIN_TIMEOUT_MS 150
+
+/* CMSIS-DAP requests are variable length. With CMSIS-DAP over USB, the
+ * transfer sizes are preserved by the USB stack. However, TCP/IP is stream
+ * oriented so we perform our own packetization to preserve the boundaries
+ * between each request. This short header is prepended to each CMSIS-DAP
+ * request and response before being sent over the socket. Little endian format
+ * is used for multibyte values.
+ */
+struct __attribute__((packed)) cmsis_dap_tcp_packet_hdr {
+ uint32_t signature; // "DAP"
+ uint16_t length; // Not including header length.
+ uint8_t packet_type;
+ uint8_t reserved; // Reserved for future use.
+};
+
+/* Defines for struct cmsis_dap_tcp_packet_hdr requested by reviewer. */
+#define HEADER_SIGNATURE_OFFSET 0
+#define HEADER_LENGTH_OFFSET sizeof(uint32_t)
+#define HEADER_PACKET_TYPE_OFFSET (sizeof(uint32_t) + sizeof(uint16_t))
+#define HEADER_RESERVED_OFFSET (sizeof(uint32_t) + sizeof(uint16_t) + \
+ sizeof(uint8_t))
+#define HEADER_SIZE (sizeof(uint32_t) + sizeof(uint16_t) + \
+ 2 * sizeof(uint8_t))
+
+struct cmsis_dap_backend_data {
+ int sockfd;
+};
+
+static char *cmsis_dap_tcp_host;
+static char *const cmsis_dap_tcp_port_default = STRINGIFY(CMSIS_DAP_TCP_PORT);
+static char *cmsis_dap_tcp_port = cmsis_dap_tcp_port_default;
+static int cmsis_dap_tcp_min_timeout_ms = DEFAULT_MIN_TIMEOUT_MS;
+
+static void cmsis_dap_tcp_close(struct cmsis_dap *dap);
+static int cmsis_dap_tcp_alloc(struct cmsis_dap *dap, unsigned int pkt_sz);
+static void cmsis_dap_tcp_free(struct cmsis_dap *dap);
+
+static int cmsis_dap_tcp_open(struct cmsis_dap *dap,
+ uint16_t vids[] __attribute__((unused)),
+ uint16_t pids[] __attribute__((unused)),
+ const char *serial __attribute__((unused)))
+{
+ // Skip the open if the user has not provided a hostname.
+ if (!cmsis_dap_tcp_host) {
+ LOG_DEBUG("No TCP hostname, skipping open.");
+ return ERROR_FAIL;
+ }
+
+ // Ignore vids, pids, serial. We use host and port subcommands instead.
+
+ dap->bdata = malloc(sizeof(struct cmsis_dap_backend_data));
+ if (!dap->bdata) {
+ LOG_ERROR("CMSIS-DAP: unable to allocate memory");
+ return ERROR_FAIL;
+ }
+
+ struct addrinfo hints = {
+ .ai_family = AF_UNSPEC,
+ .ai_socktype = SOCK_STREAM
+ };
+ struct addrinfo *result, *rp;
+ int fd = 0;
+
+ LOG_INFO("CMSIS-DAP: Connecting to %s:%s using TCP backend",
+ cmsis_dap_tcp_host ? cmsis_dap_tcp_host : "localhost",
+ cmsis_dap_tcp_port);
+
+ /* Some of the following code was taken from remote_bitbang.c */
+ /* Obtain address(es) matching host/port */
+ int s = getaddrinfo(cmsis_dap_tcp_host, cmsis_dap_tcp_port, &hints,
+ &result);
+ if (s != 0) {
+ LOG_ERROR("CMSIS-DAP: getaddrinfo: %s\n", gai_strerror(s));
+ free(dap->bdata);
+ return ERROR_FAIL;
+ }
+
+ /* getaddrinfo() returns a list of address structures.
+ Try each address until we successfully connect(2).
+ If socket(2) (or connect(2)) fails, we (close the socket
+ and) try the next address. */
+
+ for (rp = result; rp ; rp = rp->ai_next) {
+ fd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
+ if (fd == -1)
+ continue;
+
+ if (connect(fd, rp->ai_addr, rp->ai_addrlen) != -1) {
+ LOG_DEBUG("Connected.");
+ break; /* Success */
+ }
+
+ close(fd);
+ }
+
+ freeaddrinfo(result);
+
+ if (!rp) { /* No address succeeded */
+ LOG_ERROR("CMSIS-DAP: unable to connect to device %s:%s",
+ cmsis_dap_tcp_host ? cmsis_dap_tcp_host : "localhost",
+ cmsis_dap_tcp_port);
+ log_socket_error("Failed to connect");
+ free(dap->bdata);
+ dap->bdata = NULL;
+ return ERROR_FAIL;
+ }
+
+ /* Set NODELAY to minimize latency. */
+ int one = 1;
+ /* On Windows optval has to be a const char *. */
+ setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (const char *)&one, sizeof(one));
+
+ dap->bdata->sockfd = fd;
+
+ int retval = cmsis_dap_tcp_alloc(dap, CMSIS_DAP_PACKET_SIZE);
+ if (retval != ERROR_OK) {
+ cmsis_dap_tcp_close(dap);
+ return retval;
+ }
+ return ERROR_OK;
+}
+
+static void cmsis_dap_tcp_close(struct cmsis_dap *dap)
+{
+ if (close_socket(dap->bdata->sockfd) != 0)
+ log_socket_error("close_socket");
+
+ if (dap->bdata)
+ free(dap->bdata);
+ dap->bdata = NULL;
+ cmsis_dap_tcp_free(dap);
+}
+
+static inline int readall_socket(int handle, void *buffer, unsigned int count)
+{
+ // Return after all count bytes available, or timeout, or error.
+ return recv(handle, buffer, count, MSG_WAITALL);
+}
+
+static inline int peekall_socket(int handle, void *buffer, unsigned int count)
+{
+ /* Data remains unread on the socket until recv() is called later without
+ * the MSG_PEEK flag. Return after all count bytes available, or timeout,
+ * or error.
+ */
+ return recv(handle, buffer, count, MSG_PEEK | MSG_WAITALL);
+}
+
+static int cmsis_dap_tcp_read(struct cmsis_dap *dap, int transfer_timeout_ms,
+ enum cmsis_dap_blocking blocking)
+{
+ int wait_ms = (blocking == CMSIS_DAP_NON_BLOCKING) ? 0 :
+ transfer_timeout_ms;
+ if (wait_ms) {
+ LOG_DEBUG_IO("CMSIS-DAP: using tcp timeout %d msec", wait_ms);
+
+ // Don't use very short timeouts with TCP/IP as it may not be as fast
+ // to respond as USB. User configurable minimum value.
+ if (wait_ms < cmsis_dap_tcp_min_timeout_ms) {
+ wait_ms = cmsis_dap_tcp_min_timeout_ms;
+ LOG_DEBUG_IO("CMSIS-DAP: extending timeout to %d msec", wait_ms);
+ }
+ }
+ socket_recv_timeout(dap->bdata->sockfd, wait_ms);
+
+ if (blocking == CMSIS_DAP_NON_BLOCKING)
+ socket_nonblock(dap->bdata->sockfd);
+ else
+ socket_block(dap->bdata->sockfd);
+
+ // Peek at the header first to find the length.
+ int retval = peekall_socket(dap->bdata->sockfd, dap->packet_buffer,
+ HEADER_SIZE);
+ LOG_DEBUG_IO("Reading header returned %d", retval);
+ if (retval == 0) {
+ LOG_DEBUG_IO("CMSIS-DAP: tcp timeout reached 1");
+ return ERROR_TIMEOUT_REACHED;
+ } else if (retval == -1) {
+ if (errno == EAGAIN || errno == EWOULDBLOCK) {
+ if (blocking == CMSIS_DAP_NON_BLOCKING)
+ return ERROR_TIMEOUT_REACHED;
+
+ LOG_DEBUG_IO("CMSIS-DAP: tcp timeout reached 2. timeout = %d msec",
+ wait_ms);
+ return ERROR_TIMEOUT_REACHED;
+ }
+
+ LOG_ERROR("CMSIS-DAP: error reading header");
+ log_socket_error("peek_socket");
+ return ERROR_FAIL;
+ } else if (retval != HEADER_SIZE) {
+ LOG_ERROR("CMSIS-DAP: short header read");
+ log_socket_error("peek_socket header short read");
+ return ERROR_FAIL;
+ }
+
+ struct cmsis_dap_tcp_packet_hdr header;
+ header.signature = le_to_h_u32(dap->packet_buffer +
+ HEADER_SIGNATURE_OFFSET);
+ header.length = le_to_h_u16(dap->packet_buffer + HEADER_LENGTH_OFFSET);
+ header.packet_type = dap->packet_buffer[HEADER_PACKET_TYPE_OFFSET];
+ header.reserved = dap->packet_buffer[HEADER_RESERVED_OFFSET];
+
+ if (header.signature != DAP_PKT_HDR_SIGNATURE) {
+ LOG_ERROR("CMSIS-DAP: Unrecognized packet signature 0x%08x",
+ header.signature);
+ return ERROR_FAIL;
+ } else if (header.packet_type != DAP_PKT_TYPE_RESPONSE) {
+ LOG_ERROR("CMSIS-DAP: Unrecognized packet type 0x%02x",
+ header.packet_type);
+ return ERROR_FAIL;
+ } else if (header.length + HEADER_SIZE > dap->packet_buffer_size) {
+ LOG_ERROR("CMSIS-DAP: Packet length %d too large to fit.",
+ header.length);
+ return ERROR_FAIL;
+ }
+
+ // Read the complete packet.
+ int read_len = HEADER_SIZE + header.length;
+ LOG_DEBUG_IO("Reading %d bytes (%d payload)...", read_len, header.length);
+ retval = readall_socket(dap->bdata->sockfd, dap->packet_buffer, read_len);
+
+ if (retval == 0) {
+ LOG_DEBUG_IO("CMSIS-DAP: tcp timeout reached 3");
+ return ERROR_TIMEOUT_REACHED;
+ } else if (retval == -1) {
+ LOG_ERROR("CMSIS-DAP: error reading data");
+ log_socket_error("read_socket");
+ return ERROR_FAIL;
+ } else if (retval != read_len) {
+ LOG_ERROR("CMSIS-DAP: short read. retval = %d. read_len = %d. "
+ "blocking = %s. wait_ms = %d", retval, read_len,
+ (blocking == CMSIS_DAP_NON_BLOCKING) ? "yes" : "no", wait_ms);
+ log_socket_error("read_socket short read");
+ return ERROR_FAIL;
+ }
+ return retval;
+}
+
+static int cmsis_dap_tcp_write(struct cmsis_dap *dap, int txlen,
+ int timeout_ms __attribute__((unused)))
+{
+ const unsigned int len = txlen + HEADER_SIZE;
+ if (len > dap->packet_buffer_size) {
+ LOG_ERROR("CMSIS-DAP: Packet length %d exceeds TCP buffer size!", len);
+ return ERROR_FAIL;
+ }
+
+ /* Set the header values. */
+ h_u32_to_le(dap->packet_buffer + HEADER_SIGNATURE_OFFSET,
+ DAP_PKT_HDR_SIGNATURE);
+ h_u16_to_le(dap->packet_buffer + HEADER_LENGTH_OFFSET, txlen);
+ dap->packet_buffer[HEADER_PACKET_TYPE_OFFSET] = DAP_PKT_TYPE_REQUEST;
+ dap->packet_buffer[HEADER_RESERVED_OFFSET] = 0;
+
+ /* write data to device */
+ LOG_DEBUG_IO("Writing %d bytes (%d payload)", len, txlen);
+ int retval = write_socket(dap->bdata->sockfd, dap->packet_buffer, len);
+ if (retval < 0) {
+ log_socket_error("write_socket");
+ return ERROR_FAIL;
+ } else if (retval != (int)len) {
+ LOG_ERROR("CMSIS-DAP: error writing data");
+ log_socket_error("write_socket short write");
+ return ERROR_FAIL;
+ }
+ return retval;
+}
+
+static int cmsis_dap_tcp_alloc(struct cmsis_dap *dap, unsigned int pkt_sz)
+{
+ // Reserve space for the packet header.
+ unsigned int packet_buffer_size = pkt_sz + HEADER_SIZE;
+ uint8_t *buf = malloc(packet_buffer_size);
+ if (!buf) {
+ LOG_ERROR("CMSIS-DAP: unable to allocate CMSIS-DAP packet buffer");
+ return ERROR_FAIL;
+ }
+
+ dap->packet_buffer = buf;
+ dap->packet_size = pkt_sz;
+ dap->packet_usable_size = pkt_sz;
+ dap->packet_buffer_size = packet_buffer_size;
+
+ dap->command = dap->packet_buffer + HEADER_SIZE;
+ dap->response = dap->packet_buffer + HEADER_SIZE;
+ return ERROR_OK;
+}
+
+static void cmsis_dap_tcp_free(struct cmsis_dap *dap)
+{
+ free(dap->packet_buffer);
+ dap->packet_buffer = NULL;
+}
+
+static void cmsis_dap_tcp_cancel_all(struct cmsis_dap *dap)
+{
+}
+
+COMMAND_HANDLER(cmsis_dap_handle_tcp_port)
+{
+ if (CMD_ARGC != 1)
+ return ERROR_COMMAND_SYNTAX_ERROR;
+
+ if (cmsis_dap_tcp_port != cmsis_dap_tcp_port_default)
+ free(cmsis_dap_tcp_port);
+
+ cmsis_dap_tcp_port = strdup(CMD_ARGV[0]);
+ if (!cmsis_dap_tcp_port) {
+ LOG_ERROR("CMSIS-DAP: out of memory");
+ return ERROR_FAIL;
+ }
+ return ERROR_OK;
+}
+
+COMMAND_HANDLER(cmsis_dap_handle_tcp_host)
+{
+ if (CMD_ARGC != 1)
+ return ERROR_COMMAND_SYNTAX_ERROR;
+
+ free(cmsis_dap_tcp_host);
+ cmsis_dap_tcp_host = strdup(CMD_ARGV[0]);
+ if (!cmsis_dap_tcp_host) {
+ LOG_ERROR("CMSIS-DAP: out of memory");
+ return ERROR_FAIL;
+ }
+ return ERROR_OK;
+}
+
+COMMAND_HANDLER(cmsis_dap_handle_tcp_min_timeout)
+{
+ if (CMD_ARGC != 1)
+ return ERROR_COMMAND_SYNTAX_ERROR;
+
+ COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], cmsis_dap_tcp_min_timeout_ms);
+ LOG_INFO("CMSIS-DAP: using minimum timeout of %d ms for TCP packets.",
+ cmsis_dap_tcp_min_timeout_ms);
+ return ERROR_OK;
+}
+
+const struct command_registration cmsis_dap_tcp_subcommand_handlers[] = {
+ {
+ .name = "host",
+ .handler = &cmsis_dap_handle_tcp_host,
+ .mode = COMMAND_CONFIG,
+ .help = "set the host name to use (for TCP backend only)",
+ .usage = "<host_name>",
+ },
+ {
+ .name = "port",
+ .handler = &cmsis_dap_handle_tcp_port,
+ .mode = COMMAND_CONFIG,
+ .help = "set the port number to use for DAP (for TCP backend only)",
+ .usage = "<port_number>",
+ },
+ {
+ .name = "min_timeout",
+ .handler = &cmsis_dap_handle_tcp_min_timeout,
+ .mode = COMMAND_CONFIG,
+ .help = "set the minimum timeout in milliseconds to wait for response "
+ "packets (for TCP backend only)",
+ .usage = "<milliseconds>",
+ },
+ COMMAND_REGISTRATION_DONE
+};
+
+const struct cmsis_dap_backend cmsis_dap_tcp_backend = {
+ .name = "tcp",
+ .open = cmsis_dap_tcp_open,
+ .close = cmsis_dap_tcp_close,
+ .read = cmsis_dap_tcp_read,
+ .write = cmsis_dap_tcp_write,
+ .packet_buffer_alloc = cmsis_dap_tcp_alloc,
+ .packet_buffer_free = cmsis_dap_tcp_free,
+ .cancel_all = cmsis_dap_tcp_cancel_all,
+};
diff --git a/tcl/interface/cmsis-dap-tcp.cfg b/tcl/interface/cmsis-dap-tcp.cfg
new file mode 100644
index 000000000..7889fb944
--- /dev/null
+++ b/tcl/interface/cmsis-dap-tcp.cfg
@@ -0,0 +1,18 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+#
+# cmsis-dap-tcp - CMSIS-DAP protocol over TCP/IP.
+#
+
+adapter driver cmsis-dap
+cmsis-dap backend tcp
+
+# Specify the hostname or IP address of your programmer.
+# cmsis-dap tcp host 192.168.1.4
+
+# Optionally specify a port number. Default port is 4441.
+# cmsis-dap tcp port 4441
+
+# Optionally set a lower bound on packet timeouts (milliseconds), if using a
+# slow network.
+# cmsis-dap tcp min_timeout 300
-----------------------------------------------------------------------
Summary of changes:
configure.ac | 10 +-
doc/openocd.texi | 43 +++-
src/helper/replacements.h | 14 ++
src/jtag/drivers/Makefile.am | 8 +-
src/jtag/drivers/cmsis_dap.c | 20 +-
src/jtag/drivers/cmsis_dap.h | 2 +
src/jtag/drivers/cmsis_dap_tcp.c | 439 +++++++++++++++++++++++++++++++++++++++
tcl/interface/cmsis-dap-tcp.cfg | 18 ++
8 files changed, 543 insertions(+), 11 deletions(-)
create mode 100644 src/jtag/drivers/cmsis_dap_tcp.c
create mode 100644 tcl/interface/cmsis-dap-tcp.cfg
hooks/post-receive
--
Main OpenOCD repository
|
|
From: openocd-gerrit <ope...@us...> - 2025-09-01 07:44:18
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Main OpenOCD repository".
The branch, master has been updated
via 64ed1c74d5d4eb8808047881d074cb8e9579dbe3 (commit)
from 61d1d13a0248fc6f0b131210d816b823816f14d6 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 64ed1c74d5d4eb8808047881d074cb8e9579dbe3
Author: HAOUES Ahmed <ahm...@st...>
Date: Wed May 7 16:25:39 2025 +0100
flash/stm32l4x: Support STM32U37/U38x devices
STM32U37/U38x devices have 1Mb flash (split into pages of 4 Kb)
Note: add wait for the BSY bit to be cleared in FLASH_SR
Change-Id: I8208aa81951b9e2f7b0a6bbfce3f7c8ad0f78ade
Signed-off-by: HAOUES Ahmed <ahm...@st...>
Reviewed-on: https://review.openocd.org/c/openocd/+/8874
Tested-by: jenkins
Reviewed-by: Tomas Vanek <va...@fb...>
diff --git a/src/flash/nor/stm32l4x.c b/src/flash/nor/stm32l4x.c
index 2da2c69fe..0c56ef6d9 100644
--- a/src/flash/nor/stm32l4x.c
+++ b/src/flash/nor/stm32l4x.c
@@ -287,7 +287,7 @@ struct stm32l4_wrp {
};
/* human readable list of families this drivers supports (sorted alphabetically) */
-static const char *device_families = "STM32C0/G0/G4/L4/L4+/L5/U0/U5/WB/WL";
+static const char *device_families = "STM32C0/G0/G4/L4/L4+/L5/U0/U3/U5/WB/WL";
static const struct stm32l4_rev stm32l47_l48xx_revs[] = {
{ 0x1000, "1" }, { 0x1001, "2" }, { 0x1003, "3" }, { 0x1007, "4" }
@@ -350,6 +350,10 @@ static const struct stm32l4_rev stm32u0xx_revs[] = {
{ 0x1000, "A" },
};
+static const struct stm32l4_rev stm32u37_u38xx_revs[] = {
+ { 0x1000, "A" }, { 0x1001, "Z" },
+};
+
static const struct stm32l4_rev stm32g43_g44xx_revs[] = {
{ 0x1000, "A" }, { 0x2000, "B" }, { 0x2001, "Z" },
};
@@ -690,6 +694,18 @@ static const struct stm32l4_part_info stm32l4_parts[] = {
.otp_base = 0x1FFF6800,
.otp_size = 1024,
},
+ {
+ .id = DEVID_STM32U37_U38XX,
+ .revs = stm32u37_u38xx_revs,
+ .num_revs = ARRAY_SIZE(stm32u37_u38xx_revs),
+ .device_str = "STM32U37/U38xx",
+ .max_flash_size_kb = 1024,
+ .flags = F_HAS_DUAL_BANK | F_HAS_TZ | F_HAS_L5_FLASH_REGS | F_WRP_HAS_LOCK,
+ .flash_regs_base = 0x40022000,
+ .fsize_addr = 0x0BFA07A0,
+ .otp_base = 0x0BFA0000,
+ .otp_size = 512,
+ },
{
.id = DEVID_STM32U59_U5AXX,
.revs = stm32u59_u5axx_revs,
@@ -1380,6 +1396,10 @@ static int stm32l4_erase(struct flash_bank *bank, unsigned int first,
4. Wait for the BSY bit to be cleared
*/
+ retval = stm32l4_wait_status_busy(bank, FLASH_ERASE_TIMEOUT);
+ if (retval != ERROR_OK)
+ goto err_lock;
+
for (unsigned int i = first; i <= last; i++) {
uint32_t erase_flags;
erase_flags = FLASH_PER | FLASH_STRT;
@@ -1785,6 +1805,9 @@ static int stm32l4_write(struct flash_bank *bank, const uint8_t *buffer,
if (retval != ERROR_OK)
goto err_lock;
+ retval = stm32l4_wait_status_busy(bank, FLASH_WRITE_TIMEOUT);
+ if (retval != ERROR_OK)
+ goto err_lock;
/* For TrustZone enabled devices, when TZEN is set and RDP level is 0.5,
* the debug is possible only in non-secure state.
@@ -2151,6 +2174,15 @@ static int stm32l4_probe(struct flash_bank *bank)
stm32l4_info->bank1_sectors = num_pages / 2;
}
break;
+ case DEVID_STM32U37_U38XX:
+ page_size_kb = 4;
+ num_pages = flash_size_kb / page_size_kb;
+ stm32l4_info->bank1_sectors = num_pages;
+ if (is_max_flash_size || (stm32l4_info->optr & FLASH_U5_DUALBANK)) {
+ stm32l4_info->dual_bank_mode = true;
+ stm32l4_info->bank1_sectors = num_pages / 2;
+ }
+ break;
case DEVID_STM32U53_U54XX:
case DEVID_STM32U57_U58XX:
case DEVID_STM32U59_U5AXX:
diff --git a/src/flash/nor/stm32l4x.h b/src/flash/nor/stm32l4x.h
index 1f4f2344f..8e6cb4309 100644
--- a/src/flash/nor/stm32l4x.h
+++ b/src/flash/nor/stm32l4x.h
@@ -94,6 +94,7 @@
#define DEVID_STM32C05XX 0x44C
#define DEVID_STM32C09XX 0x44D
#define DEVID_STM32C03XX 0x453
+#define DEVID_STM32U37_U38XX 0x454
#define DEVID_STM32U53_U54XX 0x455
#define DEVID_STM32G05_G06XX 0x456
#define DEVID_STM32U031XX 0x459
diff --git a/tcl/target/stm32u3x.cfg b/tcl/target/stm32u3x.cfg
new file mode 100644
index 000000000..449c04217
--- /dev/null
+++ b/tcl/target/stm32u3x.cfg
@@ -0,0 +1,45 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+# script for stm32u3x family
+# stm32u3x devices support both JTAG and SWD transports.
+
+source [find target/swj-dp.tcl]
+source [find mem_helper.tcl]
+
+if { [info exists CHIPNAME] } {
+ set _CHIPNAME $CHIPNAME
+} else {
+ set _CHIPNAME stm32u3x
+}
+
+source [find target/stm32x5x_common.cfg]
+
+# In order to allow the flash program and erase operations,
+# we need to set the voltage scale to range 1
+
+proc config_voltage_range {} {
+ set offset [expr {[stm32x5x_is_secure] ? 0x10000000 : 0}]
+ # PWR voltage scaling register
+ set PWR_VOSR [expr {0x4003080C + $offset}]
+ # PWR supply voltage monitoring control register
+ set PWR_SVMCR [expr {0x40030810 + $offset}]
+ # RCC AHB1 peripheral clock enable register 2
+ # RCC_AHB1ENR2 = PWREN
+ mww [expr {0x40030C94 + $offset}] 0x4
+ if {(([mrw $PWR_VOSR] & 0x10001) != 0x10001)} {
+ # PWR_SVMCR = IO2SV
+ mmw $PWR_SVMCR 0x20000000 0
+ # PWR_VOSR : R1EN: Voltage scaling range 1
+ mmw $PWR_VOSR 1 3
+ # while !(PWR_VOSR & R1RDY)
+ while {([mrw $PWR_VOSR] & 0x10001) != 0x10001} {}
+ # Enable EPOD Booster
+ mmw $PWR_VOSR 0x00000100 0
+ # while !(PWR_VOSR & BOOSTRDY)
+ while {([mrw $PWR_VOSR] & 0x1000000) != 0} {}
+ }
+}
+
+$_TARGETNAME configure -event reset-init {
+ config_voltage_range
+}
diff --git a/tcl/target/stm32x5x_common.cfg b/tcl/target/stm32x5x_common.cfg
index fb3aeb18c..b6370e493 100644
--- a/tcl/target/stm32x5x_common.cfg
+++ b/tcl/target/stm32x5x_common.cfg
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: GPL-2.0-or-later
-# common script for stm32l5x and stm32u5x families
+# common script for stm32l5x, stm32u3x and stm32u5x families
# Work-area is a space in RAM used for flash programming
# By default use 64kB
@@ -16,6 +16,7 @@ if { [info exists CPUTAPID] } {
} else {
if { [using_jtag] } {
# STM32L5x: RM0438 Rev5, Section 52.2.8 JTAG debug port - Table 425. JTAG-DP data registers
+ # STM32U3x: RM0487 Rev1, Section 53.3.1 JTAG debug port - Table 569. JTAG-DP data registers
# STM32U5x: RM0456 Rev1, Section 65.2.8 JTAG debug port - Table 661. JTAG-DP data registers
# Corresponds to Cortex®-M33 JTAG debug port ID code
set _CPUTAPID 0x0ba04477
-----------------------------------------------------------------------
Summary of changes:
src/flash/nor/stm32l4x.c | 34 ++++++++++++++++++++++++++++++-
src/flash/nor/stm32l4x.h | 1 +
tcl/target/stm32u3x.cfg | 45 ++++++++++++++++++++++++++++++++++++++++++
tcl/target/stm32x5x_common.cfg | 3 ++-
4 files changed, 81 insertions(+), 2 deletions(-)
create mode 100644 tcl/target/stm32u3x.cfg
hooks/post-receive
--
Main OpenOCD repository
|
|
From: openocd-gerrit <ope...@us...> - 2025-08-29 12:08:52
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Main OpenOCD repository".
The branch, master has been updated
via 61d1d13a0248fc6f0b131210d816b823816f14d6 (commit)
from fcbe243c0b7543d5a46c72d44117104368236c58 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 61d1d13a0248fc6f0b131210d816b823816f14d6
Author: Michal Lenc <mic...@se...>
Date: Mon Aug 25 15:39:15 2025 +0200
doc/openocd.texi: add entry describing atsamv user signature area
Adds documentation entry for newly added possibility to program
ATSAMV family embedded flash signature area page.
Change-Id: I3bbaba304868dca49d6dd7006276d2d3a95facad
Signed-off-by: Michal Lenc <mic...@se...>
Reviewed-on: https://review.openocd.org/c/openocd/+/9096
Reviewed-by: Tomas Vanek <va...@fb...>
Tested-by: jenkins
diff --git a/doc/openocd.texi b/doc/openocd.texi
index 22c7fcedd..4d8f79558 100644
--- a/doc/openocd.texi
+++ b/doc/openocd.texi
@@ -6965,6 +6965,18 @@ This driver uses the same command names/syntax as @xref{at91sam3}.
flash bank $_FLASHNAME atsamv 0x00400000 0 0 0 $_TARGETNAME
@end example
+These families also have a user signature area located at the beginning
+of an embedded flash. This is a 512 bytes large page whose data are not
+erased by assering ERASE pin or by software ERASE command. It can be
+used to store configuration, keys, trimming values and so on. The area
+overlaps with the beginning of standard flash and uses special commands
+to perform write/read operations. OpenOCD locates the signature area
+at fake address above 32 bit address space, specifically at 0x100000000.
+
+@example
+flash bank $_SIGNATURENAME atsamv 0x100000000 0 0 0 $_TARGETNAME
+@end example
+
@deffn {Command} {atsamv gpnvm} [@option{show} [@option{all}|number]]
@deffnx {Command} {atsamv gpnvm} (@option{clr}|@option{set}) number
With no parameters, @option{show} or @option{show all},
-----------------------------------------------------------------------
Summary of changes:
doc/openocd.texi | 12 ++++++++++++
1 file changed, 12 insertions(+)
hooks/post-receive
--
Main OpenOCD repository
|
|
From: openocd-gerrit <ope...@us...> - 2025-08-29 12:08:03
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Main OpenOCD repository".
The branch, master has been updated
via fcbe243c0b7543d5a46c72d44117104368236c58 (commit)
via 0819c3939f1f9d331b262a07565311efacc1b8d8 (commit)
from 5d333337b667121077df317e377b120d9fea4ca3 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit fcbe243c0b7543d5a46c72d44117104368236c58
Author: Tomas Vanek <va...@fb...>
Date: Mon Jul 28 09:50:55 2025 +0200
flash/nor/atsamv: reduce flash driver verbosity
Remove useless LOG_INFO in samv_flash_bank_command().
Change LOG_INFO to LOG_DEBUG in samv_erase().
Change-Id: I46923ea4f020197ba902b1a7226cc8ee91831a5a
Signed-off-by: Tomas Vanek <va...@fb...>
Reviewed-on: https://review.openocd.org/c/openocd/+/9061
Reviewed-by: zapb <de...@za...>
Reviewed-by: Michal Lenc <mic...@se...>
Tested-by: jenkins
diff --git a/src/flash/nor/atsamv.c b/src/flash/nor/atsamv.c
index 3cad1e113..c8de90900 100644
--- a/src/flash/nor/atsamv.c
+++ b/src/flash/nor/atsamv.c
@@ -410,7 +410,6 @@ static int samv_protect_check(struct flash_bank *bank)
FLASH_BANK_COMMAND_HANDLER(samv_flash_bank_command)
{
- LOG_INFO("flash bank command");
struct samv_flash_bank *samv_info;
samv_info = calloc(1, sizeof(struct samv_flash_bank));
bank->driver_priv = samv_info;
@@ -510,12 +509,12 @@ static int samv_erase(struct flash_bank *bank, unsigned int first,
if ((first == 0) && ((last + 1) == bank->num_sectors))
return samv_efc_perform_command(bank->target, SAMV_EFC_FCMD_EA, 0, NULL);
- LOG_INFO("erasing lock regions %u-%u...", first, last);
+ LOG_DEBUG("erasing lock regions %u-%u...", first, last);
for (unsigned int i = first; i <= last; i++) {
uint32_t status;
r = samv_erase_pages(bank->target, (i * page_count), page_count, &status);
- LOG_INFO("erasing lock region %u", i);
+ LOG_DEBUG("erasing lock region %u", i);
if (r != ERROR_OK)
LOG_ERROR("error performing erase page @ lock region number %u", i);
if (status & (1 << 2)) {
commit 0819c3939f1f9d331b262a07565311efacc1b8d8
Author: Tomas Vanek <va...@fb...>
Date: Mon Jul 28 09:36:18 2025 +0200
tcl/target/atsamv: disable watchdog in reset-init event
Prevent disrupting of 'flash erase_check' or 'flash verify_image'
running longer than 16 seconds.
Change-Id: I545a1155ac0d237c49f2f3a27235d8a67df2a61b
Signed-off-by: Tomas Vanek <va...@fb...>
Reviewed-on: https://review.openocd.org/c/openocd/+/9060
Tested-by: jenkins
Reviewed-by: Michal Lenc <mic...@se...>
diff --git a/tcl/target/atsamv.cfg b/tcl/target/atsamv.cfg
index 1adf1af0e..9fd89795b 100644
--- a/tcl/target/atsamv.cfg
+++ b/tcl/target/atsamv.cfg
@@ -41,6 +41,11 @@ target create $_TARGETNAME cortex_m -endian $_ENDIAN -dap $_CHIPNAME.dap
$_TARGETNAME configure -work-area-phys 0x20400000 -work-area-size $_WORKAREASIZE -work-area-backup 0
+$_TARGETNAME configure -event reset-init {
+ # WDT_MR = WDDIS (disable watchdog)
+ mww 0x400E1854 0x8000
+}
+
adapter speed 1800
if {![using_hla]} {
-----------------------------------------------------------------------
Summary of changes:
src/flash/nor/atsamv.c | 5 ++---
tcl/target/atsamv.cfg | 5 +++++
2 files changed, 7 insertions(+), 3 deletions(-)
hooks/post-receive
--
Main OpenOCD repository
|
|
From: openocd-gerrit <ope...@us...> - 2025-08-29 12:07:34
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Main OpenOCD repository".
The branch, master has been updated
via 5d333337b667121077df317e377b120d9fea4ca3 (commit)
from e971d677c0a5a8b55c257886466e7bfd3a73ce54 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 5d333337b667121077df317e377b120d9fea4ca3
Author: Michal Lenc <mic...@se...>
Date: Fri May 31 11:27:38 2024 +0200
atsamv: add support for user signature partition write
Embedded flash also has a user signature area. This is a 512
bytes large page whose data are not erased by asserting ERASE pin or by
software ERASE command. It may be used to store configuration, keys,
trimming values etc.
This commit adds option to access this area from OpenOCD.
Change-Id: If870aa85938b9cccd94f958dd1f3d93dbdf779f0
Signed-off-by: Michal Lenc <mic...@se...>
Reviewed-on: https://review.openocd.org/c/openocd/+/8302
Reviewed-by: Tomas Vanek <va...@fb...>
Reviewed-by: Antonio Borneo <bor...@gm...>
Tested-by: jenkins
diff --git a/src/flash/nor/atsamv.c b/src/flash/nor/atsamv.c
index 56db23d36..3cad1e113 100644
--- a/src/flash/nor/atsamv.c
+++ b/src/flash/nor/atsamv.c
@@ -12,6 +12,9 @@
* atsamv, atsams, and atsame support
* Copyright (C) 2015 Morgan Quigley
*
+ * atsamv extension of user signature area
+ * Copyright (C) 2024-2025 Elektroline Inc.
+ *
* Some of the lower level code was based on code supplied by
* ATMEL under BSD-Source-Code License and this copyright.
* ATMEL Microcontroller Software Support
@@ -24,6 +27,7 @@
#include "imp.h"
#include <helper/time_support.h>
+#include <helper/bits.h>
#define REG_NAME_WIDTH (12)
@@ -40,18 +44,39 @@
#define SAMV_EFC_FCMD_SFB (0xB) /* (EFC) Set Fuse Bit */
#define SAMV_EFC_FCMD_CFB (0xC) /* (EFC) Clear Fuse Bit */
#define SAMV_EFC_FCMD_GFB (0xD) /* (EFC) Get Fuse Bit */
+#define SAMV_EFC_FCMD_WUS (0x12) /* (EFC) Write User Signature */
+#define SAMV_EFC_FCMD_EUS (0x13) /* (EFC) Erase User Signature */
+#define SAMV_EFC_FCMD_STUS (0x14) /* (EFC) Start Read User Signature */
+#define SAMV_EFC_FCMD_SPUS (0x15) /* (EFC) Stop Read User Signature */
+
+#define SAMV_EFC_FMR_SCOD BIT(16) /* Sequantial Code Optimalization Disable */
+
+#define SAMV_EFC_FSR_FRDY_SET 1
+#define SAMV_EFC_FRS_FRDY_CLR 0
#define OFFSET_EFC_FMR 0
#define OFFSET_EFC_FCR 4
#define OFFSET_EFC_FSR 8
#define OFFSET_EFC_FRR 12
+#define TIMEOUT_MS_FRS_CHANGE 10 /* Timeout for FRS ready bit change */
+#define TIMEOUT_MS_CMD_DEFAULT 50 /* Default timeout for command */
+#define TIMEOUT_MS_CMD_ERASE 24000 /* Timeout for erase commands */
+
#define SAMV_CHIPID_CIDR (0x400E0940)
#define SAMV_NUM_GPNVM_BITS 9
#define SAMV_CONTROLLER_ADDR (0x400e0c00)
#define SAMV_SECTOR_SIZE 16384
#define SAMV_PAGE_SIZE 512
#define SAMV_FLASH_BASE 0x00400000
+/* This is a workaround. Flash Signature area is actually located at the
+ * beginning of the flash memory at the address range overlapping the
+ * first page of program flash. Since OpenOCD does not support write to
+ * a bank outside of address range, we use address above maximum 32-bit
+ * address space.
+ */
+#define SAMV_FLASH_SIGNATURE_BASE 0x100000000
+#define SAMV_FLASH_SIGNATURE_SIZE SAMV_PAGE_SIZE
struct samv_flash_bank {
bool probed;
@@ -59,6 +84,7 @@ struct samv_flash_bank {
unsigned int gpnvm[SAMV_NUM_GPNVM_BITS];
};
+
/* The actual sector size of the SAMV7 flash memory is 128K bytes.
* 16 sectors for a 2048KB device. The lock regions are 16KB per lock
* region, with a 2048KB device having 128 lock regions.
@@ -72,6 +98,36 @@ static int samv_efc_get_status(struct target *target, uint32_t *v)
return r;
}
+static int samv_efc_wait_status(struct target *target, uint8_t desired,
+ int64_t timeout, uint32_t *status)
+{
+ uint32_t v;
+ int64_t ms_now, ms_end;
+ int r;
+
+ if (status)
+ *status = 0;
+
+ ms_end = timeout + timeval_ms();
+
+ do {
+ r = samv_efc_get_status(target, &v);
+ if (r != ERROR_OK)
+ return r;
+
+ if (status)
+ *status = v;
+ ms_now = timeval_ms();
+ if (ms_now > ms_end) {
+ /* error */
+ LOG_ERROR("Command timeout");
+ return ERROR_FLASH_BUSY;
+ }
+ } while ((v & 1) != desired);
+
+ return ERROR_OK;
+}
+
static int samv_efc_get_result(struct target *target, uint32_t *v)
{
uint32_t rv;
@@ -81,15 +137,20 @@ static int samv_efc_get_result(struct target *target, uint32_t *v)
return r;
}
+static inline int samv_efc_get_mode(struct target *target, uint32_t *v)
+{
+ return target_read_u32(target, SAMV_CONTROLLER_ADDR + OFFSET_EFC_FMR, v);
+}
+
+static inline int samv_efc_set_mode(struct target *target, uint32_t v)
+{
+ return target_write_u32(target, SAMV_CONTROLLER_ADDR + OFFSET_EFC_FMR, v);
+}
+
static int samv_efc_start_command(struct target *target,
- unsigned int command, unsigned int argument)
+ uint8_t command, unsigned int argument)
{
uint32_t v;
- samv_efc_get_status(target, &v);
- if (!(v & 1)) {
- LOG_ERROR("flash controller is not ready");
- return ERROR_FAIL;
- }
v = (0x5A << 24) | (argument << 8) | command;
LOG_DEBUG("starting flash command: 0x%08x", (unsigned int)(v));
@@ -100,32 +161,33 @@ static int samv_efc_start_command(struct target *target,
}
static int samv_efc_perform_command(struct target *target,
- unsigned int command, unsigned int argument, uint32_t *status)
+ uint8_t command, unsigned int argument, uint32_t *status)
{
int r;
uint32_t v;
- int64_t ms_now, ms_end;
+ int64_t timeout;
if (status)
*status = 0;
+ r = samv_efc_get_status(target, &v);
+ if (r != ERROR_OK)
+ return r;
+ if ((v & 1) != 0x1)
+ return ERROR_FAIL;
r = samv_efc_start_command(target, command, argument);
if (r != ERROR_OK)
return r;
- ms_end = 10000 + timeval_ms();
+ if (command == SAMV_EFC_FCMD_EA || command == SAMV_EFC_FCMD_EPA ||
+ command == SAMV_EFC_FCMD_EUS)
+ timeout = TIMEOUT_MS_CMD_ERASE;
+ else
+ timeout = TIMEOUT_MS_CMD_DEFAULT;
- do {
- r = samv_efc_get_status(target, &v);
- if (r != ERROR_OK)
- return r;
- ms_now = timeval_ms();
- if (ms_now > ms_end) {
- /* error */
- LOG_ERROR("Command timeout");
- return ERROR_FAIL;
- }
- } while ((v & 1) == 0);
+ r = samv_efc_wait_status(target, SAMV_EFC_FSR_FRDY_SET, timeout, &v);
+ if (r != ERROR_OK)
+ return r;
/* if requested, copy the flash controller error bits back to the caller */
if (status)
@@ -133,6 +195,51 @@ static int samv_efc_perform_command(struct target *target,
return ERROR_OK;
}
+static int samv_efc_read_sequence(struct target *target, uint8_t start_cmd,
+ uint8_t stop_cmd, uint8_t *buf, size_t read_size)
+{
+ uint32_t v;
+ uint32_t addr = SAMV_FLASH_BASE;
+ int r;
+
+ samv_efc_get_mode(target, &v);
+ v |= SAMV_EFC_FMR_SCOD;
+ samv_efc_set_mode(target, v);
+
+ r = samv_efc_start_command(target, start_cmd, 0);
+ if (r != ERROR_OK) {
+ samv_efc_start_command(target, stop_cmd, 0);
+ goto rs_finish;
+ }
+
+ r = samv_efc_wait_status(target, SAMV_EFC_FRS_FRDY_CLR,
+ TIMEOUT_MS_FRS_CHANGE, NULL);
+ if (r != ERROR_OK)
+ goto rs_finish;
+
+ r = target_read_memory(target, addr, sizeof(uint32_t),
+ read_size / sizeof(uint32_t), buf);
+ if (r != ERROR_OK) {
+ LOG_ERROR("flash program failed to read page @ 0x%" PRIx32 "", addr);
+ goto rs_finish;
+ }
+
+ r = samv_efc_start_command(target, stop_cmd, 0);
+ if (r != ERROR_OK)
+ goto rs_finish;
+
+ r = samv_efc_wait_status(target, SAMV_EFC_FSR_FRDY_SET,
+ TIMEOUT_MS_FRS_CHANGE, NULL);
+ if (r != ERROR_OK)
+ goto rs_finish;
+
+rs_finish:
+ v &= ~SAMV_EFC_FMR_SCOD;
+ samv_efc_set_mode(target, v);
+
+ return r;
+}
+
static int samv_erase_pages(struct target *target,
int first_page, int num_pages, uint32_t *status)
{
@@ -230,6 +337,17 @@ static int samv_set_gpnvm(struct target *target, unsigned int gpnvm)
return r;
}
+static int samv_erase_user_signature(struct target *target)
+{
+ int r;
+
+ r = samv_efc_perform_command(target, SAMV_EFC_FCMD_EUS, 0, NULL);
+ if (r != ERROR_OK)
+ LOG_ERROR("error performing user signature write");
+
+ return r;
+}
+
static int samv_flash_unlock(struct target *target,
unsigned int start_sector, unsigned int end_sector)
{
@@ -306,6 +424,14 @@ static int samv_get_device_id(struct flash_bank *bank, uint32_t *device_id)
static int samv_probe(struct flash_bank *bank)
{
+ if (bank->base == SAMV_FLASH_SIGNATURE_BASE) {
+ bank->size = SAMV_FLASH_SIGNATURE_SIZE;
+ bank->num_sectors = 1;
+ bank->sectors = calloc(bank->num_sectors, sizeof(struct flash_sector));
+ bank->sectors[0].size = SAMV_FLASH_SIGNATURE_SIZE;
+ return ERROR_OK;
+ }
+
uint32_t device_id;
int r = samv_get_device_id(bank, &device_id);
if (r != ERROR_OK)
@@ -377,6 +503,9 @@ static int samv_erase(struct flash_bank *bank, unsigned int first,
if (r != ERROR_OK)
return r;
+ if (bank->base == SAMV_FLASH_SIGNATURE_BASE)
+ return samv_erase_user_signature(bank->target);
+
/* easy case: we've been requested to erase the entire flash */
if ((first == 0) && ((last + 1) == bank->num_sectors))
return samv_efc_perform_command(bank->target, SAMV_EFC_FCMD_EA, 0, NULL);
@@ -418,45 +547,134 @@ static int samv_protect(struct flash_bank *bank, int set, unsigned int first,
return r;
}
-static int samv_page_read(struct target *target,
+static int samv_read_standard_page(struct target *target,
unsigned int page_num, uint8_t *buf)
{
uint32_t addr = SAMV_FLASH_BASE + page_num * SAMV_PAGE_SIZE;
int r = target_read_memory(target, addr, 4, SAMV_PAGE_SIZE / 4, buf);
if (r != ERROR_OK)
- LOG_ERROR("flash program failed to read page @ 0x%08x",
- (unsigned int)(addr));
+ LOG_ERROR("flash program failed to read page @ 0x%08" PRIx32 "",
+ addr);
return r;
}
-static int samv_page_write(struct target *target,
+static int samv_read_user_signature(struct target *target, uint8_t *buf)
+{
+ int r;
+
+ r = samv_efc_read_sequence(target, SAMV_EFC_FCMD_STUS, SAMV_EFC_FCMD_SPUS,
+ buf, SAMV_PAGE_SIZE);
+
+ return r;
+}
+
+static int samv_page_read(struct target *target,
+ target_addr_t base, unsigned int page_num, uint8_t *buf)
+{
+ int r;
+ if (base == SAMV_FLASH_SIGNATURE_BASE)
+ r = samv_read_user_signature(target, buf);
+ else
+ r = samv_read_standard_page(target, page_num, buf);
+
+ return r;
+}
+
+static int samv_write_user_signature(struct target *target,
+ unsigned int pagenum, const uint8_t *buf)
+{
+ const uint32_t addr = SAMV_FLASH_BASE;
+ int r;
+
+ r = target_write_memory(target, addr, sizeof(uint32_t),
+ SAMV_PAGE_SIZE / sizeof(uint32_t), buf);
+ if (r != ERROR_OK) {
+ LOG_ERROR("failed to buffer page at 0x%08" PRIx32 "", addr);
+ return r;
+ }
+
+ r = samv_efc_perform_command(target, SAMV_EFC_FCMD_WUS, 0, NULL);
+ if (r != ERROR_OK)
+ LOG_ERROR("error performing user signature write");
+
+ return r;
+}
+
+static int samv_write_standard_page(struct target *target,
unsigned int pagenum, const uint8_t *buf)
{
uint32_t status;
const uint32_t addr = SAMV_FLASH_BASE + pagenum * SAMV_PAGE_SIZE;
int r;
- LOG_DEBUG("write page %u at address 0x%08x", pagenum, (unsigned int)addr);
+ LOG_DEBUG("write page %u at address 0x%08" PRIx32 "", pagenum, addr);
r = target_write_memory(target, addr, 4, SAMV_PAGE_SIZE / 4, buf);
if (r != ERROR_OK) {
- LOG_ERROR("failed to buffer page at 0x%08x", (unsigned int)addr);
+ LOG_ERROR("failed to buffer page at 0x%08" PRIx32 "", addr);
return r;
}
r = samv_efc_perform_command(target, SAMV_EFC_FCMD_WP, pagenum, &status);
if (r != ERROR_OK)
- LOG_ERROR("error performing write page at 0x%08x", (unsigned int)addr);
+ LOG_ERROR("error performing write page at 0x%08" PRIx32 "", addr);
if (status & (1 << 2)) {
- LOG_ERROR("page at 0x%08x is locked", (unsigned int)addr);
+ LOG_ERROR("page at 0x%08" PRIx32 " is locked", addr);
return ERROR_FAIL;
}
if (status & (1 << 1)) {
- LOG_ERROR("flash command error at 0x%08x", (unsigned int)addr);
+ LOG_ERROR("flash command error at 0x%08" PRIx32 "", addr);
return ERROR_FAIL;
}
return ERROR_OK;
}
+static int samv_page_write(struct target *target,
+ target_addr_t base, unsigned int pagenum, const uint8_t *buf)
+{
+ int r;
+ if (base == SAMV_FLASH_SIGNATURE_BASE)
+ r = samv_write_user_signature(target, pagenum, buf);
+ else
+ r = samv_write_standard_page(target, pagenum, buf);
+
+ return r;
+}
+
+static int samv_read(struct flash_bank *bank, uint8_t *buffer,
+ uint32_t offset, uint32_t count)
+{
+ int r;
+ uint8_t pagebuffer[SAMV_PAGE_SIZE] = {0};
+ struct target *target = bank->target;
+
+ LOG_DEBUG("offset=0x%08" PRIx32 " count=0x%08" PRIx32 "", offset, count);
+
+ if (target->state != TARGET_HALTED) {
+ LOG_ERROR("Target not halted");
+ return ERROR_TARGET_NOT_HALTED;
+ }
+
+ if (offset + count > bank->size) {
+ LOG_WARNING("Reads past end of flash. Extra data discarded.");
+ count = bank->size - offset;
+ }
+
+ LOG_DEBUG("offset: 0x%08" PRIx32 ", count: 0x%08" PRIx32 "", offset, count);
+
+ if (bank->base == SAMV_FLASH_SIGNATURE_BASE) {
+ r = samv_read_user_signature(target, pagebuffer);
+ if (r != ERROR_OK)
+ return r;
+ memcpy(buffer, pagebuffer + offset, count);
+ } else {
+ r = target_read_memory(target, offset, 1, count, buffer);
+ if (r != ERROR_OK)
+ return r;
+ }
+
+ return ERROR_OK;
+}
+
static int samv_write(struct flash_bank *bank, const uint8_t *buffer,
uint32_t offset, uint32_t count)
{
@@ -470,10 +688,10 @@ static int samv_write(struct flash_bank *bank, const uint8_t *buffer,
if ((offset + count) > bank->size) {
LOG_ERROR("flash write error - past end of bank");
- LOG_ERROR(" offset: 0x%08x, count 0x%08x, bank end: 0x%08x",
- (unsigned int)(offset),
- (unsigned int)(count),
- (unsigned int)(bank->size));
+ LOG_ERROR(" offset: 0x%08" PRIx32 ", count 0x%08" PRIx32 ", bank end: 0x%08" PRIx32 "",
+ offset,
+ count,
+ bank->size);
return ERROR_FAIL;
}
@@ -481,9 +699,8 @@ static int samv_write(struct flash_bank *bank, const uint8_t *buffer,
uint32_t page_cur = offset / SAMV_PAGE_SIZE;
uint32_t page_end = (offset + count - 1) / SAMV_PAGE_SIZE;
- LOG_DEBUG("offset: 0x%08x, count: 0x%08x",
- (unsigned int)(offset), (unsigned int)(count));
- LOG_DEBUG("page start: %d, page end: %d", (int)(page_cur), (int)(page_end));
+ LOG_DEBUG("offset: 0x%08" PRIx32 ", count: 0x%08" PRIx32 "", offset, count);
+ LOG_DEBUG("page start: %" PRIu32 ", page end: %" PRIu32 "", page_cur, page_end);
/* Special case: all one page */
/* Otherwise: */
@@ -497,14 +714,14 @@ static int samv_write(struct flash_bank *bank, const uint8_t *buffer,
/* handle special case - all one page. */
if (page_cur == page_end) {
LOG_DEBUG("special case, all in one page");
- r = samv_page_read(bank->target, page_cur, pagebuffer);
+ r = samv_page_read(bank->target, bank->base, page_cur, pagebuffer);
if (r != ERROR_OK)
return r;
- page_offset = offset & (SAMV_PAGE_SIZE-1);
+ page_offset = offset & (SAMV_PAGE_SIZE - 1);
memcpy(pagebuffer + page_offset, buffer, count);
- r = samv_page_write(bank->target, page_cur, pagebuffer);
+ r = samv_page_write(bank->target, bank->base, page_cur, pagebuffer);
if (r != ERROR_OK)
return r;
return ERROR_OK;
@@ -515,7 +732,7 @@ static int samv_write(struct flash_bank *bank, const uint8_t *buffer,
if (page_offset) {
LOG_DEBUG("non-aligned start");
/* read the partial page */
- r = samv_page_read(bank->target, page_cur, pagebuffer);
+ r = samv_page_read(bank->target, bank->base, page_cur, pagebuffer);
if (r != ERROR_OK)
return r;
@@ -523,11 +740,11 @@ static int samv_write(struct flash_bank *bank, const uint8_t *buffer,
uint32_t n = SAMV_PAGE_SIZE - page_offset;
memcpy(pagebuffer + page_offset, buffer, n);
- r = samv_page_write(bank->target, page_cur, pagebuffer);
+ r = samv_page_write(bank->target, bank->base, page_cur, pagebuffer);
if (r != ERROR_OK)
return r;
- count -= n;
+ count -= n;
offset += n;
buffer += n;
page_cur++;
@@ -537,11 +754,11 @@ static int samv_write(struct flash_bank *bank, const uint8_t *buffer,
assert(offset % SAMV_PAGE_SIZE == 0);
/* step 2) handle the full pages */
- LOG_DEBUG("full page loop: cur=%d, end=%d, count = 0x%08x",
- (int)page_cur, (int)page_end, (unsigned int)(count));
+ LOG_DEBUG("full page loop: cur=%" PRIu32 ", end=%" PRIu32 ", count = 0x%08" PRIx32 "",
+ page_cur, page_end, count);
while ((page_cur < page_end) && (count >= SAMV_PAGE_SIZE)) {
- r = samv_page_write(bank->target, page_cur, buffer);
+ r = samv_page_write(bank->target, bank->base, page_cur, buffer);
if (r != ERROR_OK)
return r;
count -= SAMV_PAGE_SIZE;
@@ -551,13 +768,13 @@ static int samv_write(struct flash_bank *bank, const uint8_t *buffer,
/* step 3) write final page, if it's partial (otherwise it's already done) */
if (count) {
- LOG_DEBUG("final partial page, count = 0x%08x", (unsigned int)(count));
+ LOG_DEBUG("final partial page, count = 0x%08" PRIx32 "", count);
/* we have a partial page */
- r = samv_page_read(bank->target, page_cur, pagebuffer);
+ r = samv_page_read(bank->target, bank->base, page_cur, pagebuffer);
if (r != ERROR_OK)
return r;
memcpy(pagebuffer, buffer, count); /* data goes at start of page */
- r = samv_page_write(bank->target, page_cur, pagebuffer);
+ r = samv_page_write(bank->target, bank->base, page_cur, pagebuffer);
if (r != ERROR_OK)
return r;
}
@@ -691,7 +908,7 @@ const struct flash_driver atsamv_flash = {
.erase = samv_erase,
.protect = samv_protect,
.write = samv_write,
- .read = default_flash_read,
+ .read = samv_read,
.probe = samv_probe,
.auto_probe = samv_auto_probe,
.erase_check = default_flash_blank_check,
diff --git a/tcl/target/atsamv.cfg b/tcl/target/atsamv.cfg
index 7e9f6c57e..1adf1af0e 100644
--- a/tcl/target/atsamv.cfg
+++ b/tcl/target/atsamv.cfg
@@ -58,4 +58,6 @@ if {![using_hla]} {
}
set _FLASHNAME $_CHIPNAME.flash
+set _SIGNATURENAME $_CHIPNAME.usersignature
flash bank $_FLASHNAME atsamv 0x00400000 0 0 0 $_TARGETNAME
+flash bank $_SIGNATURENAME atsamv 0x100000000 0 0 0 $_TARGETNAME
-----------------------------------------------------------------------
Summary of changes:
src/flash/nor/atsamv.c | 315 +++++++++++++++++++++++++++++++++++++++++--------
tcl/target/atsamv.cfg | 2 +
2 files changed, 268 insertions(+), 49 deletions(-)
hooks/post-receive
--
Main OpenOCD repository
|
|
From: openocd-gerrit <ope...@us...> - 2025-08-27 14:37:15
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Main OpenOCD repository".
The branch, master has been updated
via e971d677c0a5a8b55c257886466e7bfd3a73ce54 (commit)
via 96c219a40848710c8d94a08f235c12f4d6202c9e (commit)
from 56d67dac2eebf44b2d34e9aba13359e3e3947975 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit e971d677c0a5a8b55c257886466e7bfd3a73ce54
Author: Antonio Borneo <bor...@gm...>
Date: Sun Aug 24 12:36:09 2025 +0200
drivers ch347: drop useless initialization
Drop some useless initialization in the driver.
Replace a constant value returned through a variable with the
value itself.
Change-Id: I7b7c0b30c6d36e9763ff78bf826742792546fa7f
Signed-off-by: Antonio Borneo <bor...@gm...>
Reviewed-on: https://review.openocd.org/c/openocd/+/9095
Tested-by: jenkins
Reviewed-by: Matthias Jentsch <in...@ea...>
Reviewed-by: Tomas Vanek <va...@fb...>
diff --git a/src/jtag/drivers/ch347.c b/src/jtag/drivers/ch347.c
index a0404a21f..6a848ba7c 100644
--- a/src/jtag/drivers/ch347.c
+++ b/src/jtag/drivers/ch347.c
@@ -793,11 +793,10 @@ static int ch347_cmd_start_next(uint8_t type)
{
// different command type or non chainable command? (GPIO commands can't be concat)
uint8_t prev_type = ch347.scratchpad_cmd_type;
- int retval = ERROR_OK;
if (prev_type != type || ch347_is_single_cmd_type(type)) {
// something written in the scratchpad? => store it as command
if (prev_type != 0 && ch347.scratchpad_idx > 0) {
- retval = ch347_cmd_from_scratchpad();
+ int retval = ch347_cmd_from_scratchpad();
if (retval != ERROR_OK)
return retval;
@@ -813,7 +812,7 @@ static int ch347_cmd_start_next(uint8_t type)
/* before we can send non chainable command ("single" like GPIO command) we should send all
other commands because we can't send it together with other commands */
if (ch347_is_single_cmd_type(type)) {
- retval = ch347_cmd_transmit_queue();
+ int retval = ch347_cmd_transmit_queue();
if (retval != ERROR_OK)
return retval;
}
@@ -822,7 +821,7 @@ static int ch347_cmd_start_next(uint8_t type)
ch347.scratchpad_cmd_type = type;
}
- return retval;
+ return ERROR_OK;
}
/**
@@ -980,16 +979,15 @@ static int ch347_scratchpad_add_clock_tms(bool tms)
*/
static int ch347_scratchpad_add_stableclocks(int count)
{
- int retval = ERROR_OK;
if (ch347.scratchpad_cmd_type == 0) {
- retval = ch347_cmd_start_next(CH347_CMD_JTAG_BIT_OP);
+ int retval = ch347_cmd_start_next(CH347_CMD_JTAG_BIT_OP);
if (retval != ERROR_OK)
return retval;
}
bool tms = ch347.tms_pin == TMS_H;
for (int i = 0; i < count; i++) {
- retval = ch347_scratchpad_add_clock_tms(tms);
+ int retval = ch347_scratchpad_add_clock_tms(tms);
if (retval != ERROR_OK)
return retval;
}
@@ -1197,7 +1195,7 @@ static int ch347_scratchpad_add_write_read(struct scan_command *cmd, uint8_t *bi
static int ch347_scratchpad_add_run_test(int cycles, enum tap_state state)
{
LOG_DEBUG_IO("cycles=%d, end_state=%d", cycles, state);
- int retval = ERROR_OK;
+ int retval;
if (tap_get_state() != TAP_IDLE) {
retval = ch347_scratchpad_add_move_state(TAP_IDLE, 0);
if (retval != ERROR_OK)
@@ -1226,7 +1224,7 @@ static int ch347_scratchpad_add_scan(struct scan_command *cmd)
int scan_bits = jtag_build_buffer(cmd, &buf);
// add a move to IRSHIFT or DRSHIFT state
- int retval = ERROR_OK;
+ int retval;
if (cmd->ir_scan)
retval = ch347_scratchpad_add_move_state(TAP_IRSHIFT, 0);
else
commit 96c219a40848710c8d94a08f235c12f4d6202c9e
Author: Antonio Borneo <bor...@gm...>
Date: Sun Aug 24 12:30:52 2025 +0200
drivers: ch347: fix scan-build warnings
The newly merged driver ch347 triggers two new scan-build warnings
about dead assignment to variables.
Fix them.
Change-Id: Ided14272c3573be1498584e68ac4653cde029f31
Signed-off-by: Antonio Borneo <bor...@gm...>
Fixes: 7d0e12589629 ("jtag/drivers: Add support for CH347-based JTAG adapters")
Reviewed-on: https://review.openocd.org/c/openocd/+/9094
Tested-by: jenkins
Reviewed-by: Matthias Jentsch <in...@ea...>
Reviewed-by: Tomas Vanek <va...@fb...>
diff --git a/src/jtag/drivers/ch347.c b/src/jtag/drivers/ch347.c
index 8f563acaf..a0404a21f 100644
--- a/src/jtag/drivers/ch347.c
+++ b/src/jtag/drivers/ch347.c
@@ -863,7 +863,6 @@ static int ch347_single_read_get_byte(int read_buf_idx, uint8_t *byte)
if (read_buf_idx > CH347_SINGLE_CMD_MAX_READ || read_buf_idx < 0) {
LOG_ERROR("read_buf_idx out of range");
- read_buf_idx = 0;
return ERROR_FAIL;
}
@@ -989,7 +988,6 @@ static int ch347_scratchpad_add_stableclocks(int count)
}
bool tms = ch347.tms_pin == TMS_H;
- retval = ERROR_OK;
for (int i = 0; i < count; i++) {
retval = ch347_scratchpad_add_clock_tms(tms);
if (retval != ERROR_OK)
-----------------------------------------------------------------------
Summary of changes:
src/jtag/drivers/ch347.c | 18 +++++++-----------
1 file changed, 7 insertions(+), 11 deletions(-)
hooks/post-receive
--
Main OpenOCD repository
|
|
From: openocd-gerrit <ope...@us...> - 2025-08-24 11:20:21
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Main OpenOCD repository".
The branch, master has been updated
via 56d67dac2eebf44b2d34e9aba13359e3e3947975 (commit)
from f381945567096763548b9daeb2ef9a5c58b66251 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 56d67dac2eebf44b2d34e9aba13359e3e3947975
Author: Daniel Anselmi <dan...@gm...>
Date: Mon Aug 18 23:17:09 2025 +0200
flash/nor/max32: fix: call to calloc
With gcc 15.2.1 we get the following error:
'calloc' sizes specified with 'sizeof' in the earlier argument and
not in the later argument.
Change-Id: Ib34d758bc09d34d86d29dd02ea9c7f05b1e83327
Signed-off-by: Daniel Anselmi <dan...@gm...>
Reviewed-on: https://review.openocd.org/c/openocd/+/9014
Reviewed-by: zapb <de...@za...>
Tested-by: jenkins
Reviewed-by: Antonio Borneo <bor...@gm...>
diff --git a/src/flash/nor/max32xxx.c b/src/flash/nor/max32xxx.c
index ed6083441..e91b9b67d 100644
--- a/src/flash/nor/max32xxx.c
+++ b/src/flash/nor/max32xxx.c
@@ -113,7 +113,7 @@ FLASH_BANK_COMMAND_HANDLER(max32xxx_flash_bank_command)
return ERROR_FLASH_BANK_INVALID;
}
- info = calloc(sizeof(struct max32xxx_flash_bank), 1);
+ info = calloc(1, sizeof(struct max32xxx_flash_bank));
COMMAND_PARSE_NUMBER(u32, CMD_ARGV[2], info->flash_size);
COMMAND_PARSE_NUMBER(u32, CMD_ARGV[6], info->flc_base);
COMMAND_PARSE_NUMBER(u32, CMD_ARGV[7], info->sector_size);
-----------------------------------------------------------------------
Summary of changes:
src/flash/nor/max32xxx.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
hooks/post-receive
--
Main OpenOCD repository
|
|
From: openocd-gerrit <ope...@us...> - 2025-08-24 11:19:54
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Main OpenOCD repository".
The branch, master has been updated
via f381945567096763548b9daeb2ef9a5c58b66251 (commit)
from 65b886812bc0ea4d6d31b58a5786159e1f48c323 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit f381945567096763548b9daeb2ef9a5c58b66251
Author: Marc Schink <de...@za...>
Date: Sun Aug 17 12:38:36 2025 +0200
tcl/file_renaming: Remove simple renames
The target configuration entries are simple renames and are handled
automatically.
Change-Id: Icae6b9b0f20b3c31df2900119f9ed2dadb2b768a
Signed-off-by: Marc Schink <de...@za...>
Reviewed-on: https://review.openocd.org/c/openocd/+/9085
Reviewed-by: Antonio Borneo <bor...@gm...>
Tested-by: jenkins
diff --git a/tcl/file_renaming.cfg b/tcl/file_renaming.cfg
index 6f88ddd90..8950f6cd6 100644
--- a/tcl/file_renaming.cfg
+++ b/tcl/file_renaming.cfg
@@ -20,8 +20,4 @@ set _file_renaming {
board/stm32mp13x_dk.cfg board/st/stm32mp135f-dk.cfg
board/stm32mp15x_dk2.cfg board/st/stm32mp157f-dk2.cfg
board/sifive-hifive1-revb.cfg board/sifive/hifive1-rev-b.cfg
- target/nrf51.cfg target/nordic/nrf51.cfg
- target/nrf52.cfg target/nordic/nrf52.cfg
- target/nrf53.cfg target/nordic/nrf53.cfg
- target/nrf91.cfg target/nordic/nrf91.cfg
}
-----------------------------------------------------------------------
Summary of changes:
tcl/file_renaming.cfg | 4 ----
1 file changed, 4 deletions(-)
hooks/post-receive
--
Main OpenOCD repository
|
|
From: openocd-gerrit <ope...@us...> - 2025-08-24 11:19:22
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Main OpenOCD repository".
The branch, master has been updated
via 65b886812bc0ea4d6d31b58a5786159e1f48c323 (commit)
via 23ab2062e7f0ae40b33abc6c5477388978f6dc48 (commit)
from 4e493229c6c2d84e8f52341be0328ce31e57a6f2 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 65b886812bc0ea4d6d31b58a5786159e1f48c323
Author: Marc Schink <de...@za...>
Date: Thu Aug 14 15:01:27 2025 +0200
tcl/board: Move SiFive configs into vendor directory
Move the configuration files into a dedicated vendor folder as required
by the developer guidelines.
Change-Id: I5bf048f2d8d0fccbcfe40e0a0e7b30dfbab192d1
Signed-off-by: Marc Schink <de...@za...>
Reviewed-on: https://review.openocd.org/c/openocd/+/9082
Reviewed-by: Antonio Borneo <bor...@gm...>
Tested-by: jenkins
diff --git a/src/helper/startup.tcl b/src/helper/startup.tcl
index e328cbe07..89ed71b90 100644
--- a/src/helper/startup.tcl
+++ b/src/helper/startup.tcl
@@ -39,7 +39,7 @@ proc find {filename} {
return $t
}
- foreach vendor {nordic ti st} {
+ foreach vendor {nordic ti sifive st} {
# - path/to/a/certain/config_file
# replaced with
# - path/to/a/certain/${vendor}/config_file
diff --git a/tcl/board/sifive-e31arty.cfg b/tcl/board/sifive/e31-arty.cfg
similarity index 94%
rename from tcl/board/sifive-e31arty.cfg
rename to tcl/board/sifive/e31-arty.cfg
index b3e980f40..bdf79dae6 100644
--- a/tcl/board/sifive-e31arty.cfg
+++ b/tcl/board/sifive/e31-arty.cfg
@@ -3,7 +3,7 @@
#
# Be sure you include the speed and interface before this file
# Example:
-# -c "adapter speed 5000" -f "interface/ftdi/olimex-arm-usb-tiny-h.cfg" -f "board/sifive-e31arty.cfg"
+# -c "adapter speed 5000" -f "interface/ftdi/olimex-arm-usb-tiny-h.cfg" -f "board/sifive/e31-arty.cfg"
set _CHIPNAME riscv
jtag newtap $_CHIPNAME cpu -irlen 5 -expected-id 0x20000001
diff --git a/tcl/board/sifive-e51arty.cfg b/tcl/board/sifive/e51-arty.cfg
similarity index 94%
rename from tcl/board/sifive-e51arty.cfg
rename to tcl/board/sifive/e51-arty.cfg
index 3133c3902..1476d503e 100644
--- a/tcl/board/sifive-e51arty.cfg
+++ b/tcl/board/sifive/e51-arty.cfg
@@ -3,7 +3,7 @@
#
# Be sure you include the speed and interface before this file
# Example:
-# -c "adapter speed 5000" -f "interface/ftdi/olimex-arm-usb-tiny-h.cfg" -f "board/sifive-e51arty.cfg"
+# -c "adapter speed 5000" -f "interface/ftdi/olimex-arm-usb-tiny-h.cfg" -f "board/sifive/e51-arty.cfg"
set _CHIPNAME riscv
jtag newtap $_CHIPNAME cpu -irlen 5 -expected-id 0x20000001
diff --git a/tcl/board/sifive-hifive1-revb.cfg b/tcl/board/sifive/hifive1-rev-b.cfg
similarity index 100%
rename from tcl/board/sifive-hifive1-revb.cfg
rename to tcl/board/sifive/hifive1-rev-b.cfg
diff --git a/tcl/board/sifive-hifive1.cfg b/tcl/board/sifive/hifive1.cfg
similarity index 100%
rename from tcl/board/sifive-hifive1.cfg
rename to tcl/board/sifive/hifive1.cfg
diff --git a/tcl/file_renaming.cfg b/tcl/file_renaming.cfg
index 20679b6ab..6f88ddd90 100644
--- a/tcl/file_renaming.cfg
+++ b/tcl/file_renaming.cfg
@@ -19,6 +19,7 @@ set _file_renaming {
board/nordic_nrf52_dk.cfg board/nordic/nrf52-dk.cfg
board/stm32mp13x_dk.cfg board/st/stm32mp135f-dk.cfg
board/stm32mp15x_dk2.cfg board/st/stm32mp157f-dk2.cfg
+ board/sifive-hifive1-revb.cfg board/sifive/hifive1-rev-b.cfg
target/nrf51.cfg target/nordic/nrf51.cfg
target/nrf52.cfg target/nordic/nrf52.cfg
target/nrf53.cfg target/nordic/nrf53.cfg
commit 23ab2062e7f0ae40b33abc6c5477388978f6dc48
Author: Parshintsev Anatoly <ana...@sy...>
Date: Tue May 20 10:10:43 2025 +0300
server: global state updated by signal handlers should have a volatile sig_atomic_t type
Signal handlers currently violate both C language and POSIX requirements:
1. To avoid undefined behavior (UB), variables accessed or modified by
signal handlers be of atomic lock-free type.
2. The respected variables should be marked as volatile.
3. Signal handlers may only call a very limited subset of standard
library functions.
4. Additionally, POSIX restricts signal handlers to signal-safe
functions.
This patch addresses the first two issues by changing the type of global
variables that are accessed inside signal handler to `sig_atomic_t` and
adding `volatile` qualifiers.
Items 3 and 4 must be handled separately but are outside the scope of
this change.
Change-Id: I9c344e87bab9eefe7d99b0aad300a3ef4712df51
Signed-off-by: Parshintsev Anatoly <ana...@sy...>
Reviewed-on: https://review.openocd.org/c/openocd/+/8927
Tested-by: jenkins
Reviewed-by: Antonio Borneo <bor...@gm...>
Reviewed-by: Chris Head <ch...@za...>
diff --git a/src/server/server.c b/src/server/server.c
index 0649ec942..5f6bb584e 100644
--- a/src/server/server.c
+++ b/src/server/server.c
@@ -43,10 +43,10 @@ enum shutdown_reason {
SHUTDOWN_WITH_ERROR_CODE, /* set by shutdown command; quit with non-zero return code */
SHUTDOWN_WITH_SIGNAL_CODE /* set by sig_handler; exec shutdown then exit with signal as return code */
};
-static enum shutdown_reason shutdown_openocd = CONTINUE_MAIN_LOOP;
+static volatile sig_atomic_t shutdown_openocd = CONTINUE_MAIN_LOOP;
/* store received signal to exit application by killing ourselves */
-static int last_signal;
+static volatile sig_atomic_t last_signal;
/* set the polling period to 100ms */
static int polling_period = 100;
@@ -604,6 +604,7 @@ static void sig_handler(int sig)
/* store only first signal that hits us */
if (shutdown_openocd == CONTINUE_MAIN_LOOP) {
shutdown_openocd = SHUTDOWN_WITH_SIGNAL_CODE;
+ assert(sig >= SIG_ATOMIC_MIN && sig <= SIG_ATOMIC_MAX);
last_signal = sig;
LOG_DEBUG("Terminating on Signal %d", sig);
} else
-----------------------------------------------------------------------
Summary of changes:
src/helper/startup.tcl | 2 +-
src/server/server.c | 5 +++--
tcl/board/{sifive-e31arty.cfg => sifive/e31-arty.cfg} | 2 +-
tcl/board/{sifive-e51arty.cfg => sifive/e51-arty.cfg} | 2 +-
tcl/board/{sifive-hifive1-revb.cfg => sifive/hifive1-rev-b.cfg} | 0
tcl/board/{sifive-hifive1.cfg => sifive/hifive1.cfg} | 0
tcl/file_renaming.cfg | 1 +
7 files changed, 7 insertions(+), 5 deletions(-)
rename tcl/board/{sifive-e31arty.cfg => sifive/e31-arty.cfg} (94%)
rename tcl/board/{sifive-e51arty.cfg => sifive/e51-arty.cfg} (94%)
rename tcl/board/{sifive-hifive1-revb.cfg => sifive/hifive1-rev-b.cfg} (100%)
rename tcl/board/{sifive-hifive1.cfg => sifive/hifive1.cfg} (100%)
hooks/post-receive
--
Main OpenOCD repository
|
|
From: openocd-gerrit <ope...@us...> - 2025-08-24 11:18:47
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Main OpenOCD repository".
The branch, master has been updated
via 4e493229c6c2d84e8f52341be0328ce31e57a6f2 (commit)
from 160e2343bd7ab4f3b5f2bd8c89535709cc4bf519 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 4e493229c6c2d84e8f52341be0328ce31e57a6f2
Author: Ashi Gupta <qui...@qu...>
Date: Fri Jan 10 15:35:14 2025 +0530
tcl/target: Added target configuration for Qualcomm QCS6490 IOT
Processors.
QCS6490 and QCM6490 are 6nm processors designed for enterprise and IOT
applications featuring global 5G and Wi-Fi 6E support with similar
architecture.
This configuration file will allow debugging applications on these
processors.
Verified with Olimex(ARM-USB-OCD-H):
openocd -f tcl/interface/ftdi/olimex-arm-usb-ocd-h.cfg
-c 'transport select jtag'
-f <path_to_qcs6490_cfg>
and Jlink:
openocd -f tcl/interface/jlink.cfg
-c 'transport select jtag'
-f <path_to_qcs6490_cfg>
Change-Id: I05e923293134eaa9b70d3cf0d18efac9a024b6c7
Signed-off-by: Ashi Gupta <qui...@qu...>
Reviewed-on: https://review.openocd.org/c/openocd/+/8615
Reviewed-by: Antonio Borneo <bor...@gm...>
Tested-by: jenkins
diff --git a/tcl/target/qualcomm/qcs6490.cfg b/tcl/target/qualcomm/qcs6490.cfg
new file mode 100644
index 000000000..d12708c8a
--- /dev/null
+++ b/tcl/target/qualcomm/qcs6490.cfg
@@ -0,0 +1,48 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+#
+# The QCS6490/QCM6490 is a 6nm processor designed for enterprise and Internet of Things (IOT) applications,
+# featuring global 5G and Wi-Fi 6E support
+#
+# Product Page:
+# https://www.qualcomm.com/products/internet-of-things/industrial/building-enterprise/qcs6490
+# https://www.qualcomm.com/products/internet-of-things/industrial/building-enterprise/qcm6490
+
+source [find target/swj-dp.tcl]
+
+if { [info exists CHIPNAME] } {
+ set _CHIPNAME $CHIPNAME
+} else {
+ set _CHIPNAME QCS6490
+}
+
+if { [info exists ENDIAN] } {
+ set _ENDIAN $ENDIAN
+} else {
+ set _ENDIAN little
+}
+
+adapter speed 500
+reset_config trst_and_srst
+
+# Set CUP TAP ID based on protocol selection
+if { [using_jtag] } {
+ set _CPUTAPID 0x5ba00477
+} else {
+ set _CPUTAPID 0x5ba02477
+}
+
+swj_newdap $_CHIPNAME cpu -expected-id $_CPUTAPID -irlen 4
+
+dap create $_CHIPNAME.dap -chain-position $_CHIPNAME.cpu -ignore-syspwrupack
+
+cti create $_CHIPNAME.cti -dap $_CHIPNAME.dap -baseaddr 0x87020000 -ap-num 1
+
+target create $_CHIPNAME.cpu0 aarch64 -endian $_ENDIAN -dap $_CHIPNAME.dap -coreid 0 \
+ -dbgbase 0x87010000 -cti $_CHIPNAME.cti -event reset-assert-post { dap init }
+
+$_CHIPNAME.cpu0 configure -event examine-end {
+ eval $_CHIPNAME.cpu0 arp_halt
+}
+
+# Default breakpoints to hardware breakpoints
+gdb_breakpoint_override hard
-----------------------------------------------------------------------
Summary of changes:
tcl/target/qualcomm/qcs6490.cfg | 48 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 48 insertions(+)
create mode 100644 tcl/target/qualcomm/qcs6490.cfg
hooks/post-receive
--
Main OpenOCD repository
|
|
From: openocd-gerrit <ope...@us...> - 2025-08-24 11:17:59
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Main OpenOCD repository".
The branch, master has been updated
via 160e2343bd7ab4f3b5f2bd8c89535709cc4bf519 (commit)
from 7e403d9d3be58b1965f230831ac7bf84d5371189 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 160e2343bd7ab4f3b5f2bd8c89535709cc4bf519
Author: Marek Vrbka <mar...@co...>
Date: Wed Aug 13 15:36:21 2025 +0200
replacements: make socket_select() work on Windows if no sockets are provided
On Windows 11, if select() is called with empty sets, it fails and
returns WSAINVAL. On POSIX this works fine.
This patch addresses it by detecting this case in OpenOCD replacements
and returning 0 in these cases.
This fixes OpenOCD crash on Windows if no services are enabled
(gdb server, tcl server and telnet server all disabled).
Change-Id: I601878671caf4ae44e105d6a819251d2d96c607c
Signed-off-by: Marek Vrbka <mar...@co...>
Reviewed-on: https://review.openocd.org/c/openocd/+/9081
Tested-by: jenkins
Reviewed-by: Antonio Borneo <bor...@gm...>
diff --git a/src/helper/replacements.c b/src/helper/replacements.c
index 782d97518..9fb7b4a35 100644
--- a/src/helper/replacements.c
+++ b/src/helper/replacements.c
@@ -152,6 +152,21 @@ int win_select(int max_fd, fd_set *rfds, fd_set *wfds, fd_set *efds, struct time
FD_ZERO(&sock_write);
FD_ZERO(&sock_except);
+ /* On Windows, if all provided sets are empty/NULL an error code of -1 is returned
+ * and WSAGetLastError() returns WSAEINVAL instead of delaying.
+ * We check for this case, delay and return 0 instead of calling select(). */
+ if (rfds && rfds->fd_count == 0)
+ rfds = NULL;
+ if (wfds && wfds->fd_count == 0)
+ wfds = NULL;
+ if (efds && efds->fd_count == 0)
+ efds = NULL;
+ if (!rfds && !wfds && !efds && tv) {
+ sleep(tv->tv_sec);
+ usleep(tv->tv_usec);
+ return 0;
+ }
+
/* build an array of handles for non-sockets */
for (i = 0; i < max_fd; i++) {
if (SAFE_FD_ISSET(i, rfds) || SAFE_FD_ISSET(i, wfds) || SAFE_FD_ISSET(i, efds)) {
-----------------------------------------------------------------------
Summary of changes:
src/helper/replacements.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
hooks/post-receive
--
Main OpenOCD repository
|
|
From: openocd-gerrit <ope...@us...> - 2025-08-24 11:16:56
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Main OpenOCD repository".
The branch, master has been updated
via 7e403d9d3be58b1965f230831ac7bf84d5371189 (commit)
via 93f16eed4d4db379671293277e9b6e7d5aba6c9b (commit)
from 7effc6f825fe8aacfb15ea198994b212f55897cb (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 7e403d9d3be58b1965f230831ac7bf84d5371189
Author: Andreas Dannenberg <an...@mi...>
Date: Wed Aug 13 21:22:11 2025 +0900
tcl/target: add Rockchip RK3588 target
The Rockchip RK3588 SoC is used in systems such as the GenBook RK3588
open-hardware laptop and the Coolpi CM5 compute module. This patch adds
support for debugging those. Tested using the ST-LINK/V2 debug adapter
in SWD mode connected to the SDMMC_D2 (SWCLK) and SDMMC_D3 (SWDIO) pins
on the 50-pin J17 connector inside the GenBook RK3588 laptop.
Change-Id: Ia5da403054b6c9aa41184a4e092a74aa882a267d
Signed-off-by: Andreas Dannenberg <an...@mi...>
Reviewed-on: https://review.openocd.org/c/openocd/+/9013
Tested-by: jenkins
Reviewed-by: Antonio Borneo <bor...@gm...>
diff --git a/tcl/target/rk3588.cfg b/tcl/target/rk3588.cfg
new file mode 100644
index 000000000..7b470268a
--- /dev/null
+++ b/tcl/target/rk3588.cfg
@@ -0,0 +1,86 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Rockchip RK3588 Target
+# https://www.rock-chips.com/a/en/products/RK35_Series/2022/0926/1660.html
+# Andreas Dannenberg <an...@mi...>
+
+if { [info exists CHIPNAME] } {
+ set _CHIPNAME $CHIPNAME
+} else {
+ set _CHIPNAME rk3588
+}
+
+if { [info exists DAP_TAPID] } {
+ set _DAP_TAPID $DAP_TAPID
+} else {
+ set _DAP_TAPID 0x2ba01477
+}
+
+adapter speed 4000
+
+transport select swd
+
+# Declare the one SWD tap to access the DAP
+swd newdap $_CHIPNAME cpu -expected-id $_DAP_TAPID
+
+# Create the DAP
+dap create $_CHIPNAME.dap -chain-position $_CHIPNAME.cpu
+
+# Create target to allow accessing system memory directly
+target create $_CHIPNAME.ahb mem_ap -dap $_CHIPNAME.dap -ap-num 0
+
+# Declare the 8 main application cores (4 little cores + 4 big cores)
+
+# Little cluster (cores 0..3)
+set _TARGETNAME $_CHIPNAME.lcore
+set $_TARGETNAME.base(0) 0x81004000
+set $_TARGETNAME.base(1) 0x81005000
+set $_TARGETNAME.base(2) 0x81006000
+set $_TARGETNAME.base(3) 0x81007000
+set $_TARGETNAME.cti(0) 0x81014000
+set $_TARGETNAME.cti(1) 0x81015000
+set $_TARGETNAME.cti(2) 0x81016000
+set $_TARGETNAME.cti(3) 0x81017000
+
+# Big cluster (cores 4..7)
+set _TARGETNAME $_CHIPNAME.bcore
+set $_TARGETNAME.base(4) 0x81024000
+set $_TARGETNAME.base(5) 0x81025000
+set $_TARGETNAME.base(6) 0x81026000
+set $_TARGETNAME.base(7) 0x81027000
+set $_TARGETNAME.cti(4) 0x81034000
+set $_TARGETNAME.cti(5) 0x81035000
+set $_TARGETNAME.cti(6) 0x81036000
+set $_TARGETNAME.cti(7) 0x81037000
+
+# Build string used to enable SMP mode
+set _smp_command "target smp"
+
+set _cores 8
+for { set _core 0 } { $_core < $_cores } { incr _core 1 } {
+ if {$_core < 4} {
+ set _TARGETNAME $_CHIPNAME.lcore
+ } else {
+ set _TARGETNAME $_CHIPNAME.bcore
+ }
+
+ cti create cti$_core -dap $_CHIPNAME.dap -baseaddr [set $_TARGETNAME.cti($_core)] -ap-num 0
+
+ target create ${_TARGETNAME}$_core aarch64 \
+ -dap $_CHIPNAME.dap -coreid $_core -cti cti$_core \
+ -dbgbase [set $_TARGETNAME.base($_core)]
+
+ if { $_core != 0 } {
+ # non-boot core examination may fail
+ ${_TARGETNAME}$_core configure -defer-examine
+ } else {
+ # uncomment to use hardware threads pseudo rtos
+ # ${_TARGETNAME}$_core configure -rtos hwthread
+ }
+
+ set _smp_command "$_smp_command ${_TARGETNAME}$_core"
+}
+
+eval $_smp_command
+
+# Set default target to boot core
+targets $_CHIPNAME.lcore0
commit 93f16eed4d4db379671293277e9b6e7d5aba6c9b
Author: Antonio Borneo <bor...@gm...>
Date: Fri Aug 15 14:53:34 2025 +0200
command: fix OpenOCD commands return value for next jimtcl
JimTcl has been so far quite comfortable with new commands that
return error codes not supported by JimTcl itself.
This has been exploited by OpenOCD, allowing the OpenOCD commands
to return OpenOCD error codes mixed with JimTcl error code.
With the change [1] merged in JimTcl branch 'master' for 0.84, any
negative value returned by a command gets interpreted as a syntax
error detected at runtime by the command itself; JimTcl dumps the
correct syntax and returns a valid JimTcl error code that replaces
the negative value.
Since all OpenOCD error codes are negative values, they are all
taken as syntax errors by the new JimTcl. E.g.:
openocd -c exit
dumps
wrong # args: should be "exit ..."
Actually OpenOCD does not need the OpenOCD error code from the
commands, with the exception of the codes:
[a] ERROR_COMMAND_SYNTAX_ERROR, used internally by the command
dispatcher, before returning to JimTcl;
[b] ERROR_COMMAND_CLOSE_CONNECTION, to alert the telnet server
that the current connection should be closed.
With [a] already used internally, only [b] needs to be propagated
through JimTcl and back to the OpenOCD caller.
Map the OpenOCD error code ERROR_COMMAND_CLOSE_CONNECTION to the
existing JimTcl error code JIM_EXIT, originally used only by
JimTcl 'exit' command.
Detect JIM_EXIT in command_run_line() and return to the caller the
original ERROR_COMMAND_CLOSE_CONNECTION.
Let exec_command(), and also its caller jim_command_dispatch(),
to only return JimTcl error codes. Rename it to report the change.
Modify the test suite as now a syntax error does not returns -601
anymore.
While there, drop the association key "retval" as it's not used.
Note: after this change there is no real need to replace the
JimTcl command 'exit' with the OpenOCD version as both produce the
same result. But I prefer keeping the code as is to mask any
future change in the related JimTcl code.
Link: https://github.com/msteveb/jimtcl/commit/5669e84aad22 [1]
Change-Id: Ibd7aaeccdf4d7c9efe72aa71909aef83be5ecd27
Signed-off-by: Antonio Borneo <bor...@gm...>
Reported-by: Andrzej SierżÄga <as...@gm...>
Reviewed-on: https://review.openocd.org/c/openocd/+/9084
Tested-by: jenkins
diff --git a/src/helper/command.c b/src/helper/command.c
index d6993ab76..742eea1b1 100644
--- a/src/helper/command.c
+++ b/src/helper/command.c
@@ -417,7 +417,7 @@ static bool command_can_run(struct command_context *cmd_ctx, struct command *c,
return false;
}
-static int exec_command(Jim_Interp *interp, struct command_context *context,
+static int jim_exec_command(Jim_Interp *interp, struct command_context *context,
struct command *c, int argc, Jim_Obj * const *argv)
{
/* use c->handler */
@@ -467,14 +467,14 @@ static int exec_command(Jim_Interp *interp, struct command_context *context,
free(words);
- int *return_retval = Jim_GetAssocData(interp, "retval");
- if (return_retval)
- *return_retval = retval;
-
if (retval == ERROR_OK)
return JIM_OK;
- return retval;
+ // used by telnet server to close one connection
+ if (retval == ERROR_COMMAND_CLOSE_CONNECTION)
+ return JIM_EXIT;
+
+ return JIM_ERR;
}
int command_run_line(struct command_context *context, char *line)
@@ -484,7 +484,6 @@ int command_run_line(struct command_context *context, char *line)
* results
*/
/* run the line thru a script engine */
- int retval = ERROR_FAIL;
int retcode;
/* Beware! This code needs to be reentrant. It is also possible
* for OpenOCD commands to be invoked directly from Tcl. This would
@@ -499,20 +498,17 @@ int command_run_line(struct command_context *context, char *line)
Jim_DeleteAssocData(interp, "context");
retcode = Jim_SetAssocData(interp, "context", NULL, context);
if (retcode == JIM_OK) {
- /* associated the return value */
- Jim_DeleteAssocData(interp, "retval");
- retcode = Jim_SetAssocData(interp, "retval", NULL, &retval);
- if (retcode == JIM_OK) {
- retcode = Jim_Eval_Named(interp, line, NULL, 0);
-
- Jim_DeleteAssocData(interp, "retval");
- }
+ retcode = Jim_Eval_Named(interp, line, NULL, 0);
Jim_DeleteAssocData(interp, "context");
int inner_retcode = Jim_SetAssocData(interp, "context", NULL, old_context);
if (retcode == JIM_OK)
retcode = inner_retcode;
}
context->current_target_override = saved_target_override;
+
+ if (retcode == JIM_RETURN)
+ retcode = interp->returnCode;
+
if (retcode == JIM_OK) {
const char *result;
int reslen;
@@ -522,25 +518,19 @@ int command_run_line(struct command_context *context, char *line)
command_output_text(context, result);
command_output_text(context, "\n");
}
- retval = ERROR_OK;
- } else if (retcode == JIM_EXIT) {
- /* ignore.
- * exit(Jim_GetExitCode(interp)); */
- } else if (retcode == ERROR_COMMAND_CLOSE_CONNECTION) {
- return retcode;
- } else {
- Jim_MakeErrorMessage(interp);
- /* error is broadcast */
- LOG_USER("%s", Jim_GetString(Jim_GetResult(interp), NULL));
+ return ERROR_OK;
+ }
- if (retval == ERROR_OK) {
- /* It wasn't a low level OpenOCD command that failed */
- return ERROR_FAIL;
- }
- return retval;
+ if (retcode == JIM_EXIT) {
+ // used by telnet server to close one connection
+ return ERROR_COMMAND_CLOSE_CONNECTION;
}
- return retval;
+ Jim_MakeErrorMessage(interp);
+ /* error is broadcast */
+ LOG_USER("%s", Jim_GetString(Jim_GetResult(interp), NULL));
+
+ return ERROR_FAIL;
}
int command_run_linef(struct command_context *context, const char *format, ...)
@@ -867,7 +857,7 @@ static int jim_command_dispatch(Jim_Interp *interp, int argc, Jim_Obj * const *a
if (c->jim_override_target)
cmd_ctx->current_target_override = c->jim_override_target;
- int retval = exec_command(interp, cmd_ctx, c, argc, argv);
+ int retval = jim_exec_command(interp, cmd_ctx, c, argc, argv);
if (c->jim_override_target)
cmd_ctx->current_target_override = saved_target_override;
diff --git a/testing/tcl_commands/utils.tcl b/testing/tcl_commands/utils.tcl
index dfc896661..65e52d2fe 100644
--- a/testing/tcl_commands/utils.tcl
+++ b/testing/tcl_commands/utils.tcl
@@ -32,7 +32,7 @@ namespace eval testing_helpers {
}
proc check_syntax_err script {
- tailcall check_for_error -601 {} $script
+ tailcall check_for_error 1 {} $script
}
proc check_matches {pattern script} {
-----------------------------------------------------------------------
Summary of changes:
src/helper/command.c | 54 +++++++++++---------------
tcl/target/rk3588.cfg | 86 ++++++++++++++++++++++++++++++++++++++++++
testing/tcl_commands/utils.tcl | 2 +-
3 files changed, 109 insertions(+), 33 deletions(-)
create mode 100644 tcl/target/rk3588.cfg
hooks/post-receive
--
Main OpenOCD repository
|
|
From: openocd-gerrit <ope...@us...> - 2025-08-24 11:16:17
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Main OpenOCD repository".
The branch, master has been updated
via 7effc6f825fe8aacfb15ea198994b212f55897cb (commit)
via fe0080478b9e76a4b6b64186b7b705726ac55848 (commit)
from 443139db002d597510bb744bece291c2703c13a3 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 7effc6f825fe8aacfb15ea198994b212f55897cb
Author: Antonio Borneo <bor...@gm...>
Date: Thu Aug 14 22:18:56 2025 +0200
helper: command: inline command_retval_set()
Inline the function command_retval_set(), called only once.
No functional changes.
Change-Id: I4478002adf92c2328e4879019020de5d1dfe89c8
Signed-off-by: Antonio Borneo <bor...@gm...>
Reviewed-on: https://review.openocd.org/c/openocd/+/9083
Tested-by: jenkins
diff --git a/src/helper/command.c b/src/helper/command.c
index 04f4f9a54..d6993ab76 100644
--- a/src/helper/command.c
+++ b/src/helper/command.c
@@ -63,15 +63,6 @@ void *jimcmd_privdata(Jim_Cmd *cmd)
return jimcmd_is_proc(cmd) ? NULL : cmd->u.native.privData;
}
-static int command_retval_set(Jim_Interp *interp, int retval)
-{
- int *return_retval = Jim_GetAssocData(interp, "retval");
- if (return_retval)
- *return_retval = retval;
-
- return (retval == ERROR_OK) ? JIM_OK : retval;
-}
-
extern struct command_context *global_cmd_ctx;
/* dump a single line to the log for the command.
@@ -475,7 +466,15 @@ static int exec_command(Jim_Interp *interp, struct command_context *context,
Jim_DecrRefCount(context->interp, cmd.output);
free(words);
- return command_retval_set(interp, retval);
+
+ int *return_retval = Jim_GetAssocData(interp, "retval");
+ if (return_retval)
+ *return_retval = retval;
+
+ if (retval == ERROR_OK)
+ return JIM_OK;
+
+ return retval;
}
int command_run_line(struct command_context *context, char *line)
commit fe0080478b9e76a4b6b64186b7b705726ac55848
Author: Antonio Borneo <bor...@gm...>
Date: Sat Sep 28 17:58:51 2024 +0200
jimtcl: fix build with jimtcl master branch
Current jimtcl release 0.83 has been tagged on 2024-08-28 and the
new 0.84 is on the way.
The change [1] merged in jimtcl branch 'master' for 0.84 breaks
the build of OpenOCD.
OpenOCD releases are not frequent and jimtcl is now by default an
external build dependency. The release of jimtcl 0.84 could force
OpenOCD to deliver a fix release to support it.
Anticipate the change [1] by detecting it at compile time, without
relying on jimtcl version, and providing an alternative code.
Link: https://github.com/msteveb/jimtcl/commit/5669e84aad22 [1]
Change-Id: I61bf100d447083258aea222aaf15608b7cbe2e57
Signed-off-by: Antonio Borneo <bor...@gm...>
Reviewed-on: https://review.openocd.org/c/openocd/+/8956
Tested-by: jenkins
Reviewed-by: Andrzej SierżÄga <as...@gm...>
diff --git a/src/helper/command.c b/src/helper/command.c
index b70081a4d..04f4f9a54 100644
--- a/src/helper/command.c
+++ b/src/helper/command.c
@@ -45,17 +45,22 @@ static enum command_mode get_command_mode(Jim_Interp *interp, const char *cmd_na
/* set of functions to wrap jimtcl internal data */
static inline bool jimcmd_is_proc(Jim_Cmd *cmd)
{
+#if defined(JIM_CMD_ISPROC)
+ // JIM_VERSION >= 84
+ return cmd->flags & JIM_CMD_ISPROC;
+#else
return cmd->isproc;
+#endif
}
bool jimcmd_is_oocd_command(Jim_Cmd *cmd)
{
- return !cmd->isproc && cmd->u.native.cmdProc == jim_command_dispatch;
+ return !jimcmd_is_proc(cmd) && cmd->u.native.cmdProc == jim_command_dispatch;
}
void *jimcmd_privdata(Jim_Cmd *cmd)
{
- return cmd->isproc ? NULL : cmd->u.native.privData;
+ return jimcmd_is_proc(cmd) ? NULL : cmd->u.native.privData;
}
static int command_retval_set(Jim_Interp *interp, int retval)
-----------------------------------------------------------------------
Summary of changes:
src/helper/command.c | 28 ++++++++++++++++------------
1 file changed, 16 insertions(+), 12 deletions(-)
hooks/post-receive
--
Main OpenOCD repository
|
|
From: openocd-gerrit <ope...@us...> - 2025-08-24 05:05:35
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Main OpenOCD repository".
The branch, master has been updated
via 443139db002d597510bb744bece291c2703c13a3 (commit)
from 1879145bff1b4827f301eeb5039a6a722f3b2d2f (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 443139db002d597510bb744bece291c2703c13a3
Author: Antonio Borneo <bor...@gm...>
Date: Wed Aug 20 11:33:53 2025 +0200
jtag: keep the list of drivers in alphabetic order
The introduction of the driver ch347 breaks the order.
Fix it.
Change-Id: I868fd3ec0b6694fb4bb7b28db0083ab1a9409b1c
Signed-off-by: Antonio Borneo <bor...@gm...>
Reviewed-on: https://review.openocd.org/c/openocd/+/9089
Reviewed-by: Matthias Jentsch <in...@ea...>
Reviewed-by: Tomas Vanek <va...@fb...>
Reviewed-by: ZhiYuanNJ <871...@qq...>
Tested-by: jenkins
diff --git a/src/jtag/interfaces.c b/src/jtag/interfaces.c
index 597196c0e..e29937b58 100644
--- a/src/jtag/interfaces.c
+++ b/src/jtag/interfaces.c
@@ -59,6 +59,9 @@ struct adapter_driver *adapter_drivers[] = {
#if BUILD_BUS_PIRATE == 1
&buspirate_adapter_driver,
#endif
+#if BUILD_CH347 == 1
+ &ch347_adapter_driver,
+#endif
#if BUILD_CMSIS_DAP_USB == 1 || BUILD_CMSIS_DAP_HID == 1
&cmsis_dap_adapter_driver,
#endif
@@ -159,8 +162,6 @@ struct adapter_driver *adapter_drivers[] = {
&xlnx_pcie_xvc_adapter_driver,
&xlnx_axi_xvc_adapter_driver,
#endif
-#if BUILD_CH347 == 1
- &ch347_adapter_driver,
-#endif
+
NULL,
};
-----------------------------------------------------------------------
Summary of changes:
src/jtag/interfaces.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
hooks/post-receive
--
Main OpenOCD repository
|
|
From: openocd-gerrit <ope...@us...> - 2025-08-24 05:05:11
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Main OpenOCD repository".
The branch, master has been updated
via 1879145bff1b4827f301eeb5039a6a722f3b2d2f (commit)
via b4a19768863825b5acddd6adc3ec44fd04acdea1 (commit)
via fe50eceaff056d366a1f33bc21f59fc830e4ca83 (commit)
from 0c575ced95219f11d554bdf5c34008362fb38f7b (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 1879145bff1b4827f301eeb5039a6a722f3b2d2f
Author: Tomas Vanek <va...@fb...>
Date: Sat Feb 8 22:40:43 2025 +0100
drivers/ch347: limit SWD packet size by processing time
CH347 chip firmware probably does not service USB poll/requests
from the host during processing of SWD packet. If the processing
takes longer than approx 8 ms, USB host disconnects the adapter
from the bus as if it were dead.
To avoid disconnect, compute approximate processing time
of SWD transactions and flush the queue if the total time
gets over the limit (use 7 ms to keep some safety margin).
Allow ch347_swd_send_idle() to split the requested delay
to more partial sequences. It prevents USB disconnect at beginning
of target examine, when memaccess 255 clk is used.
Also memaccess > 255 clk is now possible.
Set the maximal divisor to fit the longest ADI sequence
into 7 ms processing time.
Tested on a linux x64 PC and RPi 5.
Change-Id: Ibdcff4de52e3eb4d86ed83af81a1c64f1f9b5d24
Signed-off-by: Tomas Vanek <va...@fb...>
Reviewed-on: https://review.openocd.org/c/openocd/+/8746
Tested-by: jenkins
Reviewed-by: ZhiYuanNJ <871...@qq...>
diff --git a/src/jtag/drivers/ch347.c b/src/jtag/drivers/ch347.c
index e420410f1..8f563acaf 100644
--- a/src/jtag/drivers/ch347.c
+++ b/src/jtag/drivers/ch347.c
@@ -115,13 +115,15 @@
#define CH347_CMD_SWD_REG_W 0xA0 // SWD Interface write reg
#define CH347_CMD_SWD_SEQ_W 0xA1 // SWD Interface write spec seq
#define CH347_CMD_SWD_REG_R 0xA2 // SWD Interface read reg
-#define CH347_MAX_SEND_CMD 19 // max send cmd number
-#define CH347_MAX_SEND_BUF 0X200
-#define CH347_MAX_RECV_BUF 0X200
+#define CH347_MAX_PROCESSING_US 7000 // max time in us for packet processing
+ // USB hosts disconnect the adapter if SWD processing takes more!
+#define CH347_MAX_SEND_BUF USBC_PACKET_USBHS
+#define CH347_MAX_RECV_BUF USBC_PACKET_USBHS
#define CH347_MAX_CMD_BUF 128
#define CH347_SWD_CLOCK_MAX 5000
#define CH347_SWD_CLOCK_BASE 1000
-#define CH347_SWD_CLOCK_MAX_DIVISOR 8
+// limited by the longest sequence processing time
+#define CH347_SWD_CLOCK_MAX_DIVISOR (CH347_MAX_PROCESSING_US / swd_seq_dormant_to_swd_len)
#define CH347_EPOUT 0x06u // the usb endpoint number for writing
#define CH347_EPIN 0x86u // the usb endpoint number for reading
@@ -240,6 +242,8 @@ struct ch347_swd_context {
int need_recv_len;
int queued_retval;
int sent_cmd_count;
+ unsigned int clk_divisor;
+ unsigned int total_swd_clk;
struct list_head send_cmd_head;
struct list_head free_cmd_head;
struct ch347_swd_io ch347_cmd_buf[CH347_MAX_CMD_BUF];
@@ -1640,6 +1644,7 @@ static int ch347_swd_init_cmd(uint8_t clock_divisor)
retval = ch347_single_read_get_byte(0, &init_result);
LOG_DEBUG("SWD init clk div %" PRIu8 ", result %02" PRIx8,
clock_divisor, init_result);
+ ch347_swd_context.clk_divisor = clock_divisor;
return retval;
}
@@ -1734,7 +1739,7 @@ static int ch347_speed_get_index(int khz, int *speed_idx)
// Don't allow too low clk speeds: packet processing is limited to ~8 msec
// or triggers host USB disconnect
*speed_idx = MIN(DIV_ROUND_UP(CH347_SWD_CLOCK_BASE, khz),
- CH347_SWD_CLOCK_MAX_DIVISOR);
+ (int)CH347_SWD_CLOCK_MAX_DIVISOR);
}
return ERROR_OK;
}
@@ -1990,6 +1995,7 @@ static void ch347_write_swd_reg(uint8_t cmd, const uint32_t out)
ch347_swd_context.send_buf[ch347_swd_context.send_len++] = parity_u32(out);
// 0xA0 + 1 byte(3bit ACK)
ch347_swd_context.need_recv_len += (1 + 1);
+ ch347_swd_context.total_swd_clk += 46;
}
static void ch347_write_spec_seq(const uint8_t *out, uint8_t out_len)
@@ -2001,6 +2007,7 @@ static void ch347_write_spec_seq(const uint8_t *out, uint8_t out_len)
for (uint8_t i = 0; i < DIV_ROUND_UP(out_len, 8); i++)
ch347_swd_context.send_buf[ch347_swd_context.send_len++] = out ? out[i] : 0x00;
ch347_swd_context.need_recv_len += 1; // 0xA1
+ ch347_swd_context.total_swd_clk += out_len;
}
static void ch347_read_swd_reg(uint8_t cmd)
@@ -2011,6 +2018,7 @@ static void ch347_read_swd_reg(uint8_t cmd)
ch347_swd_context.send_buf[ch347_swd_context.send_len++] = cmd;
// 0xA2 + 1 byte(3bit ACK) + 4 byte(data) + 1 byte(1bit parity+1bit trn)
ch347_swd_context.need_recv_len += 1 + 1 + 4 + 1;
+ ch347_swd_context.total_swd_clk += 46;
}
static int ch347_swd_switch_out(enum swd_special_seq seq, const uint8_t *out, unsigned int out_len)
@@ -2080,22 +2088,81 @@ static int ch347_swd_run_queue_inner(void);
static int ch347_swd_send_idle(uint32_t ap_delay_clk)
{
- struct ch347_swd_io *pswd_io = ch347_get_one_swd_io();
- if (!pswd_io) {
- int retval = ch347_swd_run_queue_inner();
- if (retval != ERROR_OK)
- return retval;
+ bool run_q = false;
+ struct ch347_swd_io *pswd_io = NULL;
+ unsigned int max_processing_clk = ch347_swd_context.clk_divisor
+ ? CH347_MAX_PROCESSING_US / ch347_swd_context.clk_divisor
+ : CH347_MAX_PROCESSING_US * 5;
+ bool more_q_runs =
+ 1 + 1 + 1 + DIV_ROUND_UP(ap_delay_clk, 8) > CH347_MAX_SEND_BUF
+ && ap_delay_clk > max_processing_clk;
+
+ if (ch347_swd_context.sent_cmd_count) {
+ unsigned int expected_total_clk = ch347_swd_context.total_swd_clk + ap_delay_clk;
+ unsigned int expected_send_len = ch347_swd_context.send_len
+ + 1 + 1 + 1 + DIV_ROUND_UP(ap_delay_clk, 8);
+ // 0xA1 + Len + rev + n byte(delay)
+ unsigned int expected_recv_len = ch347_swd_context.need_recv_len + 1;
+ // 0xA1
+ unsigned int expected_time = ch347_swd_context.clk_divisor
+ ? expected_total_clk * ch347_swd_context.clk_divisor
+ : expected_total_clk / 5;
+ if (expected_time > CH347_MAX_PROCESSING_US
+ || expected_send_len > CH347_MAX_SEND_BUF
+ || expected_recv_len > CH347_MAX_RECV_BUF) {
+ int send_room = CH347_MAX_SEND_BUF - ch347_swd_context.send_len - 1 - 1 - 1;
+ if (more_q_runs
+ && send_room > 0
+ && expected_recv_len <= CH347_MAX_RECV_BUF
+ && ch347_swd_context.total_swd_clk < max_processing_clk) {
+ pswd_io = ch347_get_one_swd_io();
+ if (pswd_io) {
+ // fill the rest of queue/time by part of delay
+ unsigned int this_delay_clk = MIN(ap_delay_clk, 255);
+ if ((unsigned int)send_room * 8 < this_delay_clk)
+ this_delay_clk = send_room * 8;
+ if (max_processing_clk - ch347_swd_context.total_swd_clk < this_delay_clk)
+ this_delay_clk = max_processing_clk - ch347_swd_context.total_swd_clk;
+ LOG_DEBUG_IO("partial delay %u clk", this_delay_clk);
+ ch347_write_spec_seq(NULL, this_delay_clk);
+ list_add_tail(&pswd_io->list_entry, &ch347_swd_context.send_cmd_head);
+ ap_delay_clk -= this_delay_clk;
+ }
+ }
+ run_q = true;
+ }
+ }
+
+ do {
+ if (!run_q)
+ pswd_io = ch347_get_one_swd_io();
- pswd_io = ch347_get_one_swd_io();
if (!pswd_io) {
- LOG_ERROR("ch347 SWD queue not empty after ch347_swd_run_queue");
- ch347_swd_context.queued_retval = ERROR_FAIL;
- return ERROR_FAIL;
+ int retval = ch347_swd_run_queue_inner();
+ if (retval != ERROR_OK)
+ return retval;
+
+ pswd_io = ch347_get_one_swd_io();
+ if (!pswd_io) {
+ LOG_ERROR("ch347 SWD queue not empty after ch347_swd_run_queue");
+ ch347_swd_context.queued_retval = ERROR_FAIL;
+ return ERROR_FAIL;
+ }
}
- }
- ch347_write_spec_seq(NULL, ap_delay_clk);
- list_add_tail(&pswd_io->list_entry, &ch347_swd_context.send_cmd_head);
+ unsigned int send_room = CH347_MAX_SEND_BUF - 1 - 1 - 1;
+ unsigned int this_delay_clk = MIN(ap_delay_clk, 255);
+ if (send_room * 8 < this_delay_clk)
+ this_delay_clk = send_room * 8;
+ if (max_processing_clk < this_delay_clk)
+ this_delay_clk = max_processing_clk;
+ LOG_DEBUG_IO("delay %u clk", this_delay_clk);
+ ch347_write_spec_seq(NULL, this_delay_clk);
+ list_add_tail(&pswd_io->list_entry, &ch347_swd_context.send_cmd_head);
+ ap_delay_clk -= this_delay_clk;
+ run_q = true;
+ pswd_io = NULL;
+ } while (ap_delay_clk);
return ERROR_OK;
}
@@ -2236,6 +2303,7 @@ skip:
ch347_swd_context.need_recv_len = CH347_CMD_HEADER;
ch347_swd_context.recv_len = 0;
ch347_swd_context.sent_cmd_count = 0;
+ ch347_swd_context.total_swd_clk = 0;
retval = ch347_swd_context.queued_retval;
ch347_swd_context.queued_retval = ERROR_OK;
return retval;
@@ -2255,22 +2323,28 @@ static int ch347_swd_run_queue(void)
static int ch347_swd_queue_cmd(uint8_t cmd, uint32_t *dst, uint32_t data, uint32_t ap_delay_clk)
{
int retval = ERROR_OK;
- if (ap_delay_clk > 255)
- ap_delay_clk = 255; // limit imposed by spec. seq. size in one byte
-
- if (ch347_swd_context.sent_cmd_count >= CH347_MAX_SEND_CMD) {
- retval = ch347_swd_run_queue_inner();
- if (retval != ERROR_OK)
- return retval;
+ bool run_q = false;
+ if (ch347_swd_context.sent_cmd_count) {
+ unsigned int expected_total_clk = ch347_swd_context.total_swd_clk
+ + 46 // SWD transaction
+ + ap_delay_clk
+ + 8; // 8 idle cycles at the end of queue
+ unsigned int expected_time = ch347_swd_context.clk_divisor
+ ? expected_total_clk * ch347_swd_context.clk_divisor
+ : expected_total_clk / 5;
+ if (expected_time > CH347_MAX_PROCESSING_US) {
+ LOG_DEBUG_IO("Expected queue run %u cycles, with this cmd %u",
+ ch347_swd_context.total_swd_clk, expected_total_clk);
+ run_q = true;
+ } else if (!ch347_chk_buf_size(cmd, ap_delay_clk)) {
+ run_q = true;
+ }
}
- if (!ch347_chk_buf_size(cmd, ap_delay_clk)) {
- retval = ch347_swd_run_queue_inner();
- if (retval != ERROR_OK)
- return retval;
- }
+ struct ch347_swd_io *pswd_io = NULL;
+ if (!run_q)
+ pswd_io = ch347_get_one_swd_io();
- struct ch347_swd_io *pswd_io = ch347_get_one_swd_io();
if (!pswd_io) {
retval = ch347_swd_run_queue_inner();
if (retval != ERROR_OK)
commit b4a19768863825b5acddd6adc3ec44fd04acdea1
Author: Tomas Vanek <va...@fb...>
Date: Sun Feb 9 11:35:11 2025 +0100
drivers/ch347: fix SWD log messages
Remove annoying and not too informative error message `ack != SWD_ACK_OK`.
Fix copy&paste error in message `SWD Read data parity mismatch` logged
in case of a write returning bad ack.
Raise log level of read/write descriptive message to DEBUG when reg
read/writes returns bad ack.
Change-Id: Ic3433ae8bd02472756adf269658bfba0ba34dc26
Signed-off-by: Tomas Vanek <va...@fb...>
Reviewed-on: https://review.openocd.org/c/openocd/+/8747
Reviewed-by: ZhiYuanNJ <871...@qq...>
Tested-by: jenkins
diff --git a/src/jtag/drivers/ch347.c b/src/jtag/drivers/ch347.c
index 57d1d0fdc..e420410f1 100644
--- a/src/jtag/drivers/ch347.c
+++ b/src/jtag/drivers/ch347.c
@@ -2153,13 +2153,25 @@ static int ch347_swd_run_queue_inner(void)
/* Devices do not reply to DP_TARGETSEL write
cmd, ignore received ack */
check_ack = swd_cmd_returns_ack(pswd_io->cmd);
- if (ack != SWD_ACK_OK && check_ack) {
- ch347_swd_context.queued_retval = swd_ack_to_error_code(ack);
- LOG_ERROR("ack != SWD_ACK_OK");
- goto skip;
- }
if (pswd_io->cmd & SWD_CMD_RNW) {
uint32_t data = buf_get_u32(&recv_buf[recv_len], 0, 32);
+
+ LOG_CUSTOM_LEVEL((check_ack && ack != SWD_ACK_OK)
+ ? LOG_LVL_DEBUG : LOG_LVL_DEBUG_IO,
+ "%s%s %s read reg %X = %08" PRIx32,
+ check_ack ? "" : "ack ignored ",
+ ack == SWD_ACK_OK ? "OK" :
+ ack == SWD_ACK_WAIT ? "WAIT" :
+ ack == SWD_ACK_FAULT ? "FAULT" : "JUNK",
+ pswd_io->cmd & SWD_CMD_APNDP ? "AP" : "DP",
+ (pswd_io->cmd & SWD_CMD_A32) >> 1,
+ data);
+
+ if (ack != SWD_ACK_OK && check_ack) {
+ ch347_swd_context.queued_retval = swd_ack_to_error_code(ack);
+ goto skip;
+ }
+
uint32_t parity = buf_get_u32(&recv_buf[recv_len], 32, 1);
if (parity != (uint32_t)parity_u32(data)) {
LOG_ERROR("SWD Read data parity mismatch");
@@ -2167,15 +2179,6 @@ static int ch347_swd_run_queue_inner(void)
goto skip;
}
- LOG_DEBUG_IO("%s%s %s %s reg %X = %08X - " PRIx32,
- check_ack ? "" : "ack ignored ",
- ack == SWD_ACK_OK ? "OK" : ack == SWD_ACK_WAIT ? "WAIT" :
- ack == SWD_ACK_FAULT ? "FAULT" : "JUNK",
- pswd_io->cmd & SWD_CMD_APNDP ? "AP" : "DP",
- pswd_io->cmd & SWD_CMD_RNW ? "read" : "write",
- (pswd_io->cmd & SWD_CMD_A32) >> 1,
- data);
-
if (pswd_io->dst)
*pswd_io->dst = data;
} else {
@@ -2190,19 +2193,22 @@ static int ch347_swd_run_queue_inner(void)
/* Devices do not reply to DP_TARGETSEL write
cmd, ignore received ack */
check_ack = swd_cmd_returns_ack(pswd_io->cmd);
+
+ LOG_CUSTOM_LEVEL((check_ack && ack != SWD_ACK_OK)
+ ? LOG_LVL_DEBUG : LOG_LVL_DEBUG_IO,
+ "%s%s %s write reg %X = %08" PRIx32,
+ check_ack ? "" : "ack ignored ",
+ ack == SWD_ACK_OK ? "OK" :
+ ack == SWD_ACK_WAIT ? "WAIT" :
+ ack == SWD_ACK_FAULT ? "FAULT" : "JUNK",
+ pswd_io->cmd & SWD_CMD_APNDP ? "AP" : "DP",
+ (pswd_io->cmd & SWD_CMD_A32) >> 1,
+ pswd_io->value);
+
if (ack != SWD_ACK_OK && check_ack) {
ch347_swd_context.queued_retval = swd_ack_to_error_code(ack);
- LOG_ERROR("SWD Read data parity mismatch");
goto skip;
}
- LOG_DEBUG_IO("%s%s %s %s reg %X = %08X - " PRIx32,
- check_ack ? "" : "ack ignored ",
- ack == SWD_ACK_OK ? "OK" : ack == SWD_ACK_WAIT ? "WAIT" :
- ack == SWD_ACK_FAULT ? "FAULT" : "JUNK",
- pswd_io->cmd & SWD_CMD_APNDP ? "AP" : "DP",
- pswd_io->cmd & SWD_CMD_RNW ? "read" : "write",
- (pswd_io->cmd & SWD_CMD_A32) >> 1,
- pswd_io->value);
} else {
ch347_swd_context.queued_retval = ERROR_FAIL;
LOG_ERROR("CH347 usb write/read failed recv_len = %d", recv_len);
commit fe50eceaff056d366a1f33bc21f59fc830e4ca83
Author: Tomas Vanek <va...@fb...>
Date: Sat Feb 8 22:00:40 2025 +0100
drivers/ch347: don't loose swd_read/write_reg errors
SWD read_reg() and write_reg() methods are declared with
void return. Save the error code to ch347_swd_context.queued_retval
(will be returned later by SWD run method) instead of ignoring it.
Change-Id: Ib95a1bc3398712ac2f8520c79d281633d75f0335
Signed-off-by: Tomas Vanek <va...@fb...>
Reviewed-on: https://review.openocd.org/c/openocd/+/8745
Reviewed-by: ZhiYuanNJ <871...@qq...>
Tested-by: jenkins
diff --git a/src/jtag/drivers/ch347.c b/src/jtag/drivers/ch347.c
index 530ac5096..57d1d0fdc 100644
--- a/src/jtag/drivers/ch347.c
+++ b/src/jtag/drivers/ch347.c
@@ -2333,13 +2333,17 @@ static int ch347_swd_switch_seq(enum swd_special_seq seq)
static void ch347_swd_read_reg(uint8_t cmd, uint32_t *value, uint32_t ap_delay_clk)
{
assert(cmd & SWD_CMD_RNW);
- ch347_swd_queue_cmd(cmd, value, 0, ap_delay_clk);
+ int retval = ch347_swd_queue_cmd(cmd, value, 0, ap_delay_clk);
+ if (retval != ERROR_OK)
+ ch347_swd_context.queued_retval = retval;
}
static void ch347_swd_write_reg(uint8_t cmd, uint32_t value, uint32_t ap_delay_clk)
{
assert(!(cmd & SWD_CMD_RNW));
- ch347_swd_queue_cmd(cmd, NULL, value, ap_delay_clk);
+ int retval = ch347_swd_queue_cmd(cmd, NULL, value, ap_delay_clk);
+ if (retval != ERROR_OK)
+ ch347_swd_context.queued_retval = retval;
}
static const struct swd_driver ch347_swd = {
-----------------------------------------------------------------------
Summary of changes:
src/jtag/drivers/ch347.c | 194 +++++++++++++++++++++++++++++++++--------------
1 file changed, 139 insertions(+), 55 deletions(-)
hooks/post-receive
--
Main OpenOCD repository
|
|
From: openocd-gerrit <ope...@us...> - 2025-08-24 05:04:58
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Main OpenOCD repository".
The branch, master has been updated
via 0c575ced95219f11d554bdf5c34008362fb38f7b (commit)
from 87f78286794f6d8fbf885715b01b685f98885d9d (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 0c575ced95219f11d554bdf5c34008362fb38f7b
Author: Tomas Vanek <va...@fb...>
Date: Sat Feb 8 21:36:15 2025 +0100
drivers/ch347: fix conditional sending of idle clock cycles
ch347_swd_run_queue() fulfilled ADI requirement for idle cycles
after the last transaction just if there was room in the buffer.
A lazy programmer avoided this way the danger of recurrent call.
Introduce ch347_swd_run_queue_inner() without sending idle cycles.
They are useless when flushing the queue to get room for the next
transaction.
ch347_swd_run_queue() now can make room for idle cycles
in the queue without recursion.
While on it remove two useless debug logs showing ap_delay_clk
value and prevent the overflow of ap_delay_clk forcing it to be <= 255.
Change-Id: Ia7b7f0d373ff463e2f0742bdd068c3833c57f340
Signed-off-by: Tomas Vanek <va...@fb...>
Reviewed-on: https://review.openocd.org/c/openocd/+/8744
Reviewed-by: ZhiYuanNJ <871...@qq...>
Tested-by: jenkins
diff --git a/src/jtag/drivers/ch347.c b/src/jtag/drivers/ch347.c
index ecec155f7..530ac5096 100644
--- a/src/jtag/drivers/ch347.c
+++ b/src/jtag/drivers/ch347.c
@@ -2076,13 +2076,13 @@ static bool ch347_chk_buf_size(uint8_t cmd, uint32_t ap_delay_clk)
return flush;
}
-static int ch347_swd_run_queue(void);
+static int ch347_swd_run_queue_inner(void);
static int ch347_swd_send_idle(uint32_t ap_delay_clk)
{
struct ch347_swd_io *pswd_io = ch347_get_one_swd_io();
if (!pswd_io) {
- int retval = ch347_swd_run_queue();
+ int retval = ch347_swd_run_queue_inner();
if (retval != ERROR_OK)
return retval;
@@ -2099,7 +2099,7 @@ static int ch347_swd_send_idle(uint32_t ap_delay_clk)
return ERROR_OK;
}
-static int ch347_swd_run_queue(void)
+static int ch347_swd_run_queue_inner(void)
{
LOG_DEBUG_IO("Executing %u queued transactions", ch347_swd_context.sent_cmd_count);
if (ch347_swd_context.queued_retval != ERROR_OK) {
@@ -2107,20 +2107,7 @@ static int ch347_swd_run_queue(void)
goto skip;
}
- /* A transaction must be followed by another transaction or at least 8
- idle cycles to ensure that data is clocked through the AP. */
- if ((ch347_swd_context.send_len + (1 + 2 + 1)) > CH347_MAX_SEND_BUF)
- goto skip_idle;
-
- if ((ch347_swd_context.need_recv_len + 1) > CH347_MAX_RECV_BUF)
- goto skip_idle;
-
- int retval = ch347_swd_send_idle((uint32_t)8);
- if (retval != ERROR_OK)
- return retval;
-
-skip_idle:
- retval = ch347_swd_queue_flush();
+ int retval = ch347_swd_queue_flush();
if (retval != ERROR_OK)
return retval;
@@ -2248,27 +2235,38 @@ skip:
return retval;
}
+static int ch347_swd_run_queue(void)
+{
+ /* A transaction must be followed by another transaction or at least 8
+ idle cycles to ensure that data is clocked through the AP. */
+ int retval = ch347_swd_send_idle(8);
+ if (retval != ERROR_OK)
+ return retval;
+
+ return ch347_swd_run_queue_inner();
+}
+
static int ch347_swd_queue_cmd(uint8_t cmd, uint32_t *dst, uint32_t data, uint32_t ap_delay_clk)
{
+ int retval = ERROR_OK;
if (ap_delay_clk > 255)
- LOG_DEBUG("ap_delay_clk = %d", ap_delay_clk);
+ ap_delay_clk = 255; // limit imposed by spec. seq. size in one byte
- int retval = ERROR_OK;
if (ch347_swd_context.sent_cmd_count >= CH347_MAX_SEND_CMD) {
- retval = ch347_swd_run_queue();
+ retval = ch347_swd_run_queue_inner();
if (retval != ERROR_OK)
return retval;
}
if (!ch347_chk_buf_size(cmd, ap_delay_clk)) {
- retval = ch347_swd_run_queue();
+ retval = ch347_swd_run_queue_inner();
if (retval != ERROR_OK)
return retval;
}
struct ch347_swd_io *pswd_io = ch347_get_one_swd_io();
if (!pswd_io) {
- retval = ch347_swd_run_queue();
+ retval = ch347_swd_run_queue_inner();
if (retval != ERROR_OK)
return retval;
@@ -2294,12 +2292,10 @@ static int ch347_swd_queue_cmd(uint8_t cmd, uint32_t *dst, uint32_t data, uint32
ch347_swd_context.sent_cmd_count++;
list_add_tail(&pswd_io->list_entry, &ch347_swd_context.send_cmd_head);
+
// Insert idle cycles after AP accesses to avoid WAIT
- if (cmd & SWD_CMD_APNDP) {
- if (ap_delay_clk == 0)
- LOG_DEBUG("ap_delay_clk == 0");
+ if (ap_delay_clk)
retval = ch347_swd_send_idle(ap_delay_clk);
- }
return retval;
}
-----------------------------------------------------------------------
Summary of changes:
src/jtag/drivers/ch347.c | 48 ++++++++++++++++++++++--------------------------
1 file changed, 22 insertions(+), 26 deletions(-)
hooks/post-receive
--
Main OpenOCD repository
|
|
From: openocd-gerrit <ope...@us...> - 2025-08-24 05:03:49
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Main OpenOCD repository".
The branch, master has been updated
via 87f78286794f6d8fbf885715b01b685f98885d9d (commit)
via c7aaaac809ebb71b20dee4bacad22a56533e85f5 (commit)
from 99cb670becdb1e00fc75997383325550b02accdd (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 87f78286794f6d8fbf885715b01b685f98885d9d
Author: Tomas Vanek <va...@fb...>
Date: Sun Nov 5 06:49:18 2023 +0100
drivers/ch347: add SWD speed settings
SWD has completely different speed setting than JTAG.
There is no official chip documentation. The trial and error
method on SWD init USB packet discovered a byte parameter used
as a divisor from 1 MHz maximal clock.
Prevent setting too low clocks as it may trigger USB disconnects.
CH347T/F versions 5.44/1.1 add 5 MHz SWD speed at divisor/index 0.
CH347F related parts co-authored by ZhiYuanNJ <871...@qq...>
Signed-off-by: Tomas Vanek <va...@fb...>
Change-Id: I5a990a43dcd7a6d73c71b795283a9fbdff489bf4
Reviewed-on: https://review.openocd.org/c/openocd/+/8743
Reviewed-by: ZhiYuanNJ <871...@qq...>
Tested-by: jenkins
diff --git a/src/jtag/drivers/ch347.c b/src/jtag/drivers/ch347.c
index f4f013a79..ecec155f7 100644
--- a/src/jtag/drivers/ch347.c
+++ b/src/jtag/drivers/ch347.c
@@ -119,6 +119,9 @@
#define CH347_MAX_SEND_BUF 0X200
#define CH347_MAX_RECV_BUF 0X200
#define CH347_MAX_CMD_BUF 128
+#define CH347_SWD_CLOCK_MAX 5000
+#define CH347_SWD_CLOCK_BASE 1000
+#define CH347_SWD_CLOCK_MAX_DIVISOR 8
#define CH347_EPOUT 0x06u // the usb endpoint number for writing
#define CH347_EPIN 0x86u // the usb endpoint number for reading
@@ -205,6 +208,7 @@ struct ch347_info {
bool use_bitwise_mode;
enum pack_size pack_size; // see: pack_size for explanation
int max_len; // in STANDARD_PACK or bitwise mode we can send only one USBC_PACKET_USBHS sized package
+ bool swclk_5mhz_supported;
// a "scratchpad" where we record all bytes for one command
uint8_t scratchpad_cmd_type; // command type
@@ -1506,6 +1510,8 @@ static int ch347_open_device(void)
if (ch347.chip_variant == CH347T) {
if (swd_mode) {
+ ch347.swclk_5mhz_supported = ch347_device_descriptor.bcdDevice >= 0x544;
+
if (ch347_device_descriptor.bcdDevice < 0x441)
LOG_WARNING("CH347T version older than 4.41 probably does not support SWD transport");
@@ -1520,6 +1526,8 @@ static int ch347_open_device(void)
LOG_INFO("Please upgrade CH347T firmware to a production version >= 5.44");
} else if (ch347.chip_variant == CH347F) {
+ ch347.swclk_5mhz_supported = ch347_device_descriptor.bcdDevice >= 0x101;
+
if (ch347_device_descriptor.bcdDevice < 0x101)
LOG_INFO("Please upgrade CH347F firmware to a production version >= 1.1");
}
@@ -1608,16 +1616,44 @@ static int ch347_adapter_set_speed(uint8_t clock_index)
return ch347_adapter_init(clock_index, &unused);
}
+/**
+ * @brief swd init function
+ * @param clock_divisor Divisor of base SWD frequency 1 MHz or 0 for fast 5 MHz clock
+ *
+ * @return ERROR_OK on success
+ */
+static int ch347_swd_init_cmd(uint8_t clock_divisor)
+{
+ int retval = ch347_cmd_start_next(CH347_CMD_SWD_INIT);
+ if (retval != ERROR_OK)
+ return retval;
+
+ uint8_t cmd_data[] = {0x40, 0x42, 0x0f, 0x00, clock_divisor, 0x00, 0x00, 0x00 };
+ retval = ch347_scratchpad_add_bytes(cmd_data, ARRAY_SIZE(cmd_data));
+ if (retval != ERROR_OK)
+ return retval;
+
+ /* TODO: CH347_CMD_SWD_INIT reads one data byte.
+ But how can we decide if SWD init was successfully executed?
+ Return an error code if init was failed */
+ uint8_t init_result = 0;
+ retval = ch347_single_read_get_byte(0, &init_result);
+ LOG_DEBUG("SWD init clk div %" PRIu8 ", result %02" PRIx8,
+ clock_divisor, init_result);
+ return retval;
+}
+
/**
* @brief Initializes the JTAG interface and set CH347 TCK frequency
*
* @param speed_index speed index for JTAG_INIT command
- * @return Success returns ERROR_OKï¼failed returns ERROR_FAIL
+ * @return Success returns ERROR_OK, failed returns ERROR_FAIL
*/
static int ch347_speed_set(int speed_index)
{
if (swd_mode)
- return ERROR_OK;
+ return ch347_swd_init_cmd(speed_index);
+
int retval = ch347_adapter_set_speed(speed_index);
if (retval != ERROR_OK) {
LOG_ERROR("Couldn't set CH347 speed");
@@ -1660,6 +1696,14 @@ static int ch347_init_pack_size(void)
*/
static int ch347_speed_get(int speed_idx, int *khz)
{
+ if (swd_mode) {
+ if (speed_idx)
+ *khz = DIV_ROUND_UP(CH347_SWD_CLOCK_BASE, speed_idx);
+ else
+ *khz = CH347_SWD_CLOCK_MAX;
+ return ERROR_OK;
+ }
+
int retval = ch347_init_pack_size();
if (retval != ERROR_OK)
return retval;
@@ -1682,6 +1726,19 @@ static int ch347_speed_get_index(int khz, int *speed_idx)
LOG_ERROR("Adaptive clocking not supported");
return ERROR_FAIL;
}
+
+ if (swd_mode) {
+ if (khz >= CH347_SWD_CLOCK_MAX && ch347.swclk_5mhz_supported) {
+ *speed_idx = 0;
+ } else {
+ // Don't allow too low clk speeds: packet processing is limited to ~8 msec
+ // or triggers host USB disconnect
+ *speed_idx = MIN(DIV_ROUND_UP(CH347_SWD_CLOCK_BASE, khz),
+ CH347_SWD_CLOCK_MAX_DIVISOR);
+ }
+ return ERROR_OK;
+ }
+
// when checking with speed index 9 we can see if the device supports STANDARD_PACK or LARGER_PACK mode
int retval = ch347_init_pack_size();
if (retval != ERROR_OK)
@@ -1809,27 +1866,6 @@ static const struct command_registration ch347_command_handlers[] = {
COMMAND_REGISTRATION_DONE
};
-/**
- * @brief swd init function
- *
- * @return ERROR_OK on success
- */
-static int ch347_swd_init_cmd(void)
-{
- int retval = ch347_cmd_start_next(CH347_CMD_SWD_INIT);
- if (retval != ERROR_OK)
- return retval;
- uint8_t cmd_data[] = {0x40, 0x42, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00 };
- retval = ch347_scratchpad_add_bytes(cmd_data, ARRAY_SIZE(cmd_data));
- if (retval != ERROR_OK)
- return retval;
- /* TODO: CH347_CMD_SWD_INIT reads one data byte.
- But how can we decide if SWD init was successfully executed?
- Return an error code if init was failed */
- uint8_t unused;
- return ch347_single_read_get_byte(0, &unused);
-}
-
/**
* @brief CH347 Initialization function
*
@@ -1862,7 +1898,8 @@ static int ch347_init(void)
retval = ch347_init_pack_size();
if (retval != ERROR_OK)
return retval;
- retval = ch347_swd_init_cmd();
+
+ retval = ch347_swd_init_cmd(1);
}
return retval;
}
commit c7aaaac809ebb71b20dee4bacad22a56533e85f5
Author: Tomas Vanek <va...@fb...>
Date: Sun Nov 5 06:42:25 2023 +0100
drivers/ch347: detailed packet logging
Split USB data packet logs by CH347 protocol commands
Signed-off-by: Tomas Vanek <va...@fb...>
Change-Id: I0f61529755f007ab13f42643676199790c5be2d4
Reviewed-on: https://review.openocd.org/c/openocd/+/8742
Reviewed-by: ZhiYuanNJ <871...@qq...>
Tested-by: jenkins
diff --git a/src/jtag/drivers/ch347.c b/src/jtag/drivers/ch347.c
index 8c9c784cd..f4f013a79 100644
--- a/src/jtag/drivers/ch347.c
+++ b/src/jtag/drivers/ch347.c
@@ -261,6 +261,102 @@ static inline bool ch347_is_single_cmd_type(uint8_t type)
return type == CH347_CMD_GPIO || type == CH347_CMD_JTAG_INIT || type == CH347_CMD_SWD_INIT;
}
+static void log_buf_dump(const uint8_t *data, unsigned int size, bool recv)
+{
+ unsigned int i = 0, j = 0;
+ unsigned int n = size * 3 + 1;
+ char *str = malloc(n);
+ if (!str)
+ return;
+
+ while (i < size && j < n) {
+ uint8_t cmd = data[i++];
+ hexify(str + j, &cmd, 1, n - j);
+ j += 2;
+ str[j++] = ' ';
+
+ unsigned int cmd_payload_size = le_to_h_u16(data + i);
+ if (i + 2 <= size && j + 4 < n) {
+ hexify(str + j, data + i, 2, n - j);
+ i += 2;
+ j += 4;
+ str[j++] = ' ';
+ }
+
+ if (cmd == CH347_CMD_SWD) {
+ // nested SWD commands
+ str[j] = '\0';
+ if (i + cmd_payload_size > size) {
+ LOG_DEBUG_IO("%s - bad size", str);
+ cmd_payload_size = size - i;
+ } else {
+ LOG_DEBUG_IO("%s", str);
+ }
+ j = 0;
+ unsigned int swd_base_i = i;
+
+ while (i < swd_base_i + cmd_payload_size) {
+ uint8_t swd_cmd = data[i++];
+ hexify(str + j, &swd_cmd, 1, n - j);
+ j += 2;
+ str[j++] = ' ';
+
+ unsigned int swd_bits = 0;
+ unsigned int swd_payload_size = 0;
+ if (!recv) {
+ if (i + 2 <= size) {
+ swd_bits = le_to_h_u16(data + i);
+ hexify(str + j, data + i, 2, n - j);
+ i += 2;
+ j += 4;
+ str[j++] = ' ';
+ }
+ }
+
+ switch (swd_cmd) {
+ case CH347_CMD_SWD_REG_W:
+ if (recv)
+ swd_payload_size = 1;
+ else
+ swd_payload_size = DIV_ROUND_UP(swd_bits, 8);
+ break;
+ case CH347_CMD_SWD_SEQ_W:
+ if (!recv)
+ swd_payload_size = DIV_ROUND_UP(swd_bits, 8);
+ break;
+ case CH347_CMD_SWD_REG_R:
+ if (recv)
+ swd_payload_size = 1 + 4 + 1;
+ else
+ swd_payload_size = 1;
+ break;
+ }
+
+ hexify(str + j, data + i, MIN(swd_payload_size, size - i), n - j);
+ i += swd_payload_size;
+ j += 2 * swd_payload_size;
+ str[j] = '\0';
+ if (i > size)
+ LOG_DEBUG_IO(" %s - bad size", str);
+ else
+ LOG_DEBUG_IO(" %s", str);
+ j = 0;
+ }
+ } else {
+ hexify(str + j, data + i, MIN(cmd_payload_size, size - i), n - j);
+ i += cmd_payload_size;
+ j += 2 * cmd_payload_size;
+ str[j] = '\0';
+ if (i > size)
+ LOG_DEBUG_IO("%s - bad size", str);
+ else
+ LOG_DEBUG_IO("%s", str);
+ j = 0;
+ }
+ }
+ free(str);
+}
+
/**
* @brief writes data to the CH347 via libusb driver
*
@@ -289,9 +385,8 @@ static int ch347_write_data(uint8_t *data, int *length)
}
if (LOG_LEVEL_IS(LOG_LVL_DEBUG_IO)) {
- char *str = buf_to_hex_str(data, i * 8);
- LOG_DEBUG_IO("size=%d, buf=[%s]", i, str);
- free(str);
+ LOG_DEBUG_IO("size=%d, buf=", i);
+ log_buf_dump(data, i, false);
}
*length = i;
@@ -327,9 +422,8 @@ static int ch347_read_data(uint8_t *data, int *length)
}
if (LOG_LEVEL_IS(LOG_LVL_DEBUG_IO)) {
- char *str = buf_to_hex_str(data, i * 8);
- LOG_DEBUG_IO("size=%d, buf=[%s]", i, str);
- free(str);
+ LOG_DEBUG_IO("size=%d, buf=", i);
+ log_buf_dump(data, i, true);
}
*length = i;
-----------------------------------------------------------------------
Summary of changes:
src/jtag/drivers/ch347.c | 191 +++++++++++++++++++++++++++++++++++++++--------
1 file changed, 161 insertions(+), 30 deletions(-)
hooks/post-receive
--
Main OpenOCD repository
|
|
From: openocd-gerrit <ope...@us...> - 2025-08-24 05:03:33
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Main OpenOCD repository".
The branch, master has been updated
via 99cb670becdb1e00fc75997383325550b02accdd (commit)
from 7d0e125896291e7683f76aa1ad10532bb192692b (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 99cb670becdb1e00fc75997383325550b02accdd
Author: Tomas Vanek <va...@fb...>
Date: Sat Feb 8 18:46:32 2025 +0100
drivers/ch347, doc: warn about CH347T problems
Also suggest a possible solution if available.
CH347F related parts co-authored by ZhiYuanNJ <871...@qq...>
Change-Id: Id6557909fcb56a1e95e16277c1cd7df6769cf4dd
Signed-off-by: Tomas Vanek <va...@fb...>
Reviewed-on: https://review.openocd.org/c/openocd/+/8741
Reviewed-by: ZhiYuanNJ <871...@qq...>
Tested-by: jenkins
diff --git a/doc/openocd.texi b/doc/openocd.texi
index f4408fa23..22c7fcedd 100644
--- a/doc/openocd.texi
+++ b/doc/openocd.texi
@@ -2561,6 +2561,32 @@ and a specific set of GPIOs is used.
@deffn {Interface Driver} {ch347}
Driver for WCH CH347F and CH347T chips.
When using the CH347T, it must be configured to operate in mode 3 (UART + JTAG).
+
+@b{WARNING:} WCH CH347T chips have rather poor performance
+with respect to the USB HS connection. Upgrade firmware to the latest version!
+@itemize @bullet
+@item Chip version 2.41:
+@itemize @minus
+@item JTAG timing is very weird, some clock pulses are
+much shorter then the requested clock frequency.
+@item SWD is not implemented.
+@end itemize
+@item Chip version 4.41:
+@itemize @minus
+@item SWD clock is limited to 1 MHz maximum.
+@item SWD reading AP reg CH347 erroneously drives
+SWDIO to H for 392 ns after the last ACK bit. Some devices get so upset
+that send wrong data with parity error. A resistor in the SWDIO circuit
+mitigates the problem.
+@item A long SWD operation causes that USB host disconnects the adapter.
+@end itemize
+@item Chip version 5.44:
+@itemize @minus
+@item Maximal SWD clock speed is 5 MHz
+@item A long SWD operation causes that USB host disconnects the adapter.
+@end itemize
+@end itemize
+
This driver has these driver-specific command:
@deffn {Config Command} {ch347 vid_pid} [vid pid]+
diff --git a/src/jtag/drivers/ch347.c b/src/jtag/drivers/ch347.c
index 41893d144..8c9c784cd 100644
--- a/src/jtag/drivers/ch347.c
+++ b/src/jtag/drivers/ch347.c
@@ -1402,13 +1402,34 @@ static int ch347_open_device(void)
firmware_version);
if (ch347.chip_variant == CH347T && ch347_device_descriptor.bcdDevice < BYTEWISE_MODE_VERSION) {
- LOG_INFO("CH347 old version of the chip, JTAG only working in bitwise mode. For bytewise mode at least version %X.%X is needed.",
+ LOG_INFO("CH347T old version of the chip, JTAG only working in bitwise mode. For bytewise mode at least version %X.%X is needed.",
(BYTEWISE_MODE_VERSION >> 8) & 0xFF,
BYTEWISE_MODE_VERSION & 0xFF);
ch347.use_bitwise_mode = true;
} else {
ch347.use_bitwise_mode = false;
}
+
+ if (ch347.chip_variant == CH347T) {
+ if (swd_mode) {
+ if (ch347_device_descriptor.bcdDevice < 0x441)
+ LOG_WARNING("CH347T version older than 4.41 probably does not support SWD transport");
+
+ if (ch347_device_descriptor.bcdDevice == 0x441)
+ LOG_WARNING("If CH347T version 4.41 cannot connect or SWD fails often, insert a resistor to SWDIO circuit");
+
+ } else if (ch347_device_descriptor.bcdDevice == 0x241) {
+ LOG_WARNING("CH347T version 2.41 has very weird clock timing, may not work with a slower JTAG device");
+ }
+
+ if (ch347_device_descriptor.bcdDevice < 0x544)
+ LOG_INFO("Please upgrade CH347T firmware to a production version >= 5.44");
+
+ } else if (ch347.chip_variant == CH347F) {
+ if (ch347_device_descriptor.bcdDevice < 0x101)
+ LOG_INFO("Please upgrade CH347F firmware to a production version >= 1.1");
+ }
+
return ERROR_OK;
}
-----------------------------------------------------------------------
Summary of changes:
doc/openocd.texi | 26 ++++++++++++++++++++++++++
src/jtag/drivers/ch347.c | 23 ++++++++++++++++++++++-
2 files changed, 48 insertions(+), 1 deletion(-)
hooks/post-receive
--
Main OpenOCD repository
|
|
From: openocd-gerrit <ope...@us...> - 2025-08-24 05:03:10
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Main OpenOCD repository".
The branch, master has been updated
via 7d0e125896291e7683f76aa1ad10532bb192692b (commit)
from 68b6d3ad477b45a54282571ebd4ed8a53cf7dd90 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 7d0e125896291e7683f76aa1ad10532bb192692b
Author: EasyDevKits <in...@ea...>
Date: Sat Oct 14 16:28:59 2023 +0200
jtag/drivers: Add support for CH347-based JTAG adapters
This adds general support for JTAG adapters based on the WCH CH347T and
CH347F chips.
The CH347T must be configured in mode 3 to provide both UART and JTAG
interfaces. The CH347F exposes UART and JTAG directly. Similar to FTDI
FT2232-based devices, the CH347T/F can be used for simultaneous UART and
JTAG communication.
The ch347 driver code is based on:
https://github.com/WCHSoftGroup/ch347
Bug fixes and adjustments were made to align the code with OpenOCD style
and ensure compatibility. The driver was integrated into the OpenOCD
build system.
The USB packet format was identified using public GitHub sources and
documented here:
https://www.easydevkits.com/wch-ch347-jtag-interface/
Change-Id: I5fca9dd015111e4410fea029611fdeedbb228fdb
Signed-off-by: EasyDevKits <in...@ea...>
Reviewed-on: https://review.openocd.org/c/openocd/+/7937
Tested-by: jenkins
Reviewed-by: ZhiYuanNJ <871...@qq...>
Reviewed-by: Tomas Vanek <va...@fb...>
diff --git a/configure.ac b/configure.ac
index e7f797608..b508f2ade 100644
--- a/configure.ac
+++ b/configure.ac
@@ -129,6 +129,7 @@ m4_define([ADAPTER_OPT], [m4_translit(ADAPTER_ARG($1), [_], [-])])
m4_define([USB1_ADAPTERS],
[[[ftdi], [MPSSE mode of FTDI based devices], [FTDI]],
+ [[ch347], [Mode 3 of CH347 based devices], [CH347]],
[[stlink], [ST-Link Programmer], [HLADAPTER_STLINK]],
[[ti_icdi], [TI ICDI JTAG Programmer], [HLADAPTER_ICDI]],
[[ulink], [Keil ULINK JTAG Programmer], [ULINK]],
@@ -724,6 +725,7 @@ AM_CONDITIONAL([INTERNAL_JIMTCL], [test "x$use_internal_jimtcl" = "xyes"])
AM_CONDITIONAL([HAVE_JIMTCL_PKG_CONFIG], [test "x$have_jimtcl_pkg_config" = "xyes"])
AM_CONDITIONAL([INTERNAL_LIBJAYLINK], [test "x$use_internal_libjaylink" = "xyes"])
+
AM_CONDITIONAL([USE_GCOV], [test "x$enable_gcov" = "xyes"])
# Look for environ alternatives. Possibility #1: is environ in unistd.h or stdlib.h?
diff --git a/contrib/60-openocd.rules b/contrib/60-openocd.rules
index 2a2fe88e6..151b4e2c0 100644
--- a/contrib/60-openocd.rules
+++ b/contrib/60-openocd.rules
@@ -220,6 +220,11 @@ ATTRS{idVendor}=="16c0", ATTRS{idProduct}=="06ad", MODE="660", GROUP="plugdev",
# USBprog with OpenOCD firmware
ATTRS{idVendor}=="1781", ATTRS{idProduct}=="0c63", MODE="660", GROUP="plugdev", TAG+="uaccess"
+# WCH CH347T chip in mode 3
+ATTRS{idVendor}=="1a86", ATTRS{idProduct}=="55dd", MODE="660", GROUP="plugdev", TAG+="uaccess"
+# WCH CH347F chip
+ATTRS{idVendor}=="1a86", ATTRS{idProduct}=="55de", MODE="660", GROUP="plugdev", TAG+="uaccess"
+
# TI/Luminary Stellaris In-Circuit Debug Interface (ICDI) Board
ATTRS{idVendor}=="1cbe", ATTRS{idProduct}=="00fd", MODE="660", GROUP="plugdev", TAG+="uaccess"
diff --git a/doc/openocd.texi b/doc/openocd.texi
index 01ca7adfb..f4408fa23 100644
--- a/doc/openocd.texi
+++ b/doc/openocd.texi
@@ -633,6 +633,10 @@ This is deprecated from Linux v5.3; prefer using @b{linuxgpiod}.
@item @b{esp_usb_jtag}
@* A JTAG driver to communicate with builtin debug modules of Espressif ESP32-C3 and ESP32-S3 chips using OpenOCD.
+@item @b{ch347}
+@* A JTAG driver that works with the WCH CH347F and CH347T chips.
+When using the CH347T, it must be configured to operate in mode 3 (UART + JTAG).
+
@end itemize
@node About Jim Tcl
@@ -2554,6 +2558,41 @@ and a specific set of GPIOs is used.
@c chooses among list of bit configs ... only one option
@end deffn
+@deffn {Interface Driver} {ch347}
+Driver for WCH CH347F and CH347T chips.
+When using the CH347T, it must be configured to operate in mode 3 (UART + JTAG).
+This driver has these driver-specific command:
+
+@deffn {Config Command} {ch347 vid_pid} [vid pid]+
+The vendor ID and product ID of the CH347F or CH347T device in mode 3. If not specified
+the driver will use vendor ID 0x1a86 and product ID 0x55dd.
+Currently, up to four [@var{vid}, @var{pid}] pairs may be given, e.g.
+@example
+ch347 vid_pid 0x1a86 0x55dd 0x1a86 0x55de
+@end example
+@end deffn
+
+@deffn {Config Command} {ch347 device_desc} description
+If specified connect to a device which exactly has this product description
+string. If not specified the first found device with the correct vendor
+and product ID will be connected.
+@example
+ch347 device_desc "EasyDevKit"
+@end example
+@end deffn
+
+@deffn {Config Command} {ch347 activity_led} [n]gpio_number
+If specified the drive let an activity LED blink during JTAG operations.
+The number is the GPIO number of the CH347T chip. If prefixed with "n",
+then this GPIO should be low active. The example configures GPIO4 as
+low active activity LED. For the CH347T chip only GPIO3 (Pin11 / SCL),
+GPIO4 (Pin15 / ACT), GPIO5 (Pin9 / TRST) and GPIO6 (Pin2 / CTS1) are possible.
+@example
+ch347 activity_led n4
+@end example
+@end deffn
+@end deffn
+
@deffn {Interface Driver} {cmsis-dap}
ARM CMSIS-DAP compliant based adapter v1 (USB HID based)
or v2 (USB bulk).
diff --git a/doc/usb_adapters/ch347/1a86_55dd_easydevkit.txt b/doc/usb_adapters/ch347/1a86_55dd_easydevkit.txt
new file mode 100644
index 000000000..9a0ae71ed
--- /dev/null
+++ b/doc/usb_adapters/ch347/1a86_55dd_easydevkit.txt
@@ -0,0 +1,146 @@
+# SPDX-License-Identifier: GPL-2.0-or-later OR GFDL-1.2-no-invariants-or-later
+
+# Link: https://www.easydevkits.com
+# PCB: ESP32-WROVER-E WCH JTAG DevKit v0.1
+# Chip: CH347T in mode 3 (UART+JTAG mode)
+# Product id of 0x55dd is only valid if the chip is started in mode 3
+# These are the other product ids: mode 0 = 0x55da, mode 1 = 0x55db, mode 2 = 0x55dc
+# The similar chip CH347F has no modes and always product id 0x55de
+
+Bus 001 Device 013: ID 1a86:55dd QinHeng Electronics EasyDevKit
+Device Descriptor:
+ bLength 18
+ bDescriptorType 1
+ bcdUSB 2.00
+ bDeviceClass 0
+ bDeviceSubClass 0
+ bDeviceProtocol 0
+ bMaxPacketSize0 64
+ idVendor 0x1a86 QinHeng Electronics
+ idProduct 0x55dd
+ bcdDevice 4.41
+ iManufacturer 1 EasyDevKits
+ iProduct 2 EasyDevKit
+ iSerial 3 ACBACJGAAB
+ bNumConfigurations 1
+ Configuration Descriptor:
+ bLength 9
+ bDescriptorType 2
+ wTotalLength 0x0062
+ bNumInterfaces 3
+ bConfigurationValue 1
+ iConfiguration 0
+ bmAttributes 0x80
+ (Bus Powered)
+ MaxPower 500mA
+ Interface Association:
+ bLength 8
+ bDescriptorType 11
+ bFirstInterface 0
+ bInterfaceCount 2
+ bFunctionClass 2 Communications
+ bFunctionSubClass 2 Abstract (modem)
+ bFunctionProtocol 1 AT-commands (v.25ter)
+ iFunction 0
+ Interface Descriptor:
+ bLength 9
+ bDescriptorType 4
+ bInterfaceNumber 0
+ bAlternateSetting 0
+ bNumEndpoints 1
+ bInterfaceClass 2 Communications
+ bInterfaceSubClass 2 Abstract (modem)
+ bInterfaceProtocol 1 AT-commands (v.25ter)
+ iInterface 0
+ CDC Header:
+ bcdCDC 1.10
+ CDC Call Management:
+ bmCapabilities 0x00
+ bDataInterface 1
+ CDC ACM:
+ bmCapabilities 0x02
+ line coding and serial state
+ CDC Union:
+ bMasterInterface 0
+ bSlaveInterface 1
+ Endpoint Descriptor:
+ bLength 7
+ bDescriptorType 5
+ bEndpointAddress 0x83 EP 3 IN
+ bmAttributes 3
+ Transfer Type Interrupt
+ Synch Type None
+ Usage Type Data
+ wMaxPacketSize 0x0040 1x 64 bytes
+ bInterval 1
+ Interface Descriptor:
+ bLength 9
+ bDescriptorType 4
+ bInterfaceNumber 1
+ bAlternateSetting 0
+ bNumEndpoints 2
+ bInterfaceClass 10 CDC Data
+ bInterfaceSubClass 0
+ bInterfaceProtocol 0
+ iInterface 0
+ Endpoint Descriptor:
+ bLength 7
+ bDescriptorType 5
+ bEndpointAddress 0x04 EP 4 OUT
+ bmAttributes 2
+ Transfer Type Bulk
+ Synch Type None
+ Usage Type Data
+ wMaxPacketSize 0x0200 1x 512 bytes
+ bInterval 0
+ Endpoint Descriptor:
+ bLength 7
+ bDescriptorType 5
+ bEndpointAddress 0x84 EP 4 IN
+ bmAttributes 2
+ Transfer Type Bulk
+ Synch Type None
+ Usage Type Data
+ wMaxPacketSize 0x0200 1x 512 bytes
+ bInterval 0
+ Interface Descriptor:
+ bLength 9
+ bDescriptorType 4
+ bInterfaceNumber 2
+ bAlternateSetting 0
+ bNumEndpoints 2
+ bInterfaceClass 255 Vendor Specific Class
+ bInterfaceSubClass 0
+ bInterfaceProtocol 0
+ iInterface 0
+ Endpoint Descriptor:
+ bLength 7
+ bDescriptorType 5
+ bEndpointAddress 0x06 EP 6 OUT
+ bmAttributes 2
+ Transfer Type Bulk
+ Synch Type None
+ Usage Type Data
+ wMaxPacketSize 0x0200 1x 512 bytes
+ bInterval 0
+ Endpoint Descriptor:
+ bLength 7
+ bDescriptorType 5
+ bEndpointAddress 0x86 EP 6 IN
+ bmAttributes 2
+ Transfer Type Bulk
+ Synch Type None
+ Usage Type Data
+ wMaxPacketSize 0x0200 1x 512 bytes
+ bInterval 0
+Device Qualifier (for other device speed):
+ bLength 10
+ bDescriptorType 6
+ bcdUSB 2.00
+ bDeviceClass 255 Vendor Specific Class
+ bDeviceSubClass 0
+ bDeviceProtocol 255
+ bMaxPacketSize0 64
+ bNumConfigurations 1
+Device Status: 0x0000
+ (Bus Powered)
diff --git a/src/jtag/drivers/Makefile.am b/src/jtag/drivers/Makefile.am
index 481840504..3a3fe0772 100644
--- a/src/jtag/drivers/Makefile.am
+++ b/src/jtag/drivers/Makefile.am
@@ -208,6 +208,9 @@ endif
if AM335XGPIO
DRIVERFILES += %D%/am335xgpio.c
endif
+if CH347
+DRIVERFILES += %D%/ch347.c
+endif
DRIVERHEADERS = \
%D%/bitbang.h \
diff --git a/src/jtag/drivers/ch347.c b/src/jtag/drivers/ch347.c
new file mode 100644
index 000000000..41893d144
--- /dev/null
+++ b/src/jtag/drivers/ch347.c
@@ -0,0 +1,2225 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+/***************************************************************************
+ * Driver for CH347-JTAG interface V1.1 *
+ * *
+ * Copyright (C) 2022 by oidcat. *
+ * Author: oid...@16... *
+ * *
+ * Enhancements by EasyDevKits - in...@ea... *
+ * *
+ * CH347 is a high-speed USB bus converter chip that provides UART, I2C *
+ * and SPI synchronous serial ports and JTAG interface through USB bus. *
+ * *
+ * The JTAG interface by CH347 can supports transmission frequency *
+ * configuration up to 60MHz. *
+ * *
+ * The USB2.0 to JTAG scheme based on CH347 can be used to build *
+ * customized USB high-speed JTAG debugger and other products. *
+ * *
+ * _____________ *
+ * | |____JTAG/SWD (TDO,TDI,TMS,TCK,TRST) *
+ * USB__| CH347T/F | *
+ * |_____________|____UART(TXD1,RXD1,RTS1,CTS1,DTR1) *
+ * ______|______ *
+ * | | *
+ * | 8 MHz XTAL | *
+ * |_____________| *
+ * *
+ * This CH347 driver is only tested for the CH347T chip in mode 3. *
+ * The CH347 datasheet mention another chip the CH347F which was not *
+ * available for testing. *
+ * *
+ * The datasheet for the wch-ic.com's CH347 part is here: *
+ * https://www.wch-ic.com/downloads/CH347DS1_PDF.html *
+ * *
+ ***************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#if IS_CYGWIN == 1
+#include "windows.h"
+#undef LOG_ERROR
+#endif
+
+// project specific includes
+#include <jtag/interface.h>
+#include <jtag/commands.h>
+#include <jtag/swd.h>
+#include <helper/time_support.h>
+#include <helper/replacements.h>
+#include <helper/list.h>
+#include <helper/binarybuffer.h>
+#include "libusb_helper.h"
+
+// system includes
+#include <stdlib.h>
+#include <string.h>
+#include <sys/time.h>
+#include <time.h>
+#include <unistd.h>
+
+#define TDI_H BIT(4)
+#define TDI_L 0
+#define TMS_H BIT(1)
+#define TMS_L 0
+#define TCK_H BIT(0)
+#define TCK_L 0
+#define TRST_H BIT(5)
+#define TRST_L 0
+#define LED_ON 1
+#define LED_OFF 0
+#define GPIO_CNT 8 // the CH347 has 8 GPIO's
+/* mask which GPIO's are available in mode 3 of CH347T only GPIO3 (Pin11 / SCL), GPIO4 (Pin15 / ACT),
+ GPIO5 (Pin9 / TRST) and GPIO6 (Pin2 / CTS1) are possible. Tested only with CH347T not CH347F chip.
+ pin numbers are for CH347T */
+#define USEABLE_GPIOS 0x78
+/* For GPIO command: always set bits 7 and 6 for GPIO enable
+ bits 5 and 4 for pin direction output bit 3 is the data bit */
+#define GPIO_SET_L (BIT(4) | BIT(5) | BIT(6) | BIT(7)) // value for setting a GPIO to low
+#define GPIO_SET_H (BIT(3) | BIT(4) | BIT(5) | BIT(6) | BIT(7)) // value for setting a GPIO to high
+
+#define VENDOR_VERSION 0x5F // for getting the chip version
+
+// maybe the hardware of the CH347 chip can capture only this amount of TDO bits
+#define HW_TDO_BUF_SIZE 4096
+// Don't send more than this amount of bytes via libusb in one packet. Also that is the limit for LARGER_PACK mode.
+#define LARGER_PACK_MAX_SIZE 51200
+// The data length contained in each command packet during USB high-speed operation
+#define UCMDPKT_DATA_MAX_BYTES_USBHS 507
+#define USBC_PACKET_USBHS 512 // Maximum data length per packet at USB high speed
+#define CH347_CMD_HEADER 3 // Protocol header length (1 byte command type + 2 bytes data length)
+#define CH347_CMD_INIT_READ_LEN 1 // for JTAG_INIT/SWD_INIT we have only one data byte
+// if we send 9 in the init command we get the STANDARD mode or LARGER_PACK mode flag
+#define CH347_CMD_INIT_GET_MODE_CLOCK_INDEX_VALUE 9
+// No more bits are allowed per CH347_CMD_JTAG_BIT_OP command; this should be dividable by 8
+#define MAX_BITS_PER_BIT_OP 248
+
+/* Protocol transmission format: CMD (1 byte) + Length (2 bytes) + Data
+ Parameter acquisition, used to obtain firmware version, JTAG interface related parameters, etc */
+#define CH347_CMD_INFO_RD 0xCA
+#define CH347_CMD_GPIO 0xCC // GPIO Command
+#define CH347_CMD_JTAG_INIT 0xD0 // JTAG Interface initialization command
+#define CH347_CMD_JTAG_BIT_OP 0xD1 // JTAG interface pin bit control command
+#define CH347_CMD_JTAG_BIT_OP_RD 0xD2 // JTAG interface pin bit control and read commands
+#define CH347_CMD_JTAG_DATA_SHIFT 0xD3 // JTAG interface data shift command
+#define CH347_CMD_JTAG_DATA_SHIFT_RD 0xD4 // JTAG interface data shift and read command
+// for a single command these amount of data can be read at max
+#define CH347_SINGLE_CMD_MAX_READ MAX(GPIO_CNT, CH347_CMD_INIT_READ_LEN)
+
+// for SWD
+#define CH347_CMD_SWD_INIT 0xE5 // SWD Interface Initialization Command
+#define CH347_CMD_SWD 0xE8 // SWD Command group header
+#define CH347_CMD_SWD_REG_W 0xA0 // SWD Interface write reg
+#define CH347_CMD_SWD_SEQ_W 0xA1 // SWD Interface write spec seq
+#define CH347_CMD_SWD_REG_R 0xA2 // SWD Interface read reg
+#define CH347_MAX_SEND_CMD 19 // max send cmd number
+#define CH347_MAX_SEND_BUF 0X200
+#define CH347_MAX_RECV_BUF 0X200
+#define CH347_MAX_CMD_BUF 128
+
+#define CH347_EPOUT 0x06u // the usb endpoint number for writing
+#define CH347_EPIN 0x86u // the usb endpoint number for reading
+#define CH347T_MPHSI_INTERFACE 2 // the CH347T JTAG interface is number 2
+#define CH347F_MPHSI_INTERFACE 4 // the CH347F JTAG interface is number 4
+#define USB_WRITE_TIMEOUT 500 // write timeout in milliseconds
+#define USB_READ_TIMEOUT 500 // read timeout in milliseconds
+// BCD version for devices that can use bytewise mode below this version only bitwise mode can be used
+#define BYTEWISE_MODE_VERSION 0x241
+/* if the configuration is not setting the vendor id / product id we search for vendor id 1a86
+ and product id's 0x55dd (CH347T chip in mode 3), 0x55de (CH347F chip) and 0x55e7 (other chip) */
+#define DEFAULT_VENDOR_ID 0x1a86
+#define DEFAULT_CH347T_PRODUCT_ID 0x55dd
+#define DEFAULT_CH347F_PRODUCT_ID 0x55de
+#define DEFAULT_OTHER_PRODUCT_ID 0x55e7
+
+/* There are 3 different CH347 variants. The datasheet mentions the CH347T chip which has the product id 0x55dd
+ as default when it's configured to mode 3. The CH347F chip is also mentioned in the datasheet and has the
+ default product id 0x55de. The 3rd variant is not mentioned in a datasheet but was found here
+ https://github.com/WCHSoftGroup/ch347
+ The code from WCHSoftGroup is also searching for this product id */
+enum ch347_variant {
+ CH347T = 0, // The CH347T chip
+ CH347F = 1, // The CH347F chip
+ OTHER_PRODUCT_ID = 2, // other product id not mentioned in the datasheet
+};
+
+/* STANDARD_PACK means that we can send only one USBC_PACKET_USBHS-sized USB packet
+ and then read data back. LARGER_PACK means, we can send packets as large as
+ LARGER_PACK_MAX_SIZE. libusb splits there large packets into smaller USB packets and
+ transmit the data. Then we read back the data in a bigger packet. */
+enum pack_size {
+ UNSET = -1,
+ STANDARD_PACK = 0,
+ LARGER_PACK = 1,
+};
+
+// for STANDARD_PACK mode: these are the 6 possible speeds; values in kHz
+static const int ch347_standard_pack_clock_speeds[] = {
+ 1875, // 1.875 MHz (60000 : 32)
+ 3750, // 3.75 MHz (60000 : 16)
+ 7500, // 7.5 MHz (60000 : 8)
+ 15000, // 15 MHz (60000 : 4)
+ 30000, // 30 MHz (60000 : 2)
+ 60000 // 60 MHz
+};
+
+// for LARGER_PACK mode: these are the 8 possible speeds; values in kHz
+static const int ch347_larger_pack_clock_speeds[] = {
+ 469, // 468.75 kHz (60000 : 128)
+ 938, // 937.5 kHz (60000 : 64)
+ 1875, // 1.875 MHz (60000 : 32)
+ 3750, // 3.75 MHz (60000 : 16)
+ 7500, // 7.5 MHz (60000 : 8)
+ 15000, // 15 MHz (60000 : 4)
+ 30000, // 30 MHz (60000 : 2)
+ 60000 // 60 MHz
+};
+
+struct ch347_cmd {
+ uint8_t type; // the command type
+ uint8_t *write_data; // data bytes for write
+ uint16_t write_data_len; // count of data bytes in the write_data buffer
+ uint16_t read_len; // if >0 a read is needed after this command
+ uint16_t tdo_bit_count; // how many TDO bits are needed to shift in by this read
+ struct list_head queue; // for handling a queue (list)
+};
+
+struct ch347_scan {
+ struct scan_field *fields; // array of scan_field's for data from the device
+ int fields_len; // scan_fields array length
+ struct list_head queue; // for handling a queue (list)
+};
+
+struct ch347_info {
+ // Record the CH347 pin status
+ int tms_pin;
+ int tdi_pin;
+ int tck_pin;
+ int trst_pin;
+
+ enum ch347_variant chip_variant; // ch347_variant for explanation
+ // if true then we can't us the bytewise commands due to a bug of the chip; depends on BYTEWISE_MODE_VERSION
+ bool use_bitwise_mode;
+ enum pack_size pack_size; // see: pack_size for explanation
+ int max_len; // in STANDARD_PACK or bitwise mode we can send only one USBC_PACKET_USBHS sized package
+
+ // a "scratchpad" where we record all bytes for one command
+ uint8_t scratchpad_cmd_type; // command type
+ uint8_t scratchpad[UCMDPKT_DATA_MAX_BYTES_USBHS]; // scratchpad buffer
+ int scratchpad_idx; // current index in scratchpad
+
+ // after a command is complete it will be stored for later processing
+ struct list_head cmd_queue;
+ // all data input scan fields are queued here
+ struct list_head scan_queue;
+ // read buffer for the single commands like CH347_CMD_GPIO and CH347_CMD_JTAG_INIT
+ uint8_t single_read[CH347_SINGLE_CMD_MAX_READ];
+ int singe_read_len; // data length in single_read
+};
+
+struct ch347_swd_io {
+ uint8_t usb_cmd; // 0xA0, 0xA1, 0xA2
+ uint8_t cmd;
+ uint32_t *dst;
+ uint32_t value;
+ struct list_head list_entry;
+};
+
+struct ch347_swd_context {
+ uint8_t send_buf[CH347_MAX_SEND_BUF];
+ uint8_t recv_buf[CH347_MAX_RECV_BUF];
+ int send_len;
+ int recv_len;
+ int need_recv_len;
+ int queued_retval;
+ int sent_cmd_count;
+ struct list_head send_cmd_head;
+ struct list_head free_cmd_head;
+ struct ch347_swd_io ch347_cmd_buf[CH347_MAX_CMD_BUF];
+};
+
+static struct ch347_swd_context ch347_swd_context;
+static bool swd_mode;
+static uint16_t default_ch347_vids[] = {DEFAULT_VENDOR_ID, DEFAULT_VENDOR_ID, DEFAULT_VENDOR_ID, 0};
+static uint16_t default_ch347_pids[] = {DEFAULT_CH347T_PRODUCT_ID,
+ DEFAULT_CH347F_PRODUCT_ID, DEFAULT_OTHER_PRODUCT_ID, 0};
+static uint16_t custom_ch347_vids[] = {0, 0, 0, 0};
+static uint16_t custom_ch347_pids[] = {0, 0, 0, 0};
+static char *ch347_device_desc;
+static uint8_t ch347_activity_led_gpio_pin = 0xFF;
+static bool ch347_activity_led_active_high;
+static struct ch347_info ch347;
+static struct libusb_device_handle *ch347_handle;
+
+/* there are "single" commands. These commands can't be chained together and
+ need to be send as single command and need a read after write */
+static inline bool ch347_is_single_cmd_type(uint8_t type)
+{
+ return type == CH347_CMD_GPIO || type == CH347_CMD_JTAG_INIT || type == CH347_CMD_SWD_INIT;
+}
+
+/**
+ * @brief writes data to the CH347 via libusb driver
+ *
+ * @param data Point to the data buffer
+ * @param length Data length in and out
+ * @return ERROR_OK at success
+ */
+static int ch347_write_data(uint8_t *data, int *length)
+{
+ int write_len = *length;
+ int i = 0;
+ int transferred = 0;
+
+ while (true) {
+ int retval = jtag_libusb_bulk_write(ch347_handle, CH347_EPOUT, (char *)&data[i],
+ write_len, USB_WRITE_TIMEOUT, &transferred);
+ if (retval != ERROR_OK) {
+ LOG_ERROR("CH347 write fail");
+ *length = 0;
+ return retval;
+ }
+ i += transferred;
+ if (i >= *length)
+ break;
+ write_len = *length - i;
+ }
+
+ if (LOG_LEVEL_IS(LOG_LVL_DEBUG_IO)) {
+ char *str = buf_to_hex_str(data, i * 8);
+ LOG_DEBUG_IO("size=%d, buf=[%s]", i, str);
+ free(str);
+ }
+
+ *length = i;
+ return ERROR_OK;
+}
+
+/**
+ * @brief reads data from the CH347 via libusb driver
+ *
+ * @param data Point to the data buffer
+ * @param length Data length in and out
+ * @return ERROR_OK at success
+ */
+static int ch347_read_data(uint8_t *data, int *length)
+{
+ int read_len = *length;
+ int i = 0;
+ int transferred = 0;
+
+ while (true) {
+ int retval = jtag_libusb_bulk_read(ch347_handle, CH347_EPIN, (char *)&data[i],
+ read_len, USB_READ_TIMEOUT, &transferred);
+ if (retval != ERROR_OK) {
+ LOG_ERROR("CH347 read fail");
+ *length = 0;
+ return retval;
+ }
+
+ i += transferred;
+ if (i >= *length)
+ break;
+ read_len = *length - i;
+ }
+
+ if (LOG_LEVEL_IS(LOG_LVL_DEBUG_IO)) {
+ char *str = buf_to_hex_str(data, i * 8);
+ LOG_DEBUG_IO("size=%d, buf=[%s]", i, str);
+ free(str);
+ }
+
+ *length = i;
+ return ERROR_OK;
+}
+
+/**
+ * @brief calculates the amount of bits and bytes that should be read
+ * for this command
+ *
+ * @param cmd command for the calculation
+ */
+static void ch347_cmd_calc_reads(struct ch347_cmd *cmd)
+{
+ cmd->read_len = 0;
+ cmd->tdo_bit_count = 0;
+
+ switch (cmd->type) {
+ case CH347_CMD_GPIO:
+ // for GPIO we need to read back the same amount of data that we had send
+ cmd->read_len = cmd->write_data_len;
+ break;
+ case CH347_CMD_JTAG_INIT:
+ case CH347_CMD_SWD_INIT:
+ // for JTAG_INIT/SWD_INIT the amount is fixed
+ cmd->read_len = CH347_CMD_INIT_READ_LEN;
+ break;
+ case CH347_CMD_JTAG_BIT_OP_RD:
+ // for bit operations we need to count the TCK high edges
+ for (int i = 0; i < cmd->write_data_len; i++) {
+ if ((cmd->write_data[i] & TCK_H) == TCK_H) {
+ cmd->read_len++;
+ cmd->tdo_bit_count++;
+ }
+ }
+ break;
+ case CH347_CMD_JTAG_DATA_SHIFT_RD:
+ // for byte operations: need to read one byte back for each data byte
+ cmd->read_len = cmd->write_data_len;
+ // we occupy 8 bits per byte in the TDO hardware buffer
+ cmd->tdo_bit_count = cmd->read_len * 8;
+ break;
+ }
+}
+
+/**
+ * @brief copy the scratchpad content into a new command in the command queue
+ *
+ * @param scan_fields array of scan_field's for data from the device
+ * @param scan_fields_len array length
+ * @return ERROR_OK at success
+ */
+static int ch347_cmd_from_scratchpad(void)
+{
+ // nothing to do if no bytes are recorded
+ if (!ch347.scratchpad_idx)
+ return ERROR_OK;
+
+ // malloc for the command and data bytes
+ struct ch347_cmd *cmd = malloc(sizeof(struct ch347_cmd));
+ if (cmd)
+ cmd->write_data = malloc(ch347.scratchpad_idx);
+ if (!cmd || !cmd->write_data) {
+ LOG_ERROR("malloc failed");
+ free(cmd);
+ return ERROR_FAIL;
+ }
+
+ // copy data, calculate the reads and add to the command queue
+ cmd->type = ch347.scratchpad_cmd_type;
+ cmd->write_data_len = ch347.scratchpad_idx;
+ memcpy(cmd->write_data, ch347.scratchpad, ch347.scratchpad_idx);
+ ch347_cmd_calc_reads(cmd);
+ list_add_tail(&cmd->queue, &ch347.cmd_queue);
+
+ // cleanup the scratchpad for the next command
+ ch347.scratchpad_cmd_type = 0;
+ ch347.scratchpad_idx = 0;
+ return ERROR_OK;
+}
+
+/**
+ * @brief Reads data back from CH347 and decode it byte- and bitwise into the buffer
+ *
+ * @param decoded_buf Point to a buffer to place the data to be decoded; need to be sized
+ * to the decoded size length; not the raw_read_len
+ * @param decoded_buf_len length of the decoded_buf
+ * @param raw_read_len Data length in bytes that should be read via libusb; the decoded length can be shorter
+ * @return ERROR_OK at success
+ */
+static int ch347_read_scan(uint8_t *decoded_buf, int decoded_buf_len, int raw_read_len)
+{
+ int read_len = raw_read_len;
+ uint8_t *read_buf = malloc(read_len);
+ if (!read_buf) {
+ LOG_ERROR("malloc failed");
+ return ERROR_FAIL;
+ }
+
+ int retval = ch347_read_data(read_buf, &read_len);
+ if (retval != ERROR_OK) {
+ free(read_buf);
+ return retval;
+ }
+
+ int rd_idx = 0;
+ int decoded_buf_idx = 0;
+
+ while (rd_idx < read_len) {
+ unsigned int type = read_buf[rd_idx++];
+ uint16_t data_len = le_to_h_u16(&read_buf[rd_idx]);
+ rd_idx += 2;
+ if (decoded_buf_idx > decoded_buf_len) {
+ LOG_ERROR("CH347 decoded_buf too small");
+ free(read_buf);
+ return ERROR_FAIL;
+ }
+
+ // nothing to decode? Only read to make the CH347 happy!
+ if (!decoded_buf) {
+ rd_idx += data_len;
+ continue;
+ }
+
+ switch (type) {
+ case CH347_CMD_GPIO:
+ case CH347_CMD_JTAG_INIT:
+ case CH347_CMD_SWD_INIT:
+ case CH347_CMD_JTAG_DATA_SHIFT_RD:
+ // for all bytewise commands: copy the data bytes
+ memcpy(&decoded_buf[decoded_buf_idx], &read_buf[rd_idx], data_len);
+ decoded_buf_idx += data_len;
+ rd_idx += data_len;
+ break;
+ case CH347_CMD_JTAG_BIT_OP_RD:
+ // for CH347_CMD_JTAG_BIT_OP_RD we need to copy bit by bit
+ for (int i = 0; i < data_len; i++) {
+ if (read_buf[rd_idx + i] & BIT(0))
+ decoded_buf[decoded_buf_idx + i / 8] |= BIT(i % 8);
+ else
+ decoded_buf[decoded_buf_idx + i / 8] &= ~(BIT(i % 8));
+ }
+ rd_idx += data_len;
+ decoded_buf_idx += DIV_ROUND_UP(data_len, 8);
+ break;
+ default:
+ LOG_ERROR("CH347 read command fail");
+ free(read_buf);
+ return ERROR_FAIL;
+ }
+ }
+
+ free(read_buf);
+ return ERROR_OK;
+}
+
+/**
+ * @brief Used to put the data from the decoded buffer into the scan command fields
+ *
+ * @param decoded_buf Point to a buffer for the decoded data
+ * @param decoded_buf_len length of the decoded_buf
+ * @return ERROR_OK at success
+ */
+static int ch347_scan_data_to_fields(uint8_t *decoded_buf, int decoded_buf_len)
+{
+ int byte_offset = 0;
+ struct ch347_scan *scan;
+ struct ch347_scan *tmp;
+ int bit_offset = 0;
+ list_for_each_entry_safe(scan, tmp, &ch347.scan_queue, queue) {
+ for (int i = 0; i < scan->fields_len; i++) {
+ int num_bits = scan->fields[i].num_bits;
+ LOG_DEBUG("fields[%d].in_value[%d], read from bit offset: %d", i, num_bits, bit_offset);
+ // only if we need the value
+ if (scan->fields[i].in_value) {
+ uint8_t *capture_buf = malloc(DIV_ROUND_UP(num_bits, 8));
+ if (!capture_buf) {
+ LOG_ERROR("malloc failed");
+ return ERROR_FAIL;
+ }
+ uint8_t *captured = buf_set_buf(decoded_buf, bit_offset, capture_buf, 0, num_bits);
+
+ if (LOG_LEVEL_IS(LOG_LVL_DEBUG_IO)) {
+ char *str = buf_to_hex_str(captured, num_bits);
+ LOG_DEBUG_IO("size=%d, buf=[%s]", num_bits, str);
+ free(str);
+ }
+
+ buf_cpy(captured, scan->fields[i].in_value, num_bits);
+ free(capture_buf);
+ } else {
+ if (LOG_LEVEL_IS(LOG_LVL_DEBUG_IO))
+ LOG_DEBUG_IO("field skipped");
+ }
+ bit_offset += num_bits;
+ }
+ list_del(&scan->queue);
+ free(scan);
+ /* after one round of scan field processing the
+ next data bits are read from the next data byte
+ => round up and calculate the next start bit */
+ byte_offset = DIV_ROUND_UP(bit_offset, 8);
+ bit_offset = byte_offset * 8;
+ }
+
+ // if not all bytes are transferred: put the rest into single_read buffer
+ if (byte_offset < decoded_buf_len) {
+ ch347.singe_read_len = decoded_buf_len - byte_offset;
+ LOG_DEBUG("single read of %d bytes", ch347.singe_read_len);
+ if (ch347.singe_read_len > CH347_SINGLE_CMD_MAX_READ) {
+ LOG_ERROR("Can't read more than %d bytes for a single command!", CH347_SINGLE_CMD_MAX_READ);
+ ch347.singe_read_len = CH347_SINGLE_CMD_MAX_READ;
+ }
+ memcpy(ch347.single_read, &decoded_buf[byte_offset], ch347.singe_read_len);
+ }
+
+ return ERROR_OK;
+}
+
+/**
+ * @brief Sends the write buffer via libusb
+ * and if LARGER_PACK mode is active read also data back
+ *
+ * @return ERROR_OK at success
+ */
+static int ch347_cmd_transmit_queue(void)
+{
+ // queue last command
+ int retval = ch347_cmd_from_scratchpad();
+ if (retval != ERROR_OK)
+ return retval;
+
+ // nothing to do! => done here
+ if (list_empty(&ch347.cmd_queue))
+ return ERROR_OK;
+
+ // calculate the needed buffer length for all decoded bytes
+ struct ch347_cmd *cmd;
+ int decoded_buf_len = 0;
+ list_for_each_entry(cmd, &ch347.cmd_queue, queue)
+ if (cmd->read_len > 0)
+ decoded_buf_len += ch347_is_single_cmd_type(cmd->type) ?
+ cmd->read_len : DIV_ROUND_UP(cmd->tdo_bit_count, 8);
+
+ // create the buffer for all decoded bytes
+ uint8_t *decoded_buf = NULL;
+ int decoded_buf_idx = 0;
+ if (decoded_buf_len > 0) {
+ decoded_buf = malloc(decoded_buf_len);
+ if (!decoded_buf) {
+ LOG_ERROR("malloc failed");
+ return ERROR_FAIL;
+ }
+ }
+
+ while (!list_empty(&ch347.cmd_queue)) {
+ struct ch347_cmd *last_cmd = NULL;
+ int total_len = 0;
+ int total_tdo_count = 0;
+ int bytes_to_write = 0;
+
+ list_for_each_entry(cmd, &ch347.cmd_queue, queue) {
+ total_len += CH347_CMD_HEADER + cmd->write_data_len;
+ total_tdo_count += cmd->tdo_bit_count;
+ // don't exceed max length or max TDO bit count
+ if (total_len >= ch347.max_len || total_tdo_count >= HW_TDO_BUF_SIZE)
+ break;
+ // remember the last cmd to send and bytes to send
+ last_cmd = cmd;
+ bytes_to_write = total_len;
+ }
+
+ // sanity checks
+ if (!last_cmd || bytes_to_write == 0) {
+ LOG_ERROR("Nothing to send!");
+ free(decoded_buf);
+ return ERROR_FAIL;
+ }
+
+ // create the write buffer
+ uint8_t *write_buf = malloc(bytes_to_write);
+ if (!write_buf) {
+ LOG_ERROR("malloc failed");
+ free(decoded_buf);
+ return ERROR_FAIL;
+ }
+
+ int idx = 0;
+ int bytes_to_read = 0;
+ int current_decoded_buf_len = 0;
+ struct ch347_cmd *tmp;
+
+ list_for_each_entry_safe(cmd, tmp, &ch347.cmd_queue, queue) {
+ // copy command to buffer
+ write_buf[idx++] = cmd->type;
+ h_u16_to_le(&write_buf[idx], cmd->write_data_len);
+ idx += 2;
+ memcpy(&write_buf[idx], cmd->write_data, cmd->write_data_len);
+ idx += cmd->write_data_len;
+ // need to read something back?
+ if (cmd->read_len > 0) {
+ bytes_to_read += CH347_CMD_HEADER + cmd->read_len;
+ current_decoded_buf_len += ch347_is_single_cmd_type(cmd->type) ?
+ cmd->read_len : DIV_ROUND_UP(cmd->tdo_bit_count, 8);
+ }
+
+ // cmd data no longer needed
+ list_del(&cmd->queue);
+ free(cmd->write_data);
+ free(cmd);
+
+ if (cmd == last_cmd)
+ break;
+ }
+
+ // write data to device
+ retval = ch347_write_data(write_buf, &idx);
+ free(write_buf);
+ if (retval != ERROR_OK) {
+ free(decoded_buf);
+ return retval;
+ }
+
+ if (!bytes_to_read)
+ continue;
+
+ // Need only to execute a read without decoding the data to make the CH347 happy?
+ if (!current_decoded_buf_len) {
+ // read but don't decode anything
+ retval = ch347_read_scan(NULL, 0, bytes_to_read);
+ } else {
+ retval = ch347_read_scan(&decoded_buf[decoded_buf_idx], current_decoded_buf_len, bytes_to_read);
+ decoded_buf_idx += current_decoded_buf_len;
+ }
+
+ if (retval != ERROR_OK) {
+ free(decoded_buf);
+ return retval;
+ }
+ }
+
+ // something decoded from the data read back from CH347?
+ if (decoded_buf) {
+ // put the decoded data into the scan fields or single_read buffer
+ retval = ch347_scan_data_to_fields(decoded_buf, decoded_buf_len);
+ free(decoded_buf);
+ }
+
+ return retval;
+}
+
+/**
+ * @brief starts the next command in the scratchpad. If it's the same command type
+ * it can concat the data bytes. no need to make a new command for this case
+ *
+ * @param type command type
+ */
+static int ch347_cmd_start_next(uint8_t type)
+{
+ // different command type or non chainable command? (GPIO commands can't be concat)
+ uint8_t prev_type = ch347.scratchpad_cmd_type;
+ int retval = ERROR_OK;
+ if (prev_type != type || ch347_is_single_cmd_type(type)) {
+ // something written in the scratchpad? => store it as command
+ if (prev_type != 0 && ch347.scratchpad_idx > 0) {
+ retval = ch347_cmd_from_scratchpad();
+ if (retval != ERROR_OK)
+ return retval;
+
+ /* if the last queued command is not chainable we should send it immediately
+ because e.g. the GPIO command can't be combined with any other command */
+ if (ch347_is_single_cmd_type(prev_type)) {
+ retval = ch347_cmd_transmit_queue();
+ if (retval != ERROR_OK)
+ return retval;
+ }
+ }
+
+ /* before we can send non chainable command ("single" like GPIO command) we should send all
+ other commands because we can't send it together with other commands */
+ if (ch347_is_single_cmd_type(type)) {
+ retval = ch347_cmd_transmit_queue();
+ if (retval != ERROR_OK)
+ return retval;
+ }
+
+ // store the next command type
+ ch347.scratchpad_cmd_type = type;
+ }
+
+ return retval;
+}
+
+/**
+ * @brief queue the scan fields into the scan queue
+ *
+ * @param scan_fields array of scan field's for data from the device
+ * @param scan_fields_len array length
+ * @return ERROR_OK at success
+ */
+static int ch347_scan_queue_fields(struct scan_field *scan_fields, int scan_fields_len)
+{
+ // malloc for the scan struct
+ struct ch347_scan *scan = malloc(sizeof(struct ch347_scan));
+ if (!scan) {
+ LOG_ERROR("malloc failed");
+ return ERROR_FAIL;
+ }
+
+ scan->fields = scan_fields;
+ scan->fields_len = scan_fields_len;
+ list_add_tail(&scan->queue, &ch347.scan_queue);
+ return ERROR_OK;
+}
+
+/**
+ * @brief Function executes the single command and deliver one byte from the buffer
+ * that's read back from USB
+ *
+ * @param read_buf_idx index of the byte that should be returned
+ * @param byte returns byte at index or if index is out of range the first byte
+ * @return ERROR_OK at success
+ */
+static int ch347_single_read_get_byte(int read_buf_idx, uint8_t *byte)
+{
+ int retval = ch347_cmd_transmit_queue();
+ if (retval != ERROR_OK)
+ return retval;
+
+ if (read_buf_idx > CH347_SINGLE_CMD_MAX_READ || read_buf_idx < 0) {
+ LOG_ERROR("read_buf_idx out of range");
+ read_buf_idx = 0;
+ return ERROR_FAIL;
+ }
+
+ *byte = ch347.single_read[read_buf_idx];
+ return ERROR_OK;
+}
+
+/**
+ * @brief checks if the scratchpad is full. If it's full the function creates
+ * a command from it and puts it into the command queue
+ */
+static void ch347_scratchpad_check_full(void)
+{
+ // if full create a new command in the queue
+ if (ch347.scratchpad_idx == UCMDPKT_DATA_MAX_BYTES_USBHS) {
+ uint8_t type = ch347.scratchpad_cmd_type;
+ ch347_cmd_from_scratchpad();
+ ch347.scratchpad_cmd_type = type;
+ }
+}
+
+/**
+ * @brief adds one byte to the scratchpad
+ * if scratchpad is full after this byte the command will be created from the
+ * scratchpad and the scratchpad is cleared for the next command
+ *
+ * @param byte add this byte
+ * @return ERROR_OK at success
+ */
+static int ch347_scratchpad_add_byte(uint8_t byte)
+{
+ if (ch347.scratchpad_cmd_type == 0) {
+ LOG_ERROR("call ch347_next_cmd first!");
+ return ERROR_FAIL;
+ }
+
+ ch347.scratchpad[ch347.scratchpad_idx++] = byte;
+ ch347_scratchpad_check_full();
+ return ERROR_OK;
+}
+
+/**
+ * @brief adds the output pin byte to the scratchpad
+ * if scratchpad is full after this byte the command will be created from the
+ * scratchpad and the scratchpad is cleared for the next command
+ *
+ * @return ERROR_OK at success
+ */
+static int ch347_scratchpad_add_pin_byte(void)
+{
+ return ch347_scratchpad_add_byte(ch347.tms_pin | ch347.tdi_pin | ch347.tck_pin | ch347.trst_pin);
+}
+
+/**
+ * @brief adds bytes from a buffer to the scratchpad
+ * if scratchpad is full after this byte the command will be created from the
+ * scratchpad and the scratchpad is cleared for the next command
+ *
+ * @param bytes add this bytes
+ * @param count byte count
+ *
+ * @return ERROR_OK at success
+ */
+static int ch347_scratchpad_add_bytes(uint8_t *bytes, int count)
+{
+ if (ch347.scratchpad_cmd_type == 0) {
+ LOG_ERROR("call ch347_next_cmd first!");
+ return ERROR_FAIL;
+ }
+
+ int remaining = count;
+ int bytes_idx = 0;
+ while (remaining > 0) {
+ int bytes_to_store = ch347.scratchpad_idx + remaining <= UCMDPKT_DATA_MAX_BYTES_USBHS ?
+ remaining : UCMDPKT_DATA_MAX_BYTES_USBHS - ch347.scratchpad_idx;
+
+ if (bytes)
+ memcpy(&ch347.scratchpad[ch347.scratchpad_idx], &bytes[bytes_idx], bytes_to_store);
+ else
+ memset(&ch347.scratchpad[ch347.scratchpad_idx], 0, bytes_to_store);
+
+ ch347.scratchpad_idx += bytes_to_store;
+ bytes_idx += bytes_to_store;
+ remaining -= bytes_to_store;
+ ch347_scratchpad_check_full();
+ }
+
+ return ERROR_OK;
+}
+
+/**
+ * @brief Function used to change the TMS value at the
+ * rising edge of TCK to switch its TAP state
+ *
+ * @param tms TMS value to be changed; true = output TMS high; false = output TMS low
+ * @return ERROR_OK at success
+ */
+static int ch347_scratchpad_add_clock_tms(bool tms)
+{
+ ch347.tms_pin = tms ? TMS_H : TMS_L;
+ ch347.tck_pin = TCK_L;
+ int retval = ch347_scratchpad_add_pin_byte();
+ if (retval != ERROR_OK)
+ return retval;
+
+ ch347.tck_pin = TCK_H;
+ return ch347_scratchpad_add_pin_byte();
+}
+
+/**
+ * @brief Function adds a certain amount of TCK pulses without changing the TMS pin
+ *
+ * @param count Amount of L/H TCK pulses to add
+ * @return ERROR_OK at success
+ */
+static int ch347_scratchpad_add_stableclocks(int count)
+{
+ int retval = ERROR_OK;
+ if (ch347.scratchpad_cmd_type == 0) {
+ retval = ch347_cmd_start_next(CH347_CMD_JTAG_BIT_OP);
+ if (retval != ERROR_OK)
+ return retval;
+ }
+
+ bool tms = ch347.tms_pin == TMS_H;
+ retval = ERROR_OK;
+ for (int i = 0; i < count; i++) {
+ retval = ch347_scratchpad_add_clock_tms(tms);
+ if (retval != ERROR_OK)
+ return retval;
+ }
+
+ return ERROR_OK;
+}
+
+/**
+ * @brief Function to ensure that the clock is in a low state
+ *
+ * @return ERROR_OK at success
+ */
+static int ch347_scratchpad_add_idle_clock(void)
+{
+ ch347.tck_pin = TCK_L;
+ return ch347_scratchpad_add_pin_byte();
+}
+
+/**
+ * @brief Function that performs state switching by changing the value of TMS
+ *
+ * @param tms_value The TMS values that need to be switched form one byte of data in the switching order
+ * @param step The number of bit values that need to be read from the tms_value value
+ * @param skip Count from the skip bit of tms_value to step
+ * @return ERROR_OK at success
+ */
+static int ch347_scratchpad_add_tms_change(const uint8_t *tms_value, int step, int skip)
+{
+ LOG_DEBUG_IO("TMS Value: %02x..., step = %d, skip = %d", tms_value[0], step, skip);
+
+ int retval = ch347_cmd_start_next(CH347_CMD_JTAG_BIT_OP);
+ if (retval != ERROR_OK)
+ return retval;
+
+ for (int i = skip; i < step; i++) {
+ retval = ch347_scratchpad_add_clock_tms((tms_value[i / 8] >> (i % 8)) & BIT(0));
+ if (retval != ERROR_OK)
+ return retval;
+ }
+
+ return ch347_scratchpad_add_idle_clock();
+}
+
+/**
+ * @brief Obtain the current Tap status and switch to the status TMS value passed down by cmd
+ *
+ * @param cmd Upper layer transfer command parameters
+ * @return ERROR_OK at success; ERROR_JTAG_TRANSITION_INVALID if no transition is possible
+ */
+static int ch347_scratchpad_add_move_path(struct pathmove_command *cmd)
+{
+ LOG_DEBUG_IO("num_states=%d, last_state=%d", cmd->num_states, cmd->path[cmd->num_states - 1]);
+
+ int retval = ch347_cmd_start_next(CH347_CMD_JTAG_BIT_OP);
+ if (retval != ERROR_OK)
+ return retval;
+
+ for (unsigned int i = 0; i < cmd->num_states; i++) {
+ if (tap_state_transition(tap_get_state(), false) == cmd->path[i]) {
+ retval = ch347_scratchpad_add_clock_tms(0);
+ if (retval != ERROR_OK)
+ return retval;
+ } else if (tap_state_transition(tap_get_state(), true) == cmd->path[i]) {
+ retval = ch347_scratchpad_add_clock_tms(1);
+ if (retval != ERROR_OK)
+ return retval;
+ } else {
+ LOG_ERROR("No transition possible!");
+ return ERROR_JTAG_TRANSITION_INVALID;
+ }
+ tap_set_state(cmd->path[i]);
+ }
+
+ return ch347_scratchpad_add_idle_clock();
+}
+
+/**
+ * @brief Toggle the tap state to the target state
+ *
+ * @param state Pre switch target path
+ * @param skip Number of digits to skip
+ * @return ERROR_OK at success
+ */
+static int ch347_scratchpad_add_move_state(enum tap_state state, int skip)
+{
+ uint8_t tms_scan;
+ int tms_len;
+
+ LOG_DEBUG_IO("from %s to %s", tap_state_name(tap_get_state()), tap_state_name(state));
+ // don't do anything if we are already in the right state; but do execute always the TAP_RESET
+ if (tap_get_state() == state && state != TAP_RESET)
+ return ERROR_OK;
+
+ tms_scan = tap_get_tms_path(tap_get_state(), state);
+ tms_len = tap_get_tms_path_len(tap_get_state(), state);
+ int retval = ch347_scratchpad_add_tms_change(&tms_scan, tms_len, skip);
+ tap_set_state(state);
+ return retval;
+}
+
+/**
+ * @brief CH347 Batch read/write function
+ *
+ * @param cmd The scan command
+ * @param bits Read and write data this time
+ * @param bits_len Incoming data length in bits
+ * @param scan The transmission method of incoming data to determine whether to perform data reading
+ * @return ERROR_OK at success
+ */
+static int ch347_scratchpad_add_write_read(struct scan_command *cmd, uint8_t *bits, int bits_len, enum scan_type scan)
+{
+ // the bits and bytes to transfer
+ int byte_count = bits_len / 8;
+ int bit_count = bits_len % 8;
+
+ // only bytes are not possible because we need to set TMS high for the last bit
+ if (byte_count > 0 && bit_count == 0) {
+ // make one byte to eight bits
+ byte_count--;
+ bit_count = 8;
+ }
+
+ // in bitwise mode only bits are allowed
+ if (ch347.use_bitwise_mode) {
+ byte_count = 0;
+ bit_count = bits_len;
+ }
+
+ bool is_read = (scan == SCAN_IN || scan == SCAN_IO);
+
+ // if we need to send bytes
+ if (byte_count > 0) {
+ // start the next cmd and copy the data out bytes to it
+ int retval = ch347_cmd_start_next(is_read ? CH347_CMD_JTAG_DATA_SHIFT_RD : CH347_CMD_JTAG_DATA_SHIFT);
+ if (retval != ERROR_OK)
+ return retval;
+
+ if (bits)
+ retval = ch347_scratchpad_add_bytes(bits, byte_count);
+ else
+ retval = ch347_scratchpad_add_bytes(NULL, byte_count);
+
+ if (retval != ERROR_OK)
+ return retval;
+ }
+
+ // bits are always need to send; no possibility to not send bits
+ int retval = ch347_cmd_start_next(is_read ? CH347_CMD_JTAG_BIT_OP_RD : CH347_CMD_JTAG_BIT_OP);
+ if (retval != ERROR_OK)
+ return retval;
+
+ ch347.tms_pin = TMS_L;
+ ch347.tdi_pin = TDI_L;
+
+ for (int i = 0; i < bit_count; i++) {
+ if (bits)
+ ch347.tdi_pin = ((bits[byte_count + i / 8] >> i % 8) & BIT(0)) ? TDI_H : TDI_L;
+
+ // for the last bit set TMS high to exit the shift state
+ if (i + 1 == bit_count)
+ ch347.tms_pin = TMS_H;
+
+ ch347.tck_pin = TCK_L;
+ retval = ch347_scratchpad_add_pin_byte();
+ if (retval != ERROR_OK)
+ return retval;
+
+ ch347.tck_pin = TCK_H;
+ retval = ch347_scratchpad_add_pin_byte();
+ if (retval != ERROR_OK)
+ return retval;
+
+ /* cut the package after each MAX_BITS_PER_BIT_OP bits because it
+ needs a dividable by 8 bits package */
+ if (i > 0 && (i + 1) % MAX_BITS_PER_BIT_OP == 0) {
+ retval = ch347_cmd_from_scratchpad();
+ if (retval != ERROR_OK)
+ return retval;
+
+ retval = ch347_cmd_start_next(is_read ? CH347_CMD_JTAG_BIT_OP_RD : CH347_CMD_JTAG_BIT_OP);
+ if (retval != ERROR_OK)
+ return retval;
+ }
+ }
+
+ // one TCK_L after the last bit
+ retval = ch347_scratchpad_add_idle_clock();
+ if (retval != ERROR_OK)
+ return retval;
+
+ // if read is involved we need to queue the scan fields
+ if (is_read)
+ return ch347_scan_queue_fields(cmd->fields, cmd->num_fields);
+
+ return ERROR_OK;
+}
+
+/**
+ * @brief Toggle the Tap state to run test/idle
+ *
+ * @param cycles how many clock cycles for output
+ * @param state JTAG end state
+ * @return ERROR_OK at success
+ */
+static int ch347_scratchpad_add_run_test(int cycles, enum tap_state state)
+{
+ LOG_DEBUG_IO("cycles=%d, end_state=%d", cycles, state);
+ int retval = ERROR_OK;
+ if (tap_get_state() != TAP_IDLE) {
+ retval = ch347_scratchpad_add_move_state(TAP_IDLE, 0);
+ if (retval != ERROR_OK)
+ return retval;
+ }
+
+ retval = ch347_scratchpad_add_stableclocks(cycles);
+ if (retval != ERROR_OK)
+ return retval;
+
+ return ch347_scratchpad_add_move_state(state, 0);
+}
+
+/**
+ * @brief Switch to SHIFT-DR or SHIFT-IR status for scanning
+ *
+ * @param cmd Upper layer transfer command parameters
+ * @return ERROR_OK at success
+ */
+static int ch347_scratchpad_add_scan(struct scan_command *cmd)
+{
+ static const char *const type2str[] = {"", "SCAN_IN", "SCAN_OUT", "SCAN_IO"};
+
+ enum scan_type type = jtag_scan_type(cmd);
+ uint8_t *buf = NULL;
+ int scan_bits = jtag_build_buffer(cmd, &buf);
+
+ // add a move to IRSHIFT or DRSHIFT state
+ int retval = ERROR_OK;
+ if (cmd->ir_scan)
+ retval = ch347_scratchpad_add_move_state(TAP_IRSHIFT, 0);
+ else
+ retval = ch347_scratchpad_add_move_state(TAP_DRSHIFT, 0);
+
+ if (retval != ERROR_OK) {
+ free(buf);
+ return retval;
+ }
+
+ if (LOG_LEVEL_IS(LOG_LVL_DEBUG_IO)) {
+ char *log_buf = buf_to_hex_str(buf, scan_bits);
+ LOG_DEBUG_IO("scan=%s, type=%s, bits=%d, buf=[%s], end_state=%d",
+ cmd->ir_scan ? "IRSCAN" : "DRSCAN",
+ type2str[type],
+ scan_bits, log_buf, cmd->end_state);
+ free(log_buf);
+ }
+
+ retval = ch347_scratchpad_add_write_read(cmd, buf, scan_bits, type);
+ free(buf);
+ if (retval != ERROR_OK)
+ return retval;
+
+ // add a move to the final state
+ return ch347_scratchpad_add_move_state(cmd->end_state, 1);
+}
+
+/**
+ * @brief Sets a GPIO bit
+ *
+ * @param gpio GPIO bit number 0-7
+ * @param data true for high; false for low
+ * @return ERROR_OK at success
+ */
+static int ch347_gpio_set(int gpio, bool data)
+{
+ int retval = ch347_cmd_start_next(CH347_CMD_GPIO);
+ if (retval != ERROR_OK)
+ return retval;
+
+ uint8_t gpios[GPIO_CNT];
+ memset(gpios, 0, GPIO_CNT);
+ /* always set bits 7 and 6 for GPIO enable
+ bits 5 and 4 for pin direction output
+ bit 3 is the data bit */
+ gpios[gpio] = data == 0 ? GPIO_SET_L : GPIO_SET_H;
+ retval = ch347_scratchpad_add_bytes(gpios, GPIO_CNT);
+ if (retval != ERROR_OK)
+ return retval;
+
+ // check in the read if the bit is set/cleared correctly
+ uint8_t byte;
+ retval = ch347_single_read_get_byte(gpio, &byte);
+ if (retval != ERROR_OK)
+ return retval;
+
+ if ((byte & BIT(6)) >> 6 != data) {
+ LOG_ERROR("Output not set.");
+ return ERROR_FAIL;
+ }
+
+ return ERROR_OK;
+}
+
+/**
+ * @brief Turn the activity LED on or off
+ *
+ * @param led_state LED_ON or LED_OFF
+ * @return ERROR_OK at success or if pin is not configured
+ */
+static int ch347_activity_led_set(int led_state)
+{
+ if (ch347_activity_led_gpio_pin != 0xFF)
+ return ch347_gpio_set(ch347_activity_led_gpio_pin, ch347_activity_led_active_high ? led_state : 1 - led_state);
+
+ // not configured => also OK
+ return ERROR_OK;
+}
+
+/**
+ * @brief Control (assert/deassert) the signals SRST and TRST on the interface.
+ *
+ * @param trst 1 to assert TRST, 0 to deassert TRST.
+ * @param srst 1 to assert SRST, 0 to deassert SRST.
+ * @return Always ERROR_FAIL for asserting via SRST and TRST in SWD mode.
+ * ERROR_OK for assert/deassert in JTAG mode for TRST
+ */
+static int ch347_reset(int trst, int srst)
+{
+ LOG_DEBUG_IO("reset trst: %i srst %i", trst, srst);
+ if (srst) {
+ LOG_ERROR("Asserting SRST not supported!");
+ return ERROR_FAIL;
+ }
+
+ if (swd_mode) {
+ if (trst)
+ LOG_WARNING("Asserting TRST not supported in SWD mode!");
+ return ERROR_OK;
+ }
+
+ int retval = ch347_cmd_start_next(CH347_CMD_JTAG_BIT_OP);
+ if (retval != ERROR_OK)
+ return retval;
+
+ ch347.trst_pin = trst ? TRST_L : TRST_H;
+ retval = ch347_scratchpad_add_pin_byte();
+ if (retval != ERROR_OK)
+ return retval;
+
+ retval = ch347_scratchpad_add_idle_clock();
+ if (retval != ERROR_OK)
+ return retval;
+
+ return ch347_cmd_transmit_queue();
+}
+
+/**
+ * @brief Flushes the command buffer and sleeps for a specific timespan
+ *
+ * @param us Sleep time in microseconds
+ * @return ERROR_OK at success
+ */
+static int ch347_sleep(int us)
+{
+ LOG_DEBUG_IO("us=%d", us);
+ int retval = ch347_cmd_transmit_queue();
+ jtag_sleep(us);
+ return retval;
+}
+
+/**
+ * @brief Executes the command queue
+ *
+ * @return Success returns ERROR_OK
+ */
+static int ch347_execute_queue(struct jtag_command *cmd_queue)
+{
+ struct jtag_command *cmd = cmd_queue;
+
+ int retval = ch347_activity_led_set(LED_ON);
+ if (retval != ERROR_OK)
+ return retval;
+
+ while (retval == ERROR_OK && cmd) {
+ switch (cmd->type) {
+ case JTAG_RUNTEST:
+ retval = ch347_scratchpad_add_run_test(cmd->cmd.runtest->num_cycles, cmd->cmd.runtest->end_state);
+ break;
+ case JTAG_STABLECLOCKS:
+ retval = ch347_scratchpad_add_stableclocks(cmd->cmd.stableclocks->num_cycles);
+ break;
+ case JTAG_TLR_RESET:
+ retval = ch347_scratchpad_add_move_state(cmd->cmd.statemove->end_state, 0);
+ break;
+ case JTAG_PATHMOVE:
+ retval = ch347_scratchpad_add_move_path(cmd->cmd.pathmove);
+ break;
+ case JTAG_TMS:
+ retval = ch347_scratchpad_add_tms_change(cmd->cmd.tms->bits, cmd->cmd.tms->num_bits, 0);
+ break;
+ case JTAG_SLEEP:
+ retval = ch347_sleep(cmd->cmd.sleep->us);
+ break;
+ case JTAG_SCAN:
+ retval = ch347_scratchpad_add_scan(cmd->cmd.scan);
+ break;
+ default:
+ LOG_ERROR("BUG: unknown JTAG command type 0x%X", cmd->type);
+ retval = ERROR_FAIL;
+ break;
+ }
+
+ cmd = cmd->next;
+ }
+
+ if (retval != ERROR_OK)
+ return retval;
+
+ retval = ch347_cmd_transmit_queue();
+ if (retval != ERROR_OK)
+ return retval;
+
+ return ch347_activity_led_set(LED_OFF);
+}
+
+/**
+ * @brief opens the CH347 device via libusb driver
+ *
+ * @return ERROR_OK on success
+ */
+static int ch347_open_device(void)
+{
+ const uint16_t *ch347_vids = custom_ch347_vids[0] != 0 ? custom_ch347_vids : default_ch347_vids;
+ const uint16_t *ch347_pids = custom_ch347_pids[0] != 0 ? custom_ch347_pids : default_ch347_pids;
+
+ int retval = jtag_libusb_open(ch347_vids, ch347_pids, ch347_device_desc, &ch347_handle, NULL);
+ if (retval != ERROR_OK) {
+ char error_message[256];
+ snprintf(error_message, sizeof(error_message), "CH347 not found. Tried VID/PID pairs: ");
+ for (int i = 0; ch347_vids[i] != 0; i++)
+ snprintf(error_message + strlen(error_message), sizeof(error_message) - strlen(error_message),
+ "%04x:%04x ", ch347_vids[i], ch347_pids[i]);
+
+ LOG_ERROR("%s", error_message);
+ return retval;
+ }
+
+ struct libusb_device_descriptor ch347_device_descriptor;
+ libusb_device *device = libusb_get_device(ch347_handle);
+ if (!device) {
+ LOG_ERROR("CH347 error calling libusb_get_device");
+ jtag_libusb_close(ch347_handle);
+ return ERROR_FAIL;
+ }
+
+ retval = libusb_get_device_descriptor(device, &ch347_device_descriptor);
+ if (retval != ERROR_OK) {
+ LOG_ERROR("CH347 error getting device descriptor: %s", libusb_error_name(retval));
+ jtag_libusb_close(ch347_handle);
+ return retval;
+ }
+
+ // CH347T / CH347F detection
+ // if we can claim interface 4 we found a CH347F chip; if we can claim interface 2 we found CH347T chip
+ retval = libusb_claim_interface(ch347_handle, CH347F_MPHSI_INTERFACE);
+ if (retval != ERROR_OK) {
+ retval = libusb_claim_interface(ch347_handle, CH347T_MPHSI_INTERFACE);
+ if (retval != ERROR_OK) {
+ LOG_ERROR("CH347 unable to claim interface: %s", libusb_error_name(retval));
+ jtag_libusb_close(ch347_handle);
+ return retval;
+ }
+ ch347.chip_variant = CH347T;
+ } else {
+ ch347.chip_variant = CH347F;
+ }
+
+ char firmware_version;
+ retval = jtag_libusb_control_transfer(ch347_handle,
+ LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE,
+ VENDOR_VERSION, 0, 0, &firmware_version, sizeof(firmware_version),
+ USB_WRITE_TIMEOUT, NULL);
+ if (retval != ERROR_OK) {
+ LOG_ERROR("CH347 unable to get firmware version");
+ jtag_libusb_close(ch347_handle);
+ return retval;
+ }
+
+ char manufacturer[256 + 1];
+ if (libusb_get_string_descriptor_ascii(ch347_handle, ch347_device_descriptor.iManufacturer,
+ (unsigned char *)manufacturer, sizeof(manufacturer) - 1) < 0) {
+ strcpy(manufacturer, "(unknown)");
+ }
+ char product[256 + 1];
+ if (libusb_get_string_descriptor_ascii(ch347_handle, ch347_device_descriptor.iProduct,
+ (unsigned char *)product, sizeof(product) - 1) < 0) {
+ strcpy(product, "(unknown)");
+ }
+ char serial_number[256 + 1];
+ if (libusb_get_string_descriptor_ascii(ch347_handle, ch347_device_descriptor.iSerialNumber,
+ (unsigned char *)serial_number, sizeof(serial_number) - 1) < 0) {
+ strcpy(serial_number, "(unknown)");
+ }
+
+ LOG_INFO("CH347 %s from vendor %s with serial number %s found. (Chip version=%X.%2X, Firmware=0x%02X)",
+ product,
+ manufacturer,
+ serial_number,
+ (ch347_device_descriptor.bcdDevice >> 8) & 0xFF,
+ ch347_device_descriptor.bcdDevice & 0xFF,
+ firmware_version);
+
+ if (ch347.chip_variant == CH347T && ch347_device_descriptor.bcdDevice < BYTEWISE_MODE_VERSION) {
+ LOG_INFO("CH347 old version of the chip, JTAG only working in bitwise mode. For bytewise mode at least version %X.%X is needed.",
+ (BYTEWISE_MODE_VERSION >> 8) & 0xFF,
+ BYTEWISE_MODE_VERSION & 0xFF);
+ ch347.use_bitwise_mode = true;
+ } else {
+ ch347.use_bitwise_mode = false;
+ }
+ return ERROR_OK;
+}
+
+/**
+ * @brief CH347 Device Release Function
+ *
+ * @return ERROR_OK on success
+ */
+static int ch347_quit(void)
+{
+ // on close set the LED on, because the state without JTAG is on
+ ch347_activity_led_set(LED_ON);
+ int retval = ch347_cmd_transmit_queue();
+ jtag_libusb_close(ch347_handle);
+ LOG_DEBUG_IO("CH347 close");
+ return retval;
+}
+
+/**
+ * @brief Sends the CH347_CMD_JTAG_INIT (D0) command to get the JTAG
+ * interface initialized with the speed index or asking with special clock index 9
+ * for the LARGER_PACK mode support
+ *
+ * @param clock_index Clock index; special clock index 9 is used for checking
+ * if the device supports the LARGER_PACK mode
+ * @param supports_larger_pack_mode returns true if the device supports the LARGER_PACK mode
+ * for newer CH347 devices; false if the device supports only the older STANDARD_PACK mode
+ * @return ERROR_OK on success
+ */
+static int ch347_adapter_init(uint8_t clock_index, bool *supports_larger_pack_mode)
+{
+ int retval = ch347_cmd_start_next(CH347_CMD_JTAG_INIT);
+ if (retval != ERROR_OK)
+ return retval;
+
+ retval = ch347_scratchpad_add_byte(0);
+ if (retval != ERROR_OK)
+ return retval;
+
+ retval = ch347_scratchpad_add_byte(clock_index);
+ if (retval != ERROR_OK)
+ return retval;
+
+ for (int i = 0; i < 4; i++) {
+ retval = ch347_scratchpad_add_pin_byte();
+ if (retval != ERROR_OK)
+ return retval;
+ }
+
+ uint8_t mode;
+ retval = ch347_single_read_get_byte(0, &mode);
+ if (retval != ERROR_OK)
+ return retval;
+
+ *supports_larger_pack_mode = mode != 0;
+ return ERROR_OK;
+}
+
+/**
+ * @brief Sends the CH347_CMD_JTAG_INIT (D0) command to ask the JTAG
+ * interface with special clock index 9 for the LARGER_PACK mode support
+ *
+ * @param supports_larger_pack_mode returns true if the device supports the LARGER_PACK mode
+ * for newer CH347 devices; false if the device supports only the older STANDARD_PACK mode
+ * @return ERROR_OK on success
+ */
+static int ch347_adapter_supports_larger_pack_mode(bool *supports_larger_pack_mode)
+{
+ return ch347_adapter_init(CH347_CMD_INIT_GET_MODE_CLOCK_INDEX_VALUE, supports_larger_pack_mode);
+}
+
+/**
+ * @brief Sends the CH347_CMD_JTAG_INIT (D0) command to get the JTAG
+ * interface initialized with the speed index
+ *
+ * @param clock_index Clock index
+ * @return ERROR_OK on success
+ */
+static int ch347_adapter_set_speed(uint8_t clock_index)
+{
+ bool unused;
+ return ch347_adapter_init(clock_index, &unused);
+}
+
+/**
+ * @brief Initializes the JTAG interface and set CH347 TCK frequency
+ *
+ * @param speed_index speed index for JTAG_INIT command
+ * @return Success returns ERROR_OKï¼failed returns ERROR_FAIL
+ */
+static int ch347_speed_set(int speed_index)
+{
+ if (swd_mode)
+ return ERROR_OK;
+ int retval = ch347_adapter_set_speed(speed_index);
+ if (retval != ERROR_OK) {
+ LOG_ERROR("Couldn't set CH347 speed");
+ return retval;
+ }
+
+ return ERROR_OK;
+}
+
+/**
+ * @brief inits ch347.pack_size and ch347.max_len
+ *
+ * @return ERROR_OK on success
+ */
+static int ch347_init_pack_size(void)
+{
+ // already set?
+ if (ch347.pack_size != UNSET)
+ return ERROR_OK;
+
+ // set the lower lim...
[truncated message content] |
|
From: openocd-gerrit <ope...@us...> - 2025-08-17 13:43:24
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Main OpenOCD repository".
The branch, master has been updated
via 68b6d3ad477b45a54282571ebd4ed8a53cf7dd90 (commit)
from c132aed2a611a16f4759626123ab78e446a737ce (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 68b6d3ad477b45a54282571ebd4ed8a53cf7dd90
Author: Adrien Charruel <ach...@na...>
Date: Fri Nov 8 15:18:07 2024 +0100
jtag/driver/angie: Update Angie probe driver
Update jtag driver code to reflect these changes and properly drive
Angie probe.
The rationale behind this is to increase the probe performances,
especially in use cases when large files shall be loaded on a target.
The USB transfer performances are now close to those obtained with a
standard FTDI probe.
Change-Id: I3b31d75a3f66c2d07fed8c7423f765acc30925f8
Signed-off-by: Adrien Charruel <ach...@na...>
Reviewed-on: https://review.openocd.org/c/openocd/+/8711
Tested-by: jenkins
Reviewed-by: Antonio Borneo <bor...@gm...>
diff --git a/contrib/60-openocd.rules b/contrib/60-openocd.rules
index 6632841a4..2a2fe88e6 100644
--- a/contrib/60-openocd.rules
+++ b/contrib/60-openocd.rules
@@ -252,8 +252,6 @@ ATTRS{idVendor}=="303a", ATTRS{idProduct}=="1002", MODE="660", GROUP="plugdev",
# ANGIE USB-JTAG Adapter
ATTRS{idVendor}=="584e", ATTRS{idProduct}=="414f", MODE="660", GROUP="plugdev", TAG+="uaccess"
ATTRS{idVendor}=="584e", ATTRS{idProduct}=="424e", MODE="660", GROUP="plugdev", TAG+="uaccess"
-ATTRS{idVendor}=="584e", ATTRS{idProduct}=="4255", MODE="660", GROUP="plugdev", TAG+="uaccess"
-ATTRS{idVendor}=="584e", ATTRS{idProduct}=="4355", MODE="660", GROUP="plugdev", TAG+="uaccess"
ATTRS{idVendor}=="584e", ATTRS{idProduct}=="4a55", MODE="660", GROUP="plugdev", TAG+="uaccess"
# Marvell Sheevaplug
diff --git a/src/jtag/drivers/Makefile.am b/src/jtag/drivers/Makefile.am
index e55e0478c..481840504 100644
--- a/src/jtag/drivers/Makefile.am
+++ b/src/jtag/drivers/Makefile.am
@@ -127,8 +127,6 @@ endif
if ANGIE
angiedir = $(pkgdatadir)/angie
DRIVERFILES += %D%/angie.c
- DRIVERFILES += %D%/angie/include/msgtypes.h
- EXTRA_DIST += %D%/angie/README
dist_angie_DATA = %D%/angie/angie_firmware.bin
dist_angie_DATA += %D%/angie/angie_bitstream.bit
%C%_libocdjtagdrivers_la_LIBADD += -lm
diff --git a/src/jtag/drivers/angie.c b/src/jtag/drivers/angie.c
index 56a118eae..6d8dc2c3b 100644
--- a/src/jtag/drivers/angie.c
+++ b/src/jtag/drivers/angie.c
@@ -1,274 +1,398 @@
// SPDX-License-Identifier: GPL-2.0-or-later
-/***************************************************************************
- File : angie.c *
- Contents : OpenOCD driver code for NanoXplore USB-JTAG ANGIE *
- adapter hardware. *
- Based on openULINK driver code by: Martin Schmoelzer. *
- Copyright 2023, Ahmed Errached BOUDJELIDA, NanoXplore SAS. *
- <abo...@na...> *
- <ahm...@gm...> *
- ***************************************************************************/
+/****************************************************************************
+ * File : angie.c
+ * Contents : Driver code for NanoXplore USB-JTAG ANGIE
+ * adapter hardware.
+ * Based on FT232R driver code by: Serge Vakulenko
+ *
+ * Copyright 2024, Ahmed BOUDJELIDA, NanoXplore SAS.
+ * <abo...@na...>
+ ****************************************************************************/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
-#include <stdio.h>
-#include <stdlib.h>
-#include <math.h>
-#include "helper/system.h"
-#include <helper/types.h>
+#if IS_CYGWIN == 1
+#include "windows.h"
+#undef LOG_ERROR
+#endif
+
+// project specific includes
+#include <jtag/adapter.h>
#include <jtag/interface.h>
#include <jtag/commands.h>
+#include <helper/time_support.h>
+#include "libusb_helper.h"
#include <target/image.h>
#include <libusb.h>
-#include "libusb_helper.h"
-#include "angie/include/msgtypes.h"
-/** USB Vendor ID of ANGIE device in unconfigured state (no firmware loaded
- * yet) or with its firmware. */
-#define ANGIE_VID 0x584e
+// system includes
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/time.h>
+#include <time.h>
+
+/*
+ * Sync bit bang mode is implemented as described in FTDI Application
+ * Note AN232R-01: "Bit Bang Modes for the ANGIE and FT245R".
+ */
-/** USB Product ID of ANGIE device in unconfigured state (no firmware loaded
- * yet) or with its firmware. */
-#define ANGIE_PID 0x414F
-#define ANGIE_PID_2 0x424e
-#define ANGIE_PID_3 0x4255
-#define ANGIE_PID_4 0x4355
-#define ANGIE_PID_5 0x4a55
+/**
+ * USB endpoints.
+ */
+#define IN_EP 0x84
+#define OUT_EP 0x02
-/** Address of EZ-USB ANGIE CPU Control & Status register. This register can be
- * written by issuing a Control EP0 vendor request. */
-#define CPUCS_REG 0xE600
+/**
+ * Address of EZ-USB ANGIE CPU Control & Status register.
+ * This register can be written by issuing a Control EP0 vendor request.
+ */
+#define CPUCS_REG 0xE600
/** USB Control EP0 bRequest: "Firmware Load". */
#define REQUEST_FIRMWARE_LOAD 0xA0
/** Value to write into CPUCS to put EZ-USB ANGIE into reset. */
-#define CPU_RESET 0x01
+#define CPU_RESET 0x01
/** Value to write into CPUCS to put EZ-USB ANGIE out of reset. */
-#define CPU_START 0x00
+#define CPU_START 0x00
/** Base address of firmware in EZ-USB ANGIE code space. */
-#define FIRMWARE_ADDR 0x0000
-
-/** USB interface number */
-#define USB_INTERFACE 0
+#define FIRMWARE_ADDR 0x0000
/** Delay (in microseconds) to wait while EZ-USB performs ReNumeration. */
-#define ANGIE_RENUMERATION_DELAY_US 1500000
+#define ANGIE_RENUMERATION_DELAY_US 800000
/** Default location of ANGIE firmware image. */
-#define ANGIE_FIRMWARE_FILE PKGDATADIR "/angie/angie_firmware.bin"
+#define ANGIE_FIRMWARE_FILE PKGDATADIR "/angie/angie_firmware.bin"
/** Default location of ANGIE firmware image. */
-#define ANGIE_BITSTREAM_FILE PKGDATADIR "/angie/angie_bitstream.bit"
+#define ANGIE_BITSTREAM_FILE PKGDATADIR "/angie/angie_bitstream.bit"
+
+/**
+ * Maximum size of a single firmware section.
+ * Entire EZ-USB ANGIE code space = 16kB
+ */
+#define ANGIE_FW_SECTION_SIZE 16384
+
+/** Vendor Requests */
+#define VR_CFGOPEN 0xB0
+#define VR_DATAOUTOPEN 0xB2
+
+#define ANGIE_VID 0x584E /* NX Vendor id */
+#define ANGIE_NPROG_PID 0x424E /* ANGIE non programmed */
+#define ANGIE_PROG_OOCD_PID 0x414F /* ANGIE programmed OpenOCD */
+#define ANGIE_PROG_NXB2_PID 0x4a55 /* ANGIE programmed Nxbase2 */
+
+#define TCK_GPIO 0
+#define TDI_GPIO 1
+#define TDO_GPIO 2
+#define TMS_GPIO 3
+#define NTRST_GPIO 4
+#define NSYSRST_GPIO 6
-/** Maximum size of a single firmware section. Entire EZ-USB ANGIE code space = 16kB */
-#define SECTION_BUFFERSIZE 16384
+#define ANGIE_XFER_BUFFER_TOTAL_SIZE (16 * 1024)
+#define ANGIE_USB_BULK_SIZE 512
-/** Tuning of OpenOCD SCAN commands split into multiple ANGIE commands. */
-#define SPLIT_SCAN_THRESHOLD 10
+/** USB timeout delay in milliseconds */
+#define ANGIE_USB_TIMEOUT_MS 1000
-/** ANGIE hardware type */
-enum angie_type {
- ANGIE,
+/**
+ * List of elements used in a multiple commands reply.
+ */
+struct read_queue {
+ struct list_head list;
};
-enum angie_payload_direction {
- PAYLOAD_DIRECTION_OUT,
- PAYLOAD_DIRECTION_IN
+/**
+ * Entry element used to forge a reply buffer for openocd JTAG core.
+ */
+struct read_queue_entry {
+ const struct scan_command *cmd;
+ int reply_buffer_offset;
+ uint8_t *buffer;
+ struct list_head list;
};
-enum angie_delay_type {
- DELAY_CLOCK_TCK,
- DELAY_CLOCK_TMS,
- DELAY_SCAN_IN,
- DELAY_SCAN_OUT,
- DELAY_SCAN_IO
+/**
+ * Angie device main context
+ */
+struct angie {
+ struct libusb_device_handle *usbdev;
+ uint8_t xfer_buffer[ANGIE_XFER_BUFFER_TOTAL_SIZE];
+ size_t xfer_buffer_len;
+ uint8_t reply_buffer[ANGIE_XFER_BUFFER_TOTAL_SIZE];
+ size_t reply_buffer_len;
+ struct read_queue read_queue;
};
/**
- * ANGIE command (ANGIE command queue element).
+ * Angie device singleton
+ */
+struct angie *angie_handle;
+
+/**
+ * Init read queue list
*
- * For the OUT direction payload, things are quite easy: Payload is stored
- * in a rather small array (up to 63 bytes), the payload is always allocated
- * by the function generating the command and freed by angie_clear_queue().
+ * @param queue: pointer on the read queue head
+ */
+static void angie_read_queue_init(struct read_queue *queue)
+{
+ INIT_LIST_HEAD(&queue->list);
+}
+
+
+/**
+ * Add a single entry to the read queue
*
- * For the IN direction payload, things get a little bit more complicated:
- * The maximum IN payload size for a single command is 64 bytes. Assume that
- * a single OpenOCD command needs to scan 256 bytes. This results in the
- * generation of four ANGIE commands. The function generating these
- * commands shall allocate an uint8_t[256] array. Each command's #payload_in
- * pointer shall point to the corresponding offset where IN data shall be
- * placed, while #payload_in_start shall point to the first element of the 256
- * byte array.
- * - first command: #payload_in_start + 0
- * - second command: #payload_in_start + 64
- * - third command: #payload_in_start + 128
- * - fourth command: #payload_in_start + 192
+ * @param queue: read queue list
+ * @param entry to append
+ */
+static void angie_read_queue_add(struct read_queue *queue,
+ struct read_queue_entry *entry)
+{
+ list_add_tail(&entry->list, &queue->list);
+}
+
+/**
+ * Execute elements enqueued in the read queue list
*
- * The last command sets #needs_postprocessing to true.
+ * @param queue: read queue list
+ * @param device: pointer on the angie device
*/
-struct angie_cmd {
- uint8_t id; /**< ANGIE command ID */
+static void angie_read_queue_execute(struct read_queue *queue,
+ struct angie *device)
+{
+ struct read_queue_entry *entry;
+ struct read_queue_entry *tmp;
+
+ list_for_each_entry_safe(entry, tmp, &queue->list, list) {
+ int scan_size = jtag_scan_size(entry->cmd);
+
+ // iterate over each bit in scan data
+ for (int bit_cnt = 0; bit_cnt < scan_size; bit_cnt++) {
+ // calculate byte index
+ int bytec = bit_cnt / 8;
+ // calculate bit mask: isolate the specific bit in corresponding byte
+ int bcval = 1 << (bit_cnt % 8);
+ // extract tdo value using index: "bit0_index + bit_cnt*2 + 1"
+ int val = device->reply_buffer[entry->reply_buffer_offset + bit_cnt * 2 + 1];
+ if (val & (1 << TDO_GPIO))
+ entry->buffer[bytec] |= bcval;
+ else
+ entry->buffer[bytec] &= ~bcval;
+ }
+
+ jtag_read_buffer(entry->buffer, entry->cmd);
- uint8_t *payload_out; /**< Pointer where OUT payload shall be stored */
- uint8_t payload_out_size; /**< OUT direction payload size for this command */
+ list_del(&entry->list);
+ free(entry->buffer);
+ free(entry);
+ }
+}
- uint8_t *payload_in_start; /**< Pointer to first element of IN payload array */
- uint8_t *payload_in; /**< Pointer where IN payload shall be stored */
- uint8_t payload_in_size; /**< IN direction payload size for this command */
+/**
+ * Clear the read queue list
+ *
+ * @param queue: read queue list
+ */
+static void angie_read_queue_clean(struct read_queue *queue)
+{
+ struct read_queue_entry *entry;
+ struct read_queue_entry *tmp;
- /** Indicates if this command needs post-processing */
- bool needs_postprocessing;
+ list_for_each_entry_safe(entry, tmp, &queue->list, list) {
+ list_del(&entry->list);
+ free(entry->buffer);
+ free(entry);
+ }
+}
- /** Indicates if angie_clear_queue() should free payload_in_start */
- bool free_payload_in_start;
+/**
+ * Flush a chunk of Angie's buffer
+ *
+ * USB write is done by configuring GPIF register on the target and calling
+ * a USB bulk transfer.
+ * Sequentially a USB read transferred is issued of the same size.
+ * All the operation are synchronous.
+ * Then the read queue list is executed once the read buffer has been retrieved.
+ *
+ * @param device: Angie device pointer
+ * @param xfer_size: amount of bytes to transfer
+ * @param offset: total bytes already sent during this transfer, this will
+ * offset the receive buffer accordingly
+ * @param bytes_sent: will contain the amount of bytes sent
+ * @return ERROR_OK on success, negative error code otherwise
+ */
+static int angie_buffer_flush_chunk(struct angie *device,
+ int xfer_size,
+ int offset,
+ int *bytes_sent)
+{
+ uint8_t gpifcnt[4];
+ int sent_chunk_size = 0, bytes_received = 0;
- /** Pointer to corresponding OpenOCD command for post-processing */
- struct jtag_command *cmd_origin;
+ if (bytes_sent)
+ *bytes_sent = 0;
- struct angie_cmd *next; /**< Pointer to next command (linked list) */
-};
+ h_u32_to_be(gpifcnt, xfer_size);
-/** Describes one driver instance */
-struct angie {
- struct libusb_context *libusb_ctx;
- struct libusb_device_handle *usb_device_handle;
- enum angie_type type;
-
- unsigned int ep_in; /**< IN endpoint number */
- unsigned int ep_out; /**< OUT endpoint number */
-
- /* delay value for "SLOW_CLOCK commands" in [0:255] range in units of 4 us;
- -1 means no need for delay */
- int delay_scan_in; /**< Delay value for SCAN_IN commands */
- int delay_scan_out; /**< Delay value for SCAN_OUT commands */
- int delay_scan_io; /**< Delay value for SCAN_IO commands */
- int delay_clock_tck; /**< Delay value for CLOCK_TMS commands */
- int delay_clock_tms; /**< Delay value for CLOCK_TCK commands */
-
- int commands_in_queue; /**< Number of commands in queue */
- struct angie_cmd *queue_start; /**< Pointer to first command in queue */
- struct angie_cmd *queue_end; /**< Pointer to last command in queue */
-};
+ int ret = jtag_libusb_control_transfer(device->usbdev,
+ LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE,
+ VR_DATAOUTOPEN, 0, 0, (char *)gpifcnt, sizeof(gpifcnt),
+ ANGIE_USB_TIMEOUT_MS, NULL);
+ if (ret != ERROR_OK) {
+ LOG_ERROR("Failed to send GPIF count to target");
+ return ret;
+ }
-/**************************** Function Prototypes *****************************/
-
-/* USB helper functions */
-static int angie_usb_open(struct angie *device);
-static int angie_usb_close(struct angie *device);
-
-/* ANGIE MCU (Cypress EZ-USB) specific functions */
-static int angie_cpu_reset(struct angie *device, char reset_bit);
-static int angie_load_firmware_and_renumerate(struct angie *device, const char *filename,
- uint32_t delay_us);
-static int angie_load_firmware(struct angie *device, const char *filename);
-static int angie_load_bitstream(struct angie *device, const char *filename);
-static int angie_i2c_write(struct angie *device, uint8_t *i2c_data, uint8_t i2c_data_size);
-static int angie_io_extender_config(struct angie *device, uint8_t i2c_adr, uint8_t cfg_value);
-static int angie_write_firmware_section(struct angie *device,
- struct image *firmware_image, int section_index);
-
-/* Generic helper functions */
-static void angie_dump_signal_states(uint8_t input_signals, uint8_t output_signals);
-
-/* ANGIE command generation helper functions */
-static int angie_allocate_payload(struct angie_cmd *angie_cmd, int size,
- enum angie_payload_direction direction);
-
-/* ANGIE command queue helper functions */
-static int angie_get_queue_size(struct angie *device,
- enum angie_payload_direction direction);
-static void angie_clear_queue(struct angie *device);
-static int angie_append_queue(struct angie *device, struct angie_cmd *angie_cmd);
-static int angie_execute_queued_commands(struct angie *device, int timeout_ms);
-
-static void angie_dump_queue(struct angie *device);
-
-static int angie_append_scan_cmd(struct angie *device,
- enum scan_type scan_type,
- int scan_size_bits,
- uint8_t *tdi,
- uint8_t *tdo_start,
- uint8_t *tdo,
- uint8_t tms_count_start,
- uint8_t tms_sequence_start,
- uint8_t tms_count_end,
- uint8_t tms_sequence_end,
- struct jtag_command *origin,
- bool postprocess);
-static int angie_append_clock_tms_cmd(struct angie *device, uint8_t count,
- uint8_t sequence);
-static int angie_append_clock_tck_cmd(struct angie *device, uint16_t count);
-static int angie_append_get_signals_cmd(struct angie *device);
-static int angie_append_set_signals_cmd(struct angie *device, uint8_t low,
- uint8_t high);
-static int angie_append_sleep_cmd(struct angie *device, uint32_t us);
-static int angie_append_configure_tck_cmd(struct angie *device,
- int delay_scan_in,
- int delay_scan_out,
- int delay_scan_io,
- int delay_tck,
- int delay_tms);
-static int angie_append_test_cmd(struct angie *device);
-
-/* ANGIE TCK frequency helper functions */
-static int angie_calculate_delay(enum angie_delay_type type, long f, int *delay);
-
-/* Interface between ANGIE and OpenOCD */
-static void angie_set_end_state(enum tap_state endstate);
-static int angie_queue_statemove(struct angie *device);
-
-static int angie_queue_scan(struct angie *device, struct jtag_command *cmd);
-static int angie_queue_tlr_reset(struct angie *device, struct jtag_command *cmd);
-static int angie_queue_runtest(struct angie *device, struct jtag_command *cmd);
-static int angie_queue_pathmove(struct angie *device, struct jtag_command *cmd);
-static int angie_queue_sleep(struct angie *device, struct jtag_command *cmd);
-static int angie_queue_stableclocks(struct angie *device, struct jtag_command *cmd);
-
-static int angie_post_process_scan(struct angie_cmd *angie_cmd);
-static int angie_post_process_queue(struct angie *device);
-
-/* adapter driver functions */
-static int angie_execute_queue(struct jtag_command *cmd_queue);
-static int angie_khz(int khz, int *jtag_speed);
-static int angie_speed(int speed);
-static int angie_speed_div(int speed, int *khz);
-static int angie_init(void);
-static int angie_quit(void);
-static int angie_reset(int trst, int srst);
-
-/****************************** Global Variables ******************************/
-
-static struct angie *angie_handle;
-
-/**************************** USB helper functions ****************************/
+ ret = jtag_libusb_bulk_write(device->usbdev, OUT_EP,
+ (char *)device->xfer_buffer + offset,
+ xfer_size, ANGIE_USB_TIMEOUT_MS, &sent_chunk_size);
+ if (ret != ERROR_OK) {
+ LOG_ERROR("USB bulk transfer failed");
+ return ret;
+ }
+
+ ret = jtag_libusb_bulk_read(device->usbdev, IN_EP,
+ (char *)device->reply_buffer + offset,
+ sent_chunk_size, ANGIE_USB_TIMEOUT_MS, &bytes_received);
+ if (ret != ERROR_OK) {
+ LOG_ERROR("Failed to read USB reply");
+ return ret;
+ }
+
+ if (sent_chunk_size == xfer_size && bytes_received == xfer_size) {
+ device->reply_buffer_len += xfer_size;
+ device->xfer_buffer_len -= xfer_size;
+ if (bytes_sent)
+ *bytes_sent += sent_chunk_size;
+ } else {
+ return ERROR_FAIL;
+ }
+
+ return ERROR_OK;
+}
/**
- * Opens the ANGIE device
+ * Flush Angie transfer buffer
*
- * @param device pointer to struct angie identifying ANGIE driver instance.
- * @return on success: ERROR_OK
- * @return on failure: ERROR_FAIL
+ * Flush is done by chunks of 512 bytes to match hardware internal FIFOs.
+ * Then the read queue list is executed once the read buffer has been retrieved.
+ *
+ * @param device: Angie device pointer
+ * @return ERROR_OK on success, negative error code otherwise
*/
-static int angie_usb_open(struct angie *device)
+static int angie_buffer_flush(struct angie *device)
+{
+ if (device->xfer_buffer_len == 0)
+ return ERROR_OK;
+
+ int total_bytes_sent = 0;
+ device->reply_buffer_len = 0;
+
+ do {
+ int sent_chunk_size;
+ size_t xfer_size = MIN(device->xfer_buffer_len, ANGIE_USB_BULK_SIZE);
+ int ret = angie_buffer_flush_chunk(device, xfer_size,
+ total_bytes_sent, &sent_chunk_size);
+ if (ret != ERROR_OK)
+ return ret;
+ total_bytes_sent += sent_chunk_size;
+ } while (device->xfer_buffer_len > 0);
+
+ angie_read_queue_execute(&device->read_queue, device);
+
+ return ERROR_OK;
+}
+
+/**
+ * Check if transfer buffer has enough remaining space for a given size.
+ * If the buffer is not large enough, flush it.
+ *
+ * @param device: Angie device pointer
+ * @param size to check
+ * @return ERROR_OK on success, negative error code otherwise
+ */
+static int angie_buffer_flush_check(struct angie *device, size_t size)
+{
+ if (device->xfer_buffer_len + size >= ANGIE_XFER_BUFFER_TOTAL_SIZE)
+ return angie_buffer_flush(device);
+ return ERROR_OK;
+}
+
+/**
+ * Append a single byte value to the transfer buffer
+ *
+ * @param device: Angie device pointer
+ * @param value to append
+ * @return ERROR_OK on success, negative error code otherwise
+ */
+static int angie_buffer_append_simple(struct angie *device, uint8_t value)
{
- struct libusb_device_handle *usb_device_handle;
- const uint16_t vids[] = {ANGIE_VID, ANGIE_VID, ANGIE_VID, ANGIE_VID, ANGIE_VID, 0};
- const uint16_t pids[] = {ANGIE_PID, ANGIE_PID_2, ANGIE_PID_3, ANGIE_PID_4, ANGIE_PID_5, 0};
+ if (device->xfer_buffer_len >= ANGIE_XFER_BUFFER_TOTAL_SIZE) {
+ int ret = angie_buffer_flush(device);
+ if (ret != ERROR_OK)
+ return ret;
+ }
+ device->xfer_buffer[device->xfer_buffer_len++] = value;
+ return ERROR_OK;
+}
- int ret = jtag_libusb_open(vids, pids, NULL, &usb_device_handle, NULL);
+/**
+ * Append a bit-bang JTAG value to the transfer buffer.
+ *
+ * @param device: Angie device pointer
+ * @param tck value
+ * @param tms value
+ * @param tdi value
+ * @return ERROR_OK on success, negative error code otherwise
+ */
+static int angie_buffer_append(struct angie *device, int tck, int tms, int tdi)
+{
+ uint8_t val = (1 << NTRST_GPIO) | (1 << NSYSRST_GPIO);
+ if (tck)
+ val |= (1 << TCK_GPIO);
+ if (tms)
+ val |= (1 << TMS_GPIO);
+ if (tdi)
+ val |= (1 << TDI_GPIO);
+
+ return angie_buffer_append_simple(device, val);
+}
+/**
+ * Open Angie USB interface
+ *
+ * @param device: Angie device pointer
+ * @return ERROR_OK on success, negative error code otherwise
+ */
+static int angie_usb_open(struct angie *device)
+{
+ uint16_t avids[] = {
+ ANGIE_VID,
+ ANGIE_VID,
+ ANGIE_VID,
+ 0,
+ };
+ uint16_t apids[] = {
+ ANGIE_NPROG_PID,
+ ANGIE_PROG_OOCD_PID,
+ ANGIE_PROG_NXB2_PID,
+ 0,
+ };
+ struct libusb_device_handle *usb_dev;
+
+ int ret = jtag_libusb_open(avids, apids, NULL, &usb_dev, NULL);
if (ret != ERROR_OK) {
- LOG_ERROR("Could not find and open ANGIE");
+ LOG_ERROR("Failed to open ANGIE USB interface");
return ret;
}
- device->usb_device_handle = usb_device_handle;
- device->type = ANGIE;
+ device->usbdev = usb_dev;
return ERROR_OK;
}
@@ -276,80 +400,84 @@ static int angie_usb_open(struct angie *device)
/**
* Releases the ANGIE interface and closes the USB device handle.
*
- * @param device pointer to struct angie identifying ANGIE driver instance.
- * @return on success: ERROR_OK
- * @return on failure: ERROR_FAIL
+ * @param device: Angie device pointer
+ * @return ERROR_OK on success, negative error code otherwise
*/
static int angie_usb_close(struct angie *device)
{
- if (device->usb_device_handle) {
- if (libusb_release_interface(device->usb_device_handle, 0) != 0) {
+ int ret = ERROR_OK;
+
+ if (device->usbdev) {
+ if (libusb_release_interface(device->usbdev, 0) != LIBUSB_SUCCESS) {
LOG_ERROR("Could not release interface 0");
- return ERROR_FAIL;
+ ret = ERROR_FAIL;
}
- jtag_libusb_close(device->usb_device_handle);
- device->usb_device_handle = NULL;
+ jtag_libusb_close(device->usbdev);
+ device->usbdev = NULL;
}
- return ERROR_OK;
-}
-/******************* ANGIE CPU (EZ-USB) specific functions ********************/
+ return ret;
+}
/**
* Writes '0' or '1' to the CPUCS register, putting the EZ-USB CPU into reset
* or out of reset.
*
- * @param device pointer to struct angie identifying ANGIE driver instance.
+ * @param device: Angie device pointer
* @param reset_bit 0 to put CPU into reset, 1 to put CPU out of reset.
- * @return on success: ERROR_OK
- * @return on failure: ERROR_FAIL
+ * @return ERROR_OK on success, negative error code otherwise
*/
static int angie_cpu_reset(struct angie *device, char reset_bit)
{
- return jtag_libusb_control_transfer(device->usb_device_handle,
- (LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE),
- REQUEST_FIRMWARE_LOAD, CPUCS_REG, 0, &reset_bit, 1, LIBUSB_TIMEOUT_MS, NULL);
+ return jtag_libusb_control_transfer(device->usbdev,
+ LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE,
+ REQUEST_FIRMWARE_LOAD, CPUCS_REG, 0, &reset_bit, 1,
+ ANGIE_USB_TIMEOUT_MS, NULL);
}
/**
- * Puts the ANGIE's EZ-USB microcontroller into reset state, downloads
- * the firmware image, resumes the microcontroller and re-enumerates
- * USB devices.
+ * Send one contiguous firmware section to the ANGIE's EZ-USB microcontroller
+ * over the USB bus.
*
- * @param device pointer to struct angie identifying ANGIE driver instance.
- * The usb_handle member will be modified during re-enumeration.
- * @param filename path to the Intel HEX file containing the firmware image.
- * @param delay_us the delay to wait for the device to re-enumerate.
- * @return on success: ERROR_OK
- * @return on failure: ERROR_FAIL
+ * @param device: Angie device pointer
+ * @param address: address of the firmware section
+ * @param data: pointer to the data to be sent
+ * @param size: size of the data
+ * @return ERROR_OK on success, negative error code otherwise
*/
-static int angie_load_firmware_and_renumerate(struct angie *device,
- const char *filename, uint32_t delay_us)
+static int angie_write_firmware_section(struct angie *device, uint16_t address,
+ uint8_t *data, size_t size)
{
- int ret;
+ int bytes_remaining = size;
- /* Basic process: After downloading the firmware, the ANGIE will disconnect
- * itself and re-connect after a short amount of time so we have to close
- * the handle and re-enumerate USB devices */
+ // Send section data in chunks of up to 64 bytes to ANGIE
+ while (bytes_remaining > 0) {
+ int chunk_size;
+ int transferred;
- ret = angie_load_firmware(device, filename);
- if (ret != ERROR_OK)
- return ret;
+ if (bytes_remaining > 64)
+ chunk_size = 64;
+ else
+ chunk_size = bytes_remaining;
- ret = angie_usb_close(device);
- if (ret != ERROR_OK)
- return ret;
+ int ret = jtag_libusb_control_transfer(device->usbdev,
+ LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE,
+ REQUEST_FIRMWARE_LOAD, address, FIRMWARE_ADDR, (char *)data,
+ chunk_size, ANGIE_USB_TIMEOUT_MS, &transferred);
- usleep(delay_us);
+ if (ret != ERROR_OK)
+ return ret;
- ret = angie_usb_open(device);
- if (ret != ERROR_OK)
- return ret;
+ if (transferred != chunk_size) {
+ // Abort if libusb sent less data than requested
+ return ERROR_FAIL;
+ }
- ret = libusb_claim_interface(angie_handle->usb_device_handle, 0);
- if (ret != LIBUSB_SUCCESS)
- return ERROR_FAIL;
+ bytes_remaining -= chunk_size;
+ address += chunk_size;
+ data += chunk_size;
+ }
return ERROR_OK;
}
@@ -358,18 +486,16 @@ static int angie_load_firmware_and_renumerate(struct angie *device,
* Downloads a firmware image to the ANGIE's EZ-USB microcontroller
* over the USB bus.
*
- * @param device pointer to struct angie identifying ANGIE driver instance.
- * @param filename an absolute or relative path to the Intel HEX file
+ * @param device: Angie device pointer
+ * @param filename: an absolute or relative path to the Intel HEX file
* containing the firmware image.
- * @return on success: ERROR_OK
- * @return on failure: ERROR_FAIL
+ * @return ERROR_OK on success, negative error code otherwise
*/
static int angie_load_firmware(struct angie *device, const char *filename)
{
struct image angie_firmware_image;
- int ret;
- ret = angie_cpu_reset(device, CPU_RESET);
+ int ret = angie_cpu_reset(device, CPU_RESET);
if (ret != ERROR_OK) {
LOG_ERROR("Could not halt ANGIE CPU");
return ret;
@@ -384,12 +510,34 @@ static int angie_load_firmware(struct angie *device, const char *filename)
return ret;
}
- /* Download all sections in the image to ANGIE */
+ uint8_t *data = malloc(ANGIE_FW_SECTION_SIZE);
+ if (!data) {
+ LOG_ERROR("Out of memory");
+ return ERROR_FAIL;
+ }
+
+ // Download all sections in the image to ANGIE
for (unsigned int i = 0; i < angie_firmware_image.num_sections; i++) {
- ret = angie_write_firmware_section(device, &angie_firmware_image, i);
+ size_t size_read;
+ uint32_t size = angie_firmware_image.sections[i].size;
+ int addr = angie_firmware_image.sections[i].base_address;
+
+ LOG_DEBUG("section %02i at addr 0x%04x (size 0x%04" PRIx32 ")",
+ i, addr, size);
+
+ ret = image_read_section(&angie_firmware_image, i, 0,
+ size, data, &size_read);
+ if (ret != ERROR_OK)
+ goto exit;
+ if (size_read != size) {
+ ret = ERROR_FAIL;
+ goto exit;
+ }
+
+ ret = angie_write_firmware_section(device, addr, data, size);
if (ret != ERROR_OK) {
LOG_ERROR("Could not write firmware section");
- return ret;
+ goto exit;
}
}
@@ -398,9 +546,52 @@ static int angie_load_firmware(struct angie *device, const char *filename)
ret = angie_cpu_reset(device, CPU_START);
if (ret != ERROR_OK) {
LOG_ERROR("Could not restart ANGIE CPU");
- return ret;
+ goto exit;
}
+exit:
+ free(data);
+ return ret;
+}
+
+/**
+ * Puts the ANGIE's EZ-USB microcontroller into reset state, downloads
+ * the firmware image, resumes the microcontroller and re-enumerates
+ * USB devices.
+ *
+ * @param device: Angie device pointer
+ * The usb_handle member will be modified during re-enumeration.
+ * @param filename: path to the Intel HEX file containing the firmware image.
+ * @param delay_us: the delay to wait for the device to re-enumerate.
+ * @return ERROR_OK on success, negative error code otherwise
+ */
+static int angie_load_firmware_and_renumerate(struct angie *device,
+ const char *filename,
+ uint32_t delay_us)
+{
+ /*
+ * Basic process: After downloading the firmware, the ANGIE will disconnect
+ * itself and re-connect after a short amount of time so we have to close
+ * the handle and re-enumerate USB devices.
+ */
+
+ int ret = angie_load_firmware(device, filename);
+ if (ret != ERROR_OK)
+ return ret;
+
+ ret = angie_usb_close(device);
+ if (ret != ERROR_OK)
+ return ret;
+
+ usleep(delay_us);
+
+ ret = angie_usb_open(device);
+ if (ret != ERROR_OK)
+ return ret;
+
+ if (libusb_claim_interface(angie_handle->usbdev, 0) != LIBUSB_SUCCESS)
+ return ERROR_FAIL;
+
return ERROR_OK;
}
@@ -408,1982 +599,766 @@ static int angie_load_firmware(struct angie *device, const char *filename)
* Downloads a bitstream file to the ANGIE's FPGA through the EZ-USB microcontroller
* over the USB bus.
*
- * @param device pointer to struct angie identifying ANGIE driver instance.
- * @param filename an absolute or relative path to the Xilinx .bit file
+ * @param device: Angie device pointer
+ * @param filename: an absolute or relative path to the Xilinx .bit file
* containing the bitstream data.
- * @return on success: ERROR_OK
- * @return on failure: ERROR_FAIL
+ * @return ERROR_OK on success, negative error code otherwise
*/
static int angie_load_bitstream(struct angie *device, const char *filename)
{
- int ret, transferred;
+ int ret = ERROR_OK, transferred;
const char *bitstream_file_path = filename;
FILE *bitstream_file = NULL;
char *bitstream_data = NULL;
- size_t bitstream_size = 0;
uint8_t gpifcnt[4];
- /* Open the bitstream file */
+ // Open the bitstream file
bitstream_file = fopen(bitstream_file_path, "rb");
if (!bitstream_file) {
LOG_ERROR("Failed to open bitstream file: %s\n", bitstream_file_path);
- return ERROR_FAIL;
+ ret = ERROR_FAIL;
+ goto exit;
}
- /* Get the size of the bitstream file */
+ // Get the size of the bitstream file
fseek(bitstream_file, 0, SEEK_END);
- bitstream_size = ftell(bitstream_file);
+ size_t bitstream_size = ftell(bitstream_file);
fseek(bitstream_file, 0, SEEK_SET);
- /* Allocate memory for the bitstream data */
+ // Allocate memory for the bitstream data
bitstream_data = malloc(bitstream_size);
if (!bitstream_data) {
LOG_ERROR("Failed to allocate memory for bitstream data.");
- fclose(bitstream_file);
- return ERROR_FAIL;
+ ret = ERROR_FAIL;
+ goto exit;
}
- /* Read the bitstream data from the file */
+ // Read the bitstream data from the file
if (fread(bitstream_data, 1, bitstream_size, bitstream_file) != bitstream_size) {
LOG_ERROR("Failed to read bitstream data.");
- free(bitstream_data);
- fclose(bitstream_file);
- return ERROR_FAIL;
+ ret = ERROR_FAIL;
+ goto exit;
}
+ // CFG Open
h_u32_to_be(gpifcnt, bitstream_size);
-
- /* CFGopen */
- ret = jtag_libusb_control_transfer(device->usb_device_handle,
- 0x00, 0xB0, 0, 0, (char *)gpifcnt, 4, LIBUSB_TIMEOUT_MS, &transferred);
+ ret = jtag_libusb_control_transfer(device->usbdev,
+ LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE,
+ VR_CFGOPEN, 0, 0, (char *)gpifcnt, sizeof(gpifcnt),
+ ANGIE_USB_TIMEOUT_MS, &transferred);
if (ret != ERROR_OK) {
LOG_ERROR("Failed opencfg");
- /* Abort if libusb sent less data than requested */
- return ERROR_FAIL;
+ goto exit;
}
- /* Send the bitstream data to the microcontroller */
+ // Send the bitstream data to the microcontroller
int actual_length = 0;
- ret = jtag_libusb_bulk_write(device->usb_device_handle, 0x02, bitstream_data, bitstream_size, 1000, &actual_length);
+ ret = jtag_libusb_bulk_write(device->usbdev, OUT_EP, bitstream_data,
+ bitstream_size, ANGIE_USB_TIMEOUT_MS, &actual_length);
if (ret != ERROR_OK) {
LOG_ERROR("Failed to send bitstream data: %s", libusb_strerror(ret));
- free(bitstream_data);
- fclose(bitstream_file);
- return ERROR_FAIL;
+ goto exit;
}
LOG_INFO("Bitstream sent successfully.");
- /* Clean up */
+exit:
free(bitstream_data);
- fclose(bitstream_file);
+ if (bitstream_file)
+ fclose(bitstream_file);
- /* CFGclose */
- transferred = 0;
- ret = jtag_libusb_control_transfer(device->usb_device_handle,
- 0x00, 0xB1, 0, 0, NULL, 0, LIBUSB_TIMEOUT_MS, &transferred);
- if (ret != ERROR_OK) {
- LOG_ERROR("Failed cfgclose");
- /* Abort if libusb sent less data than requested */
- return ERROR_FAIL;
- }
- return ERROR_OK;
+ return ret;
}
/**
- * Send an i2c write operation to dev-board components.
+ * Check if Angie firmware must be updated
*
- * @param device pointer to struct angie identifying ANGIE driver instance.
- * @param i2c_data table of i2c data that we want to write to slave device.
- * @param i2c_data_size the size of i2c data table.
- * @return on success: ERROR_OK
- * @return on failure: ERROR_FAIL
+ * @param device: Angie device pointer
+ * @return true if update is needed, false otherwise
*/
-static int angie_i2c_write(struct angie *device, uint8_t *i2c_data, uint8_t i2c_data_size)
+static bool angie_is_firmware_needed(struct angie *device)
{
- char i2c_data_buffer[i2c_data_size + 2];
- char buffer_received[1];
- int ret, transferred;
- i2c_data_buffer[0] = 0; // write = 0
- i2c_data_buffer[1] = i2c_data_size - 1; // i2c_data count (without address)
-
- for (uint8_t i = 0; i < i2c_data_size; i++)
- i2c_data_buffer[i + 2] = i2c_data[i];
-
- // Send i2c packet to Dev-board and configure its clock source /
- ret = jtag_libusb_bulk_write(device->usb_device_handle, 0x06, i2c_data_buffer,
- i2c_data_size + 2, 1000, &transferred);
- if (ret != ERROR_OK) {
- LOG_ERROR("Error in i2c clock gen configuration : ret ERROR");
- return ret;
- }
- if (transferred != i2c_data_size + 2) {
- LOG_ERROR("Error in i2c clock gen configuration : bytes transferred");
- return ERROR_FAIL;
- }
+ struct libusb_device_descriptor desc;
- usleep(500);
+ // Get String Descriptor to determine if firmware needs to be loaded
+ int ret = libusb_get_device_descriptor(libusb_get_device(angie_handle->usbdev),
+ &desc);
+ if (ret != LIBUSB_SUCCESS)
+ // Could not get descriptor -> Unconfigured or original Keil firmware
+ return true;
+ else if (desc.idProduct != ANGIE_PROG_OOCD_PID)
+ return true;
- // Receive packet from ANGIE /
- ret = jtag_libusb_bulk_write(device->usb_device_handle, 0x88, buffer_received, 1, 1000, &transferred);
- if (ret != ERROR_OK) {
- LOG_ERROR("Error in i2c clock gen configuration : ret ERROR");
- return ret;
+ return false;
+}
+
+/**
+ * Set TAP end state
+ *
+ * @param state
+ */
+static void angie_set_end_state(enum tap_state state)
+{
+ if (tap_is_state_stable(state)) {
+ tap_set_end_state(state);
+ } else {
+ LOG_ERROR("BUG: %i is not a valid end state", state);
+ exit(-1);
}
- return ERROR_OK;
}
/**
- * Configure dev-board gpio extender modules by configuring their
- * register 3 and register 1 responsible for IO directions and values.
+ * Move TAP to given state
*
- * @param device pointer to struct angie identifying ANGIE driver instance.
- * @param i2c_adr i2c address of the gpio extender.
- * @param cfg_value IOs configuration to be written in register Number 3.
- * @param value the IOs value to be written in register Number 1.
- * @return on success: ERROR_OK
- * @return on failure: ERROR_FAIL
+ * @param device: Angie device pointer
+ * @param skip: number of state to skip during move
+ * @return ERROR_OK on success, negative error code otherwise
*/
-static int angie_io_extender_config(struct angie *device, uint8_t i2c_adr, uint8_t cfg_value)
+static int angie_state_move(struct angie *device, int skip)
{
- uint8_t ioconfig[3] = {i2c_adr, 3, cfg_value};
- int ret = angie_i2c_write(device, ioconfig, 3);
+ int ret;
+ int tms = 0;
+ uint8_t tms_scan = tap_get_tms_path(tap_get_state(), tap_get_end_state());
+ int tms_count = tap_get_tms_path_len(tap_get_state(), tap_get_end_state());
+
+ // tms_scan has 8 bits that we bitbang one by one
+ for (int i = skip; i < tms_count; i++) {
+ tms = (tms_scan >> i) & 1;
+ ret = angie_buffer_append(device, 0, tms, 0);
+ if (ret != ERROR_OK)
+ return ret;
+ ret = angie_buffer_append(device, 1, tms, 0);
+ if (ret != ERROR_OK)
+ return ret;
+ }
+ ret = angie_buffer_append(device, 0, tms, 0);
if (ret != ERROR_OK)
return ret;
- usleep(500);
- return ret;
+ tap_set_state(tap_get_end_state());
+
+ return ERROR_OK;
}
/**
- * Send one contiguous firmware section to the ANGIE's EZ-USB microcontroller
- * over the USB bus.
+ * Return JTAG SCAN command size in bytes
*
- * @param device pointer to struct angie identifying ANGIE driver instance.
- * @param firmware_image pointer to the firmware image that contains the section
- * which should be sent to the ANGIE's EZ-USB microcontroller.
- * @param section_index index of the section within the firmware image.
- * @return on success: ERROR_OK
- * @return on failure: ERROR_FAIL
+ * @param device: Angie device pointer
+ * @param cmd: SCAN command
+ * @return size of command in the transfer buffer in bytes
*/
-static int angie_write_firmware_section(struct angie *device,
- struct image *firmware_image, int section_index)
+static int angie_jtag_scan_size(struct angie *device,
+ const struct scan_command *cmd)
{
- int addr, bytes_remaining, chunk_size;
- uint8_t data[SECTION_BUFFERSIZE];
- uint8_t *data_ptr = data;
- uint16_t size;
- size_t size_read;
- int ret, transferred;
+ int cmd_size = 0;
+ int count = 0;
- size = (uint16_t)firmware_image->sections[section_index].size;
- addr = (uint16_t)firmware_image->sections[section_index].base_address;
+ // move to TAP_IRSHIFT or TAP_DRSHIFT state
+ if (cmd->ir_scan)
+ count = tap_get_tms_path_len(tap_get_state(), TAP_IRSHIFT);
+ else
+ count = tap_get_tms_path_len(tap_get_state(), TAP_DRSHIFT);
+ cmd_size += count * 2 + 1;
+
+ // add scan size
+ cmd_size += jtag_scan_size(cmd) * 2;
+
+ /*
+ * move to cmd specified end state
+ * Also, see below function
+ * we *KNOW* the above loop transitioned out of
+ * the shift state, so we skip the first state
+ * and move directly to the end state.
+ */
+ if (cmd->ir_scan)
+ count = tap_get_tms_path_len(TAP_IRSHIFT, cmd->end_state) - 1;
+ else
+ count = tap_get_tms_path_len(TAP_DRSHIFT, cmd->end_state) - 1;
+ cmd_size += count * 2 + 1;
- LOG_DEBUG("section %02i at addr 0x%04x (size 0x%04" PRIx16 ")", section_index, addr,
- size);
+ return cmd_size;
+}
- /* Copy section contents to local buffer */
- ret = image_read_section(firmware_image, section_index, 0, size, data,
- &size_read);
+/**
+ * Execute JTAG SCAN command
+ *
+ * @param device: Angie device pointer
+ * @param cmd: SCAN command
+ * @return ERROR_OK on success, negative error code otherwise
+ */
+static int angie_jtag_execute_scan(struct angie *device,
+ const struct scan_command *cmd)
+{
+ uint8_t *buffer = NULL;
+ LOG_DEBUG_IO("SCAN: size=%d %s scan end in %s", jtag_scan_size(cmd),
+ (cmd->ir_scan) ? "IR" : "DR", tap_state_name(cmd->end_state));
+ if (cmd->ir_scan) {
+ if (tap_get_state() != TAP_IRSHIFT)
+ angie_set_end_state(TAP_IRSHIFT);
+ } else {
+ if (tap_get_state() != TAP_DRSHIFT)
+ angie_set_end_state(TAP_DRSHIFT);
+ }
+ int ret = angie_state_move(device, 0);
if (ret != ERROR_OK)
return ret;
- if (size_read != size)
- return ERROR_FAIL;
+ angie_set_end_state(cmd->end_state);
+
+ // Execute scan
+ int scan_size = jtag_build_buffer(cmd, &buffer);
+ enum scan_type type = jtag_scan_type(cmd);
+
+ // starting byte index
+ int start_offset = device->xfer_buffer_len;
+
+ // iterate over each bit in all scan data
+ int tms = 0;
+ int tdi = 0;
+ for (int i = 0; i < scan_size; i++) {
+ // calculate tms
+ // if we finish shifting tdi bits : '1' , else '0'
+ tms = (i == scan_size - 1) ? 1 : 0;
+ // calculate byte index
+ int bytec = i / 8;
+ // calculate bit mask: isolate the specific bit in corresponding byte
+ int bcval = 1 << (i % 8);
+ // if type is not SCAN_IN (not just reading data)
+ // and the bit masked is '1' then tdi = '1'
+ tdi = 0;
+ if (type != SCAN_IN && (buffer[bytec] & bcval))
+ tdi = 1;
+ // write tdi and tms twice in tck=0 and tck=1
+ ret = angie_buffer_append(device, 0, tms, tdi);
+ if (ret != ERROR_OK)
+ return ret;
+ ret = angie_buffer_append(device, 1, tms, tdi);
+ if (ret != ERROR_OK)
+ return ret;
+ }
- bytes_remaining = size;
+ angie_set_end_state(cmd->end_state);
+ if (tap_get_state() != tap_get_end_state()) {
+ /*
+ * We *KNOW* the above loop transitioned out of
+ * the shift state, so we skip the first state
+ * and move directly to the end state.
+ */
+ ret = angie_state_move(device, 1);
+ if (ret != ERROR_OK)
+ return ret;
+ }
- /* Send section data in chunks of up to 64 bytes to ANGIE */
- while (bytes_remaining > 0) {
- if (bytes_remaining > 64)
- chunk_size = 64;
- else
- chunk_size = bytes_remaining;
-
- ret = jtag_libusb_control_transfer(device->usb_device_handle,
- (LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE),
- REQUEST_FIRMWARE_LOAD, addr, FIRMWARE_ADDR, (char *)data_ptr,
- chunk_size, LIBUSB_TIMEOUT_MS, &transferred);
-
- if (ret != ERROR_OK)
- return ret;
-
- if (transferred != chunk_size) {
- /* Abort if libusb sent less data than requested */
+ if (jtag_scan_type(cmd) != SCAN_OUT) {
+ // queue read back buffer for further processing
+ struct read_queue_entry *entry = malloc(sizeof(*entry));
+ if (!entry) {
+ LOG_ERROR("Out of memory");
+ free(buffer);
return ERROR_FAIL;
}
- bytes_remaining -= chunk_size;
- addr += chunk_size;
- data_ptr += chunk_size;
- }
-
- return ERROR_OK;
-}
-
-/************************** Generic helper functions **************************/
-
-/**
- * Print state of interesting signals via LOG_INFO().
- *
- * @param input_signals input signal states as returned by CMD_GET_SIGNALS
- * @param output_signals output signal states as returned by CMD_GET_SIGNALS
- */
-static void angie_dump_signal_states(uint8_t input_signals, uint8_t output_signals)
-{
- LOG_INFO("ANGIE signal states: TDI: %i, TDO: %i, TMS: %i, TCK: %i, TRST: %i "
- "SRST: %i",
- (output_signals & SIGNAL_TDI ? 1 : 0),
- (input_signals & SIGNAL_TDO ? 1 : 0),
- (output_signals & SIGNAL_TMS ? 1 : 0),
- (output_signals & SIGNAL_TCK ? 1 : 0),
- (output_signals & SIGNAL_TRST ? 1 : 0),
- (output_signals & SIGNAL_SRST ? 1 : 0));
-}
-
-/**************** ANGIE command generation helper functions ***************/
-
-/**
- * Allocate and initialize space in memory for ANGIE command payload.
- *
- * @param angie_cmd pointer to command whose payload should be allocated.
- * @param size the amount of memory to allocate (bytes).
- * @param direction which payload to allocate.
- * @return on success: ERROR_OK
- * @return on failure: ERROR_FAIL
- */
-static int angie_allocate_payload(struct angie_cmd *angie_cmd, int size,
- enum angie_payload_direction direction)
-{
- uint8_t *payload;
-
- payload = calloc(size, sizeof(uint8_t));
-
- if (!payload) {
- LOG_ERROR("Could not allocate ANGIE command payload: out of memory");
- return ERROR_FAIL;
- }
-
- switch (direction) {
- case PAYLOAD_DIRECTION_OUT:
- if (angie_cmd->payload_out) {
- LOG_ERROR("BUG: Duplicate payload allocation for ANGIE command");
- free(payload);
- return ERROR_FAIL;
- }
- angie_cmd->payload_out = payload;
- angie_cmd->payload_out_size = size;
- break;
- case PAYLOAD_DIRECTION_IN:
- if (angie_cmd->payload_in_start) {
- LOG_ERROR("BUG: Duplicate payload allocation for ANGIE command");
- free(payload);
- return ERROR_FAIL;
- }
-
- angie_cmd->payload_in_start = payload;
- angie_cmd->payload_in = payload;
- angie_cmd->payload_in_size = size;
-
- /* By default, free payload_in_start in angie_clear_queue(). Commands
- * that do not want this behavior (e. g. split scans) must turn it off
- * separately! */
- angie_cmd->free_payload_in_start = true;
-
- break;
- }
-
- return ERROR_OK;
-}
-
-/****************** ANGIE command queue helper functions ******************/
-
-/**
- * Get the current number of bytes in the queue, including command IDs.
- *
- * @param device pointer to struct angie identifying ANGIE driver instance.
- * @param direction the transfer direction for which to get byte count.
- * @return the number of bytes currently stored in the queue for the specified
- * direction.
- */
-static int angie_get_queue_size(struct angie *device,
- enum angie_payload_direction direction)
-{
- struct angie_cmd *current = device->queue_start;
- int sum = 0;
-
- while (current) {
- switch (direction) {
- case PAYLOAD_DIRECTION_OUT:
- sum += current->payload_out_size + 1; /* + 1 byte for Command ID */
- break;
- case PAYLOAD_DIRECTION_IN:
- sum += current->payload_in_size;
- break;
- }
-
- current = current->next;
- }
-
- return sum;
-}
-
-/**
- * Clear the ANGIE command queue.
- *
- * @param device pointer to struct angie identifying ANGIE driver instance.
- */
-static void angie_clear_queue(struct angie *device)
-{
- struct angie_cmd *current = device->queue_start;
- struct angie_cmd *next = NULL;
-
- while (current) {
- /* Save pointer to next element */
- next = current->next;
-
- /* Free payloads: OUT payload can be freed immediately */
- free(current->payload_out);
- current->payload_out = NULL;
-
- /* IN payload MUST be freed ONLY if no other commands use the
- * payload_in_start buffer */
- if (current->free_payload_in_start) {
- free(current->payload_in_start);
- current->payload_in_start = NULL;
- current->payload_in = NULL;
- }
-
- /* Free queue element */
- free(current);
-
- /* Proceed with next element */
- current = next;
- }
-
- device->commands_in_queue = 0;
- device->queue_start = NULL;
- device->queue_end = NULL;
-}
-
-/**
- * Add a command to the ANGIE command queue.
- *
- * @param device pointer to struct angie identifying ANGIE driver instance.
- * @param angie_cmd pointer to command that shall be appended to the ANGIE
- * command queue.
- * @return on success: ERROR_OK
- * @return on failure: ERROR_FAIL
- */
-static int angie_append_queue(struct angie *device, struct angie_cmd *angie_cmd)
-{
- int newsize_out, newsize_in;
- int ret = ERROR_OK;
-
- newsize_out = angie_get_queue_size(device, PAYLOAD_DIRECTION_OUT) + 1
- + angie_cmd->payload_out_size;
-
- newsize_in = angie_get_queue_size(device, PAYLOAD_DIRECTION_IN)
- + angie_cmd->payload_in_size;
-
- /* Check if the current command can be appended to the queue */
- if (newsize_out > 64 || newsize_in > 64) {
- /* New command does not fit. Execute all commands in queue before starting
- * new queue with the current command as first entry. */
- ret = angie_execute_queued_commands(device, LIBUSB_TIMEOUT_MS);
-
- if (ret == ERROR_OK)
- ret = angie_post_process_queue(device);
-
- if (ret == ERROR_OK)
- angie_clear_queue(device);
- }
-
- if (!device->queue_start) {
- /* Queue was empty */
- device->commands_in_queue = 1;
-
- device->queue_start = angie_cmd;
- device->queue_end = angie_cmd;
- } else {
- /* There are already commands in the queue */
- device->commands_in_queue++;
-
- device->queue_end->next = angie_cmd;
- device->queue_end = angie_cmd;
- }
-
- if (ret != ERROR_OK)
- angie_clear_queue(device);
-
- return ret;
-}
-
-/**
- * Sends all queued ANGIE commands to the ANGIE for execution.
- *
- * @param device pointer to struct angie identifying ANGIE driver instance.
- * @param timeout_ms
- * @return on success: ERROR_OK
- * @return on failure: ERROR_FAIL
- */
-static int angie_execute_queued_commands(struct angie *device, int timeout_ms)
-{
- struct angie_cmd *current;
- int ret, i, index_out, index_in, count_out, count_in, transferred;
- uint8_t buffer[64];
-
- if (LOG_LEVEL_IS(LOG_LVL_DEBUG_IO))
- angie_dump_queue(device);
-
- index_out = 0;
- count_out = 0;
- count_in = 0;
-
- for (current = device->queue_start; current; current = current->next) {
- /* Add command to packet */
- buffer[index_out] = current->id;
- index_out++;
- count_out++;
-
- for (i = 0; i < current->payload_out_size; i++)
- buffer[index_out + i] = current->payload_out[i];
- index_out += current->payload_out_size;
- count_in += current->payload_in_size;
- count_out += current->payload_out_size;
- }
-
- /* Send packet to ANGIE */
- ret = jtag_libusb_bulk_write(device->usb_device_handle, device->ep_out,
- (char *)buffer, count_out, timeout_ms, &transferred);
- if (ret != ERROR_OK) {
- LOG_ERROR("Libusb bulk write queued commands failed.");
- return ret;
- }
- if (transferred != count_out) {
- LOG_ERROR("Libusb bulk write queued commands failed: transferred byte count");
- return ERROR_FAIL;
- }
-
- /* Wait for response if commands contain IN payload data */
- if (count_in > 0) {
- ret = jtag_libusb_bulk_write(device->usb_device_handle, device->ep_in,
- (char *)buffer, count_in, timeout_ms, &transferred);
- if (ret != ERROR_OK) {
- LOG_ERROR("Libusb bulk write input payload data failed");
- return ret;
- }
- if (transferred != count_in) {
- LOG_ERROR("Libusb bulk write input payload data failed: transferred byte count");
- return ERROR_FAIL;
- }
-
- /* Write back IN payload data */
- index_in = 0;
- for (current = device->queue_start; current; current = current->next) {
- for (i = 0; i < current->payload_in_size; i++) {
- current->payload_in[i] = buffer[index_in];
- index_in++;
- }
- }
- }
- return ERROR_OK;
-}
-
-/**
- * Convert an ANGIE command ID (\a id) to a human-readable string.
- *
- * @param id the ANGIE command ID.
- * @return the corresponding human-readable string.
- */
-static const char *angie_cmd_id_string(uint8_t id)
-{
- switch (id) {
- case CMD_SCAN_IN:
- return "CMD_SCAN_IN";
- case CMD_SLOW_SCAN_IN:
- return "CMD_SLOW_SCAN_IN";
- case CMD_SCAN_OUT:
- return "CMD_SCAN_OUT";
- case CMD_SLOW_SCAN_OUT:
- return "CMD_SLOW_SCAN_OUT";
- case CMD_SCAN_IO:
- return "CMD_SCAN_IO";
- case CMD_SLOW_SCAN_IO:
- return "CMD_SLOW_SCAN_IO";
- case CMD_CLOCK_TMS:
- return "CMD_CLOCK_TMS";
- case CMD_SLOW_CLOCK_TMS:
- return "CMD_SLOW_CLOCK_TMS";
- case CMD_CLOCK_TCK:
- return "CMD_CLOCK_TCK";
- case CMD_SLOW_CLOCK_TCK:
- return "CMD_SLOW_CLOCK_TCK";
- case CMD_SLEEP_US:
- return "CMD_SLEEP_US";
- case CMD_SLEEP_MS:
- return "CMD_SLEEP_MS";
- case CMD_GET_SIGNALS:
- return "CMD_GET_SIGNALS";
- case CMD_SET_SIGNALS:
- return "CMD_SET_SIGNALS";
- case CMD_CONFIGURE_TCK_FREQ:
- return "CMD_CONFIGURE_TCK_FREQ";
- case CMD_SET_LEDS:
- return "CMD_SET_LEDS";
- case CMD_TEST:
- return "CMD_TEST";
- default:
- return "CMD_UNKNOWN";
- }
-}
-
-/**
- * Print one ANGIE command to stdout.
- *
- * @param angie_cmd pointer to ANGIE command.
- */
-static void angie_dump_command(struct angie_cmd *angie_cmd)
-{
- char hex[64 * 3];
- for (int i = 0; i < angie_cmd->payload_out_size; i++)
- sprintf(hex + 3 * i, "%02" PRIX8 " ", angie_cmd->payload_out[i]);
-
- hex[3 * angie_cmd->payload_out_size - 1] = 0;
- LOG_DEBUG_IO(" %-22s | OUT size = %" PRIi8 ", bytes = %s",
- angie_cmd_id_string(angie_cmd->id), angie_cmd->payload_out_size, hex);
-
- LOG_DEBUG_IO("\n | IN size = %" PRIi8 "\n", angie_cmd->payload_in_size);
-}
-
-/**
- * Print the ANGIE command queue to stdout.
- *
- * @param device pointer to struct angie identifying ANGIE driver instance.
- */
-static void angie_dump_queue(struct angie *device)
-{
- struct angie_cmd *current;
-
- LOG_DEBUG_IO("ANGIE command queue:\n");
-
- for (current = device->queue_start; current; current = current->next)
- angie_dump_command(current);
-}
-
-/**
- * Perform JTAG scan
- *
- * Creates and appends a JTAG scan command to the ANGIE command queue.
- * A JTAG scan consists of three steps:
- * - Move to the desired SHIFT state, depending on scan type (IR/DR scan).
- * - Shift TDI data into the JTAG chain, optionally reading the TDO pin.
- * - Move to the desired end state.
- *
- * @param device pointer to struct angie identifying ANGIE driver instance.
- * @param scan_type the type of the scan (IN, OUT, IO (bidirectional)).
- * @param scan_size_bits number of bits to shift into the JTAG chain.
- * @param tdi pointer to array containing TDI data.
- * @param tdo_start pointer to first element of array where TDO data shall be
- * stored. See #angie_cmd for details.
- * @param tdo pointer to array where TDO data shall be stored
- * @param tms_count_start number of TMS state transitions to perform BEFORE
- * shifting data into the JTAG chain.
- * @param tms_sequence_start sequence of TMS state transitions that will be
- * performed BEFORE shifting data into the JTAG chain.
- * @param tms_count_end number of TMS state transitions to perform AFTER
- * shifting data into the JTAG chain.
- * @param tms_sequence_end sequence of TMS state transitions that will be
- * performed AFTER shifting data into the JTAG chain.
- * @param origin pointer to OpenOCD command that generated this scan command.
- * @param postprocess whether this command needs to be post-processed after
- * execution.
- * @return on success: ERROR_OK
- * @return on failure: ERROR_FAIL
- */
-static int angie_append_scan_cmd(struct angie *device, enum scan_type scan_type,
- int scan_size_bits, uint8_t *tdi, uint8_t *tdo_start, uint8_t *tdo,
- uint8_t tms_count_start, uint8_t tms_sequence_start, uint8_t tms_count_end,
- uint8_t tms_sequence_end, struct jtag_command *origin, bool postprocess)
-{
- struct angie_cmd *cmd = calloc(1, sizeof(struct angie_cmd));
- int ret, i, scan_size_bytes;
- uint8_t bits_last_byte;
-
- if (!cmd)
- return ERROR_FAIL;
-
- /* Check size of command. USB buffer can hold 64 bytes, 1 byte is command ID,
- * 5 bytes are setup data -> 58 remaining payload bytes for TDI data */
- if (scan_size_bits > (58 * 8)) {
- LOG_ERROR("BUG: Tried to create CMD_SCAN_IO ANGIE command with too"
- " large payload");
- free(cmd);
- return ERROR_FAIL;
- }
-
- scan_size_bytes = DIV_ROUND_UP(scan_size_bits, 8);
-
- bits_last_byte = scan_size_bits % 8;
- if (bits_last_byte == 0)
- bits_last_byte = 8;
-
- /* Allocate out_payload depending on scan type */
- switch (scan_type) {
- case SCAN_IN:
- if (device->delay_scan_in < 0)
- cmd->id = CMD_SCAN_IN;
- else
- cmd->id = CMD_SLOW_SCAN_IN;
- ret = angie_allocate_payload(cmd, 5, PAYLOAD_DIRECTION_IN);
- break;
- case SCAN_OUT:
- if (device->delay_scan_out < 0)
- cmd->id = CMD_SCAN_OUT;
- else
- cmd->id = CMD_SLOW_SCAN_OUT;
- ret = angie_allocate_payload(cmd, scan_size_bytes + 5, PAYLOAD_DIRECTION_OUT);
- break;
- case SCAN_IO:
- if (device->delay_scan_io < 0)
- cmd->id = CMD_SCAN_IO;
- else
- cmd->id = CMD_SLOW_SCAN_IO;
- ret = angie_allocate_payload(cmd, scan_size_bytes + 5, PAYLOAD_DIRECTION_OUT);
- break;
- default:
- LOG_ERROR("BUG: 'append scan cmd' encountered an unknown scan type");
- ret = ERROR_FAIL;
- break;
- }
-
- if (ret != ERROR_OK) {
- free(cmd);
- return ret;
- }
-
- /* Build payload_out that is common to all scan types */
- cmd->payload_out[0] = scan_size_bytes & 0xFF;
- cmd->payload_out[1] = bits_last_byte & 0xFF;
- cmd->payload_out[2] = ((tms_count_start & 0x0F) << 4) | (tms_count_end & 0x0F);
- cmd->payload_out[3] = tms_sequence_start;
- cmd->payload_out[4] = tms_sequence_end;
-
- /* Setup payload_out for types with OUT transfer */
- if (scan_type == SCAN_OUT || scan_type == SCAN_IO) {
- for (i = 0; i < scan_size_bytes; i++)
- cmd->payload_out[i + 5] = tdi[i];
- }
-
- /* Setup payload_in pointers for types with IN transfer */
- if (scan_type == SCAN_IN || scan_type == SCAN_IO) {
- cmd->payload_in_start = tdo_start;
- cmd->payload_in = tdo;
- cmd->payload_in_size = scan_size_bytes;
- }
-
- cmd->needs_postprocessing = postprocess;
- cmd->cmd_origin = origin;
-
- /* For scan commands, we free payload_in_start only when the command is
- * the last in a series of split commands or a stand-alone command */
- cmd->free_payload_in_start = postprocess;
-
- return angie_append_queue(device, cmd);
-}
-
-/**
- * Perform TAP state transitions
- *
- * @param device pointer to struct angie identifying ANGIE driver instance.
- * @param count defines the number of TCK clock cycles generated (up to 8).
- * @param sequence defines the TMS pin levels for each state transition. The
- * Least-Significant Bit is read first.
- * @return on success: ERROR_OK
- * @return on failure: ERROR_FAIL
- */
-static int angie_append_clock_tms_cmd(struct angie *device, uint8_t count,
- uint8_t sequence)
-{
- struct angie_cmd *cmd = calloc(1, sizeof(struct angie_cmd));
- int ret;
-
- if (!cmd) {
- LOG_ERROR("Out of memory");
- return ERROR_FAIL;
- }
-
- if (device->delay_clock_tms < 0)
- cmd->id = CMD_CLOCK_TMS;
- else
- cmd->id = CMD_SLOW_CLOCK_TMS;
-
- /* CMD_CLOCK_TMS has two OUT payload bytes and zero IN payload bytes */
- ret = angie_allocate_payload(cmd, 2, PAYLOAD_DIRECTION_OUT);
- if (ret != ERROR_OK) {
- free(cmd);
- return ret;
- }
-
- cmd->payload_out[0] = count;
- cmd->payload_out[1] = sequence;
-
- return angie_append_queue(device, cmd);
-}
-
-/**
- * Generate a defined amount of TCK clock cycles
- *
- * All other JTAG signals are left unchanged.
- *
- * @param device pointer to struct angie identifying ANGIE driver instance.
- * @param count the number of TCK clock cycles to generate.
- * @return on success: ERROR_OK
- * @return on failure: ERROR_FAIL
- */
-static int angie_append_clock_tck_cmd(struct angie *device, uint16_t count)
-{
- struct angie_cmd *cmd = calloc(1, sizeof(struct angie_cmd));
- int ret;
-
- if (!cmd) {
- LOG_ERROR("Out of memory");
- return ERROR_FAIL;
- }
-
- if (device->delay_clock_tck < 0)
- cmd->id = CMD_CLOCK_TCK;
- else
- cmd->id = CMD_SLOW_CLOCK_TCK;
-
- /* CMD_CLOCK_TCK has two OUT payload bytes and zero IN payload bytes */
- ret = angie_allocate_payload(cmd, 2, PAYLOAD_DIRECTION_OUT);
- if (ret != ERROR_OK) {
- free(cmd);
- return ret;
- }
-
- cmd->payload_out[0] = count & 0xff;
- cmd->payload_out[1] = (count >> 8) & 0xff;
-
- return angie_append_queue(device, cmd);
-}
-
-/**
- * Read JTAG signals.
- *
- * @param device pointer to struct angie identifying ANGIE driver instance.
- * @return on success: ERROR_OK
- * @return on failure: ERROR_FAIL
- */
-...
[truncated message content] |
|
From: openocd-gerrit <ope...@us...> - 2025-08-17 13:40:20
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Main OpenOCD repository".
The branch, master has been updated
via c132aed2a611a16f4759626123ab78e446a737ce (commit)
from 18d5ea95e59e83ebee8379f0de459d2f8f0482f4 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit c132aed2a611a16f4759626123ab78e446a737ce
Author: Ahmed BOUDJELIDA <abo...@na...>
Date: Wed Apr 23 17:42:33 2025 +0200
contrib/firmware/angie: deactivate srst signal in bitstream
angie probe doesn't use srst pin anymore, it was removed in
latest version.
Change-Id: I6b1439f2328770e5b525c3d129afd08bddf42025
Signed-off-by: Ahmed BOUDJELIDA <abo...@na...>
Reviewed-on: https://review.openocd.org/c/openocd/+/8859
Tested-by: jenkins
Reviewed-by: Antonio Borneo <bor...@gm...>
diff --git a/contrib/firmware/angie/hdl/src/angie_bitstream.vhd b/contrib/firmware/angie/hdl/src/angie_bitstream.vhd
index a1b86862d..737a84ce5 100644
--- a/contrib/firmware/angie/hdl/src/angie_bitstream.vhd
+++ b/contrib/firmware/angie/hdl/src/angie_bitstream.vhd
@@ -75,7 +75,6 @@ signal trst_clk, trst_rst, trst_d, trst_q : std_logic;
signal tms_clk, tms_rst, tms_d, tms_q : std_logic;
signal tdi_clk, tdi_rst, tdi_d, tdi_q : std_logic;
signal tdo_clk, tdo_rst, tdo_d, tdo_q : std_logic;
-signal srst_clk, srst_rst, srst_d, srst_q : std_logic;
----------------------------------------clk_div
signal clk_div_in, clk_div_out, reset_clk_div : std_logic;
@@ -188,14 +187,6 @@ port map (
q => tdo_q
);
-DFF_inst_SRST : DFF
-port map (
- clk => srst_clk,
- reset => srst_rst,
- d => srst_d,
- q => srst_q
-);
-
-- Instantiate the FIFO OUT
U0 : fifo_generator_v9_3
port map (
@@ -233,7 +224,6 @@ trst_clk <= IFCLK_I;
tms_clk <= IFCLK_I;
tdi_clk <= IFCLK_I;
tdo_clk <= IFCLK_I;
-srst_clk <= IFCLK_I;
--------------- FIFOs
clk_wr_o <= IFCLK_I;
@@ -308,7 +298,6 @@ begin
tms_rst <= '1';
tdi_rst <= '1';
tdo_rst <= '1';
- srst_rst <= '1';
else
reset_mae <= '0'; -- No Reset State Machine
reset_mae2 <= '0'; -- Reset State Machine
@@ -320,7 +309,6 @@ begin
tms_rst <= '0';
tdi_rst <= '0';
tdo_rst <= '0';
- srst_rst <= '0';
end if;
end process;
@@ -419,8 +407,7 @@ ST_0_O <= '0';
-- TDO : in
ST_1_O <= '1';
-- SRST : out
-ST_2_O <= srst_q;
-srst_d <= data_out_o(6);
+ST_2_O <= '1';
SO_SRST_O <= '0';
-- MOD : in
ST_3_O <= '1';
diff --git a/src/jtag/drivers/angie/angie_bitstream.bit b/src/jtag/drivers/angie/angie_bitstream.bit
index fb1c73497..71fbb85e6 100644
Binary files a/src/jtag/drivers/angie/angie_bitstream.bit and b/src/jtag/drivers/angie/angie_bitstream.bit differ
-----------------------------------------------------------------------
Summary of changes:
contrib/firmware/angie/hdl/src/angie_bitstream.vhd | 15 +--------------
src/jtag/drivers/angie/angie_bitstream.bit | Bin 340721 -> 341277 bytes
2 files changed, 1 insertion(+), 14 deletions(-)
hooks/post-receive
--
Main OpenOCD repository
|
|
From: openocd-gerrit <ope...@us...> - 2025-08-17 13:38:02
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Main OpenOCD repository".
The branch, master has been updated
via 18d5ea95e59e83ebee8379f0de459d2f8f0482f4 (commit)
from 9a150e326a655c9bd2fbead1be43748ca640764c (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 18d5ea95e59e83ebee8379f0de459d2f8f0482f4
Author: Ahmed BOUDJELIDA <abo...@na...>
Date: Wed Jan 15 16:44:28 2025 +0100
contrib/firmware/angie: correct usb descriptor issues
Correct the issue of usb descriptor does not appear
near the PID and VID, Cypress USB controller cannot
handle direct pointers to memory CODE area, so we
copy the data in the external RAM area and point
to it.
Change-Id: I3221627dc8576f6341b444acd9c554fd5cc47918
Signed-off-by: Ahmed BOUDJELIDA <abo...@na...>
Reviewed-on: https://review.openocd.org/c/openocd/+/8736
Tested-by: jenkins
Reviewed-by: Antonio Borneo <bor...@gm...>
diff --git a/contrib/firmware/angie/c/include/usb.h b/contrib/firmware/angie/c/include/usb.h
index 37d3b8ae2..dbf41fe8e 100644
--- a/contrib/firmware/angie/c/include/usb.h
+++ b/contrib/firmware/angie/c/include/usb.h
@@ -104,7 +104,7 @@ struct usb_endpoint_descriptor {
struct usb_language_descriptor {
uint8_t blength; /**< Size of this descriptor in bytes. */
uint8_t bdescriptortype; /**< STRING descriptor type. */
- uint16_t wlangid[]; /**< LANGID codes. */
+ uint16_t wlangid; /**< LANGID codes. */
};
/** USB String Descriptor. See USB 2.0 Spec */
diff --git a/contrib/firmware/angie/c/src/usb.c b/contrib/firmware/angie/c/src/usb.c
index 9b48e8353..6a07cc5d3 100644
--- a/contrib/firmware/angie/c/src/usb.c
+++ b/contrib/firmware/angie/c/src/usb.c
@@ -19,6 +19,7 @@
#include "i2c.h"
#include <stdint.h>
#include <stdio.h>
+#include <string.h>
// #define PRINTF_DEBUG
@@ -122,7 +123,7 @@ __code struct usb_endpoint_descriptor bulk_ep8_in_endpoint_descriptor = {
__code struct usb_language_descriptor language_descriptor = {
.blength = 4,
.bdescriptortype = DESCRIPTOR_TYPE_STRING,
- .wlangid = {0x0409} /* US English */
+ .wlangid = 0x0409 /* US English */
};
__code struct usb_string_descriptor strmanufacturer =
@@ -134,15 +135,11 @@ __code struct usb_string_descriptor strproduct =
__code struct usb_string_descriptor strserialnumber =
STR_DESCR(6, '0', '0', '0', '0', '0', '1');
-__code struct usb_string_descriptor strconfigdescr =
- STR_DESCR(12, 'J', 'T', 'A', 'G', ' ', 'A', 'd', 'a', 'p', 't', 'e', 'r');
-
/* Table containing pointers to string descriptors */
-__code struct usb_string_descriptor *__code en_string_descriptors[4] = {
+__code struct usb_string_descriptor *__code en_string_descriptors[3] = {
&strmanufacturer,
&strproduct,
- &strserialnumber,
- &strconfigdescr
+ &strserialnumber
};
void sudav_isr(void)__interrupt SUDAV_ISR
{
@@ -196,7 +193,6 @@ void ep6_isr(void)__interrupt EP6_ISR
i2c_recieve(); /* Execute I2C communication */
EXIF &= ~0x10; /* Clear USBINT: Main global interrupt */
EPIRQ = 0x40; /* Clear individual EP6OUT IRQ */
- REVCTL = 0x3; /* REVCTL.0 and REVCTL.1 set to 1 */
}
void ep8_isr(void)__interrupt EP8_ISR
{
@@ -328,63 +324,6 @@ void usb_reset_data_toggle(uint8_t ep)
TOGCTL |= BMRESETTOGGLE;
}
-/**
- * Handle GET_STATUS request.
- *
- * @return on success: true
- * @return on failure: false
- */
-bool usb_handle_get_status(void)
-{
- uint8_t *ep_cs;
- switch (setup_data.bmrequesttype) {
- case GS_DEVICE:
- /* Two byte response: Byte 0, Bit 0 = self-powered, Bit 1 = remote wakeup.
- * Byte 1: reserved, reset to zero */
- EP0BUF[0] = 0;
- EP0BUF[1] = 0;
-
- /* Send response */
- EP0BCH = 0;
- syncdelay(3);
- EP0BCL = 2;
- syncdelay(3);
- break;
- case GS_INTERFACE:
- /* Always return two zero bytes according to USB 1.1 spec, p. 191 */
- EP0BUF[0] = 0;
- EP0BUF[1] = 0;
-
- /* Send response */
- EP0BCH = 0;
- syncdelay(3);
- EP0BCL = 2;
- syncdelay(3);
- break;
- case GS_ENDPOINT:
- /* Get stall bit for endpoint specified in low byte of wIndex */
- ep_cs = usb_get_endpoint_cs_reg(setup_data.windex & 0xff);
-
- if (*ep_cs & EPSTALL)
- EP0BUF[0] = 0x01;
- else
- EP0BUF[0] = 0x00;
-
- /* Second byte sent has to be always zero */
- EP0BUF[1] = 0;
-
- /* Send response */
- EP0BCH = 0;
- syncdelay(3);
- EP0BCL = 2;
- syncdelay(3);
- break;
- default:
- return false;
- }
- return true;
-}
-
/**
* Handle CLEAR_FEATURE request.
*
@@ -480,12 +419,17 @@ bool usb_handle_get_descriptor(void)
case DESCRIPTOR_TYPE_STRING:
if (setup_data.windex == 0) {
/* Supply language descriptor */
- SUDPTRH = HI8(&language_descriptor);
- SUDPTRL = LO8(&language_descriptor);
+ __xdata struct usb_language_descriptor temp_descriptor;
+ memcpy(&temp_descriptor, &language_descriptor, sizeof(language_descriptor));
+ SUDPTRH = HI8(&temp_descriptor);
+ SUDPTRL = LO8(&temp_descriptor);
} else if (setup_data.windex == 0x0409 /* US English */) {
/* Supply string descriptor */
- SUDPTRH = HI8(en_string_descriptors[descriptor_index - 1]);
- SUDPTRL = LO8(en_string_descriptors[descriptor_index - 1]);
+ __xdata uint8_t temp_descriptors[3];
+ memcpy(temp_descriptors, en_string_descriptors[descriptor_index - 1],
+ ((struct usb_string_descriptor *)en_string_descriptors[descriptor_index - 1])->blength);
+ SUDPTRH = HI8(temp_descriptors);
+ SUDPTRL = LO8(temp_descriptors);
} else {
return false;
}
@@ -610,6 +554,8 @@ bool usb_handle_vcommands(void)
; /* wait to finish transferring in EP0BUF, until not busy */
gcnt = ((uint32_t)(eptr[0]) << 24) | ((uint32_t)(eptr[1]) << 16)
| ((uint32_t)(eptr[2]) << 8) | (uint32_t)(eptr[3]);
+ /* REVCTL.0 and REVCTL.1 set to 1 */
+ REVCTL = 0x3;
/* Angie board FPGA bitstream download */
PIN_RDWR_B = 0;
/* Initialize GPIF interface transfer count */
@@ -632,6 +578,10 @@ bool usb_handle_vcommands(void)
EP4AUTOINLENL = (uint8_t)((uint32_t)(gcnt) & 0x000000ff);
/* Trigger GPIF IN transfer on EP4 */
GPIFTRIG = BMGPIFREAD | GPIF_EP4;
+ while (!(GPIFTRIG & BMGPIFDONE)) // poll GPIFTRIG.7 GPIF Done bit
+ ;
+ /* REVCTL.0 and REVCTL.1 set to 0 */
+ REVCTL = 0;
break;
default:
return true; /* Error: unknown VR command */
@@ -646,8 +596,12 @@ void usb_handle_setup_data(void)
{
switch (setup_data.brequest) {
case GET_STATUS:
- if (!usb_handle_get_status())
- STALL_EP0();
+ EP0BUF[0] = 0;
+ EP0BUF[1] = 0;
+ /* Send response */
+ EP0BCH = 0;
+ EP0BCL = 2;
+ syncdelay(3);
break;
case CLEAR_FEATURE:
if (!usb_handle_clear_feature())
@@ -880,7 +834,9 @@ void interrupt_init(void)
/* Clear SUDAV interrupt */
USBIRQ = SUDAVI;
- /* Enable Interrupts */
+ /* Enable Interrupts (Do not confuse this with
+ * EA External Access pin, see ANGIE Schematic)
+ */
EA = 1;
}
diff --git a/src/jtag/drivers/angie/angie_firmware.bin b/src/jtag/drivers/angie/angie_firmware.bin
index 6ba2babb1..ecf2cfd51 100644
Binary files a/src/jtag/drivers/angie/angie_firmware.bin and b/src/jtag/drivers/angie/angie_firmware.bin differ
-----------------------------------------------------------------------
Summary of changes:
contrib/firmware/angie/c/include/usb.h | 2 +-
contrib/firmware/angie/c/src/usb.c | 100 +++++++++---------------------
src/jtag/drivers/angie/angie_firmware.bin | Bin 4487 -> 4478 bytes
3 files changed, 29 insertions(+), 73 deletions(-)
hooks/post-receive
--
Main OpenOCD repository
|
|
From: openocd-gerrit <ope...@us...> - 2025-08-17 13:37:46
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Main OpenOCD repository".
The branch, master has been updated
via 9a150e326a655c9bd2fbead1be43748ca640764c (commit)
from ceaa47a2aa86ac476400683f3d78519f1ea79d5a (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 9a150e326a655c9bd2fbead1be43748ca640764c
Author: Ahmed BOUDJELIDA <abo...@na...>
Date: Thu Dec 12 10:27:14 2024 +0100
contrib/firmware/angie: add dev-board power detection
Add a check if i2c SDA pin state is HIGH.
if its HIGH, the dev-board is ON, we receive
number of Ack.
in its LOW, the board is OFF, we send this
information back to driver.
Change-Id: Ia40d3910675cc10e0208d8bc0060a19c12b1409d
Signed-off-by: Ahmed BOUDJELIDA <abo...@na...>
Reviewed-on: https://review.openocd.org/c/openocd/+/8716
Tested-by: jenkins
Reviewed-by: Antonio Borneo <bor...@gm...>
diff --git a/contrib/firmware/angie/c/include/i2c.h b/contrib/firmware/angie/c/include/i2c.h
index d0404923b..7a199c15a 100644
--- a/contrib/firmware/angie/c/include/i2c.h
+++ b/contrib/firmware/angie/c/include/i2c.h
@@ -14,6 +14,7 @@
#include <stdint.h>
#include <stdio.h>
+bool get_status(void);
void start_cd(void);
void repeated_start(void);
void stop_cd(void);
diff --git a/contrib/firmware/angie/c/src/i2c.c b/contrib/firmware/angie/c/src/i2c.c
index 9aadc2c25..4cf82955f 100644
--- a/contrib/firmware/angie/c/src/i2c.c
+++ b/contrib/firmware/angie/c/src/i2c.c
@@ -12,6 +12,19 @@
#include "delay.h"
#include "reg_ezusb.h"
+bool get_status(void)
+{
+ PIN_SDA_DIR = 1;
+ OEA = 0xF7;
+ delay_us(1);
+ bool sda_state = PIN_SDA;
+ PIN_T0 = sda_state;
+ delay_us(1);
+ OEA = 0xFF;
+ delay_us(1);
+ return sda_state;
+}
+
void start_cd(void)
{
PIN_SDA_DIR = 0; // SP6 SDA: OUT
diff --git a/contrib/firmware/angie/c/src/main.c b/contrib/firmware/angie/c/src/main.c
index 042a1eca7..657694b6c 100644
--- a/contrib/firmware/angie/c/src/main.c
+++ b/contrib/firmware/angie/c/src/main.c
@@ -11,9 +11,9 @@
*****************************************************************************/
#include "usb.h"
+#include "serial.h"
#include "delay.h"
#include "reg_ezusb.h"
-#include <serial.h>
#include <stdio.h>
extern void sudav_isr(void)__interrupt SUDAV_ISR;
diff --git a/contrib/firmware/angie/c/src/usb.c b/contrib/firmware/angie/c/src/usb.c
index f3bc99ba1..9b48e8353 100644
--- a/contrib/firmware/angie/c/src/usb.c
+++ b/contrib/firmware/angie/c/src/usb.c
@@ -55,7 +55,7 @@ __code struct usb_config_descriptor config_descriptor = {
((NUM_ENDPOINTS * 2) * sizeof(struct usb_endpoint_descriptor)),
.bnuminterfaces = 2,
.bconfigurationvalue = 1,
- .iconfiguration = 4, /* String describing this configuration */
+ .iconfiguration = 2, /* String describing this configuration */
.bmattributes = 0x80, /* Only MSB set according to USB spec */
.maxpower = 50 /* 100 mA */
};
@@ -69,7 +69,7 @@ __code struct usb_interface_descriptor interface_descriptor00 = {
.binterfaceclass = 0XFF,
.binterfacesubclass = 0x00,
.binterfaceprotocol = 0x00,
- .iinterface = 5
+ .iinterface = 0
};
__code struct usb_endpoint_descriptor bulk_ep2_endpoint_descriptor = {
@@ -99,7 +99,7 @@ __code struct usb_interface_descriptor interface_descriptor01 = {
.binterfaceclass = 0x0A,
.binterfacesubclass = 0x00,
.binterfaceprotocol = 0x00,
- .iinterface = 6
+ .iinterface = 0
};
__code struct usb_endpoint_descriptor bulk_ep6_out_endpoint_descriptor = {
@@ -200,8 +200,8 @@ void ep6_isr(void)__interrupt EP6_ISR
}
void ep8_isr(void)__interrupt EP8_ISR
{
- EXIF &= ~0x10; /* Clear USBINT: Main global interrupt */
- EPIRQ = 0x80; /* Clear individual EP8IN IRQ */
+ EXIF &= ~0x10; /* Clear USBINT: Main global interrupt */
+ EPIRQ = 0x80; /* Clear individual EP8IN IRQ */
}
void ibn_isr(void)__interrupt IBN_ISR
{
@@ -761,16 +761,16 @@ void ep_init(void)
void i2c_recieve(void)
{
- PIN_SDA_DIR = 0;
if (EP6FIFOBUF[0] == 1) {
- uint8_t rdwr = EP6FIFOBUF[0]; //read
- uint8_t data_count = EP6FIFOBUF[1]; //data sent count
+ uint8_t rdwr = EP6FIFOBUF[0]; //read: 1
+ uint8_t reg_byte_check = EP6FIFOBUF[1]; //register given: 1 else: 0
uint8_t count = EP6FIFOBUF[2]; //requested data count
uint8_t adr = EP6FIFOBUF[3]; //address
uint8_t address = get_address(adr, rdwr); //address byte (read command)
uint8_t address_2 = get_address(adr, 0); //address byte 2 (write command)
- printf("%d\n", address - 1);
+ /* i2c bus state byte */
+ EP8FIFOBUF[0] = get_status();
/* start: */
start_cd();
@@ -780,12 +780,10 @@ void i2c_recieve(void)
uint8_t ack = get_ack();
/* send data */
- if (data_count) { //if there is a byte reg
- for (uint8_t i = 0; i < data_count; i++) {
- send_byte(EP6FIFOBUF[i + 4]);
- /* ack(): */
- ack = get_ack();
- }
+ for (int i = 0; i < reg_byte_check; i++) {
+ send_byte(EP6FIFOBUF[i + 4]);
+ /* ack(): */
+ ack = get_ack();
}
/* repeated start: */
@@ -796,14 +794,14 @@ void i2c_recieve(void)
ack = get_ack();
/* receive data */
- for (uint8_t i = 0; i < count - 1; i++) {
+ for (int i = 1; i < count; i++) {
EP8FIFOBUF[i] = receive_byte();
/* send ack: */
send_ack();
}
- EP8FIFOBUF[count - 1] = receive_byte();
+ EP8FIFOBUF[count] = receive_byte();
/* send Nack: */
send_nack();
@@ -811,44 +809,46 @@ void i2c_recieve(void)
/* stop */
stop_cd();
- EP8BCH = 0; //EP8
+ EP8BCH = (count + 1) >> 8; //EP8
syncdelay(3);
- EP8BCL = count; //EP8
+ EP8BCL = count + 1; //EP8
EP6BCL = 0x80; //EP6
syncdelay(3);
EP6BCL = 0x80; //EP6
} else {
- uint8_t rdwr = EP6FIFOBUF[0]; //write
+ uint8_t rdwr = EP6FIFOBUF[0]; //write: 0
uint8_t count = EP6FIFOBUF[1]; //data count
uint8_t adr = EP6FIFOBUF[2]; //address
uint8_t address = get_address(adr, rdwr); //address byte (read command)
uint8_t ack_cnt = 0;
-/* start(): */
+ // i2c bus state byte
+ EP8FIFOBUF[0] = get_status();
+
+ /* start(): */
start_cd();
-/* address: */
+ /* address: */
send_byte(address); //write
-/* ack(): */
+ /* ack(): */
if (!get_ack())
ack_cnt++;
-/* send data */
- for (uint8_t i = 0; i < count; i++) {
+ /* send data */
+ for (int i = 0; i < count; i++) {
send_byte(EP6FIFOBUF[i + 3]);
-
/* get ack: */
if (!get_ack())
ack_cnt++;
}
-/* stop */
+ /* stop */
stop_cd();
- EP8FIFOBUF[0] = ack_cnt;
+ EP8FIFOBUF[1] = ack_cnt;
EP8BCH = 0; //EP8
syncdelay(3);
- EP8BCL = 1; //EP8
+ EP8BCL = 2; //EP8
EP6BCL = 0x80; //EP6
syncdelay(3);
diff --git a/src/jtag/drivers/angie/angie_firmware.bin b/src/jtag/drivers/angie/angie_firmware.bin
index 68486ef8f..6ba2babb1 100644
Binary files a/src/jtag/drivers/angie/angie_firmware.bin and b/src/jtag/drivers/angie/angie_firmware.bin differ
-----------------------------------------------------------------------
Summary of changes:
contrib/firmware/angie/c/include/i2c.h | 1 +
contrib/firmware/angie/c/src/i2c.c | 13 +++++++
contrib/firmware/angie/c/src/main.c | 2 +-
contrib/firmware/angie/c/src/usb.c | 58 +++++++++++++++---------------
src/jtag/drivers/angie/angie_firmware.bin | Bin 10216 -> 4487 bytes
5 files changed, 44 insertions(+), 30 deletions(-)
hooks/post-receive
--
Main OpenOCD repository
|