jtag: drivers: stlink: handle all versions with single config

Extend HLA interface to allow multiple VID/PID pairs and use it to
autodetect the connected stlink version.

Change-Id: I35cd895b2260e23cf0e8fcb1fc11a78c2b99c69b
Signed-off-by: Paul Fertser <fercerpav@gmail.com>
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: http://openocd.zylin.com/3961
Tested-by: jenkins
Reviewed-by: Karl Palsson <karlp@tweak.net.au>
Reviewed-by: Andreas Bolsch <hyphen0break@gmail.com>
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
fence_i_fix_for_release
Paul Fertser 2017-01-26 23:41:40 +03:00 committed by Spencer Oliver
parent eb26a884e0
commit 31c58c139d
31 changed files with 91 additions and 93 deletions

View File

@ -2948,8 +2948,8 @@ Specifies the serial number of the adapter.
Specifies the adapter layout to use.
@end deffn
@deffn {Config Command} {hla_vid_pid} vid pid
The vendor ID and product ID of the device.
@deffn {Config Command} {hla_vid_pid} [vid pid]+
Pairs of vendor IDs and product IDs of the device.
@end deffn
@deffn {Command} {hla_command} command

View File

@ -1650,13 +1650,11 @@ static int stlink_usb_open(struct hl_interface_param_s *param, void **fd)
h->transport = param->transport;
const uint16_t vids[] = { param->vid, 0 };
const uint16_t pids[] = { param->pid, 0 };
const char *serial = param->serial;
for (unsigned i = 0; param->vid[i]; i++) {
LOG_DEBUG("transport: %d vid: 0x%04x pid: 0x%04x serial: %s",
param->transport, param->vid, param->pid,
param->transport, param->vid[i], param->pid[i],
param->serial ? param->serial : "");
}
/*
On certain host USB configurations(e.g. MacBook Air)
@ -1668,7 +1666,7 @@ static int stlink_usb_open(struct hl_interface_param_s *param, void **fd)
in order to become operational.
*/
do {
if (jtag_libusb_open(vids, pids, serial, &h->fd) != ERROR_OK) {
if (jtag_libusb_open(param->vid, param->pid, param->serial, &h->fd) != ERROR_OK) {
LOG_ERROR("open failed");
goto error_open;
}
@ -1683,8 +1681,14 @@ static int stlink_usb_open(struct hl_interface_param_s *param, void **fd)
/* RX EP is common for all versions */
h->rx_ep = STLINK_RX_EP;
uint16_t pid;
if (jtag_libusb_get_pid(jtag_libusb_get_device(h->fd), &pid) != ERROR_OK) {
LOG_DEBUG("libusb_get_pid failed");
goto error_open;
}
/* wrap version for first read */
switch (param->pid) {
switch (pid) {
case STLINK_V1_PID:
h->version.stlink = 1;
h->tx_ep = STLINK_TX_EP;
@ -1736,12 +1740,6 @@ static int stlink_usb_open(struct hl_interface_param_s *param, void **fd)
}
} while (1);
/* compare usb vid/pid */
if ((param->vid != h->vid) || (param->pid != h->pid))
LOG_INFO("vid/pid are not identical: 0x%04X/0x%04X 0x%04X/0x%04X",
param->vid, param->pid,
h->vid, h->pid);
/* check if mode is supported */
err = ERROR_OK;

View File

@ -688,14 +688,18 @@ static int icdi_usb_open(struct hl_interface_param_s *param, void **fd)
}
LOG_DEBUG("transport: %d vid: 0x%04x pid: 0x%04x", param->transport,
param->vid, param->pid);
param->vid[0], param->pid[0]);
/* TODO: convert libusb_ calls to jtag_libusb_ */
if (param->vid[1])
LOG_WARNING("Bad configuration: 'hla_vid_pid' command does not accept more than one VID PID pair on ti-icdi!");
if (libusb_init(&h->usb_ctx) != 0) {
LOG_ERROR("libusb init failed");
goto error_open;
}
h->usb_dev = libusb_open_device_with_vid_pid(h->usb_ctx, param->vid, param->pid);
h->usb_dev = libusb_open_device_with_vid_pid(h->usb_ctx, param->vid[0], param->pid[0]);
if (!h->usb_dev) {
LOG_ERROR("open failed");
goto error_open;

View File

@ -35,7 +35,7 @@
#include <target/target.h>
static struct hl_interface_s hl_if = { {0, 0, 0, 0, 0, HL_TRANSPORT_UNKNOWN, false, -1}, 0, 0 };
static struct hl_interface_s hl_if = { {0, 0, { 0 }, { 0 }, 0, HL_TRANSPORT_UNKNOWN, false, -1}, 0, 0 };
int hl_interface_open(enum hl_transports tr)
{
@ -264,15 +264,27 @@ COMMAND_HANDLER(hl_interface_handle_layout_command)
COMMAND_HANDLER(hl_interface_handle_vid_pid_command)
{
LOG_DEBUG("hl_interface_handle_vid_pid_command");
if (CMD_ARGC != 2) {
LOG_WARNING("ignoring extra IDs in hl_vid_pid (maximum is 1 pair)");
if (CMD_ARGC > HLA_MAX_USB_IDS * 2) {
LOG_WARNING("ignoring extra IDs in hla_vid_pid "
"(maximum is %d pairs)", HLA_MAX_USB_IDS);
CMD_ARGC = HLA_MAX_USB_IDS * 2;
}
if (CMD_ARGC < 2 || (CMD_ARGC & 1)) {
LOG_WARNING("incomplete hla_vid_pid configuration directive");
return ERROR_COMMAND_SYNTAX_ERROR;
}
COMMAND_PARSE_NUMBER(u16, CMD_ARGV[0], hl_if.param.vid);
COMMAND_PARSE_NUMBER(u16, CMD_ARGV[1], hl_if.param.pid);
unsigned i;
for (i = 0; i < CMD_ARGC; i += 2) {
COMMAND_PARSE_NUMBER(u16, CMD_ARGV[i], hl_if.param.vid[i / 2]);
COMMAND_PARSE_NUMBER(u16, CMD_ARGV[i + 1], hl_if.param.pid[i / 2]);
}
/*
* Explicitly terminate, in case there are multiple instances of
* hla_vid_pid.
*/
hl_if.param.vid[i / 2] = hl_if.param.pid[i / 2] = 0;
return ERROR_OK;
}

View File

@ -29,15 +29,17 @@ enum e_hl_transports;
/** */
extern const char *hl_transports[];
#define HLA_MAX_USB_IDS 8
struct hl_interface_param_s {
/** */
const char *device_desc;
/** */
const char *serial;
/** */
uint16_t vid;
/** */
uint16_t pid;
/** List of recognised VIDs */
uint16_t vid[HLA_MAX_USB_IDS + 1];
/** List of recognised PIDs */
uint16_t pid[HLA_MAX_USB_IDS + 1];
/** */
unsigned api;
/** */

View File

@ -6,7 +6,7 @@
# STM32F091RC
# http://www.st.com/web/catalog/tools/FM116/SC959/SS1532/LN1847/PF260944
source [find interface/stlink-v2-1.cfg]
source [find interface/stlink.cfg]
transport select hla_swd

View File

@ -1,7 +1,7 @@
# This is an ST NUCLEO F103RB board with a single STM32F103RBT6 chip.
# http://www.st.com/web/catalog/tools/FM116/SC959/SS1532/LN1847/PF259875
source [find interface/stlink-v2-1.cfg]
source [find interface/stlink.cfg]
transport select hla_swd

View File

@ -1,7 +1,7 @@
# This is an ST NUCLEO F334R8 board with a single STM32F334R8T6 chip.
# http://www.st.com/web/catalog/tools/FM116/SC959/SS1532/LN1847/PF260004
source [find interface/stlink-v2-1.cfg]
source [find interface/stlink.cfg]
transport select hla_swd

View File

@ -4,7 +4,7 @@
# STM32F411RET6
# http://www.st.com/web/catalog/tools/FM116/SC959/SS1532/LN1847/PF260320
source [find interface/stlink-v2-1.cfg]
source [find interface/stlink.cfg]
transport select hla_swd

View File

@ -1,7 +1,7 @@
# This is an ST NUCLEO L152RE board with a single STM32L152RET6 chip.
# http://www.st.com/web/catalog/tools/FM116/SC959/SS1532/LN1847/PF260002
source [find interface/stlink-v2-1.cfg]
source [find interface/stlink.cfg]
transport select hla_swd

View File

@ -1,7 +1,7 @@
# This is a ST NUCLEO L476RG board with a single STM32L476RGT6 chip.
# http://www.st.com/web/catalog/tools/FM116/SC959/SS1532/LN1847/PF261636
source [find interface/stlink-v2-1.cfg]
source [find interface/stlink.cfg]
transport select hla_swd

View File

@ -4,7 +4,7 @@
#
# This is for using the onboard STLINK/V2
source [find interface/stlink-v2.cfg]
source [find interface/stlink.cfg]
transport select hla_swd

View File

@ -4,7 +4,7 @@
#
# This is for using the onboard STLINK/V2
source [find interface/stlink-v2.cfg]
source [find interface/stlink.cfg]
transport select hla_swd

View File

@ -4,7 +4,7 @@
#
# This is for using the onboard STLINK/V2
source [find interface/stlink-v2.cfg]
source [find interface/stlink.cfg]
transport select hla_swd

View File

@ -4,7 +4,7 @@
#
# This is for using the onboard STLINK/V2
source [find interface/stlink-v2.cfg]
source [find interface/stlink.cfg]
transport select hla_swd

View File

@ -4,7 +4,7 @@
#
# This is for using the onboard STLINK/V2
source [find interface/stlink-v2.cfg]
source [find interface/stlink.cfg]
transport select hla_swd

View File

@ -1,7 +1,7 @@
# This is an STM32F0 discovery board with a single STM32F051R8T6 chip.
# http://www.st.com/internet/evalboard/product/253215.jsp
source [find interface/stlink-v2.cfg]
source [find interface/stlink.cfg]
transport select hla_swd

View File

@ -1,7 +1,7 @@
# This is an STM32F3 discovery board with a single STM32F303VCT6 chip.
# http://www.st.com/internet/evalboard/product/254044.jsp
source [find interface/stlink-v2.cfg]
source [find interface/stlink.cfg]
transport select hla_swd

View File

@ -3,7 +3,7 @@
# http://www.st.com/web/catalog/tools/FM116/SC959/SS1532/PF259090
#
source [find interface/stlink-v2-1.cfg]
source [find interface/stlink.cfg]
transport select hla_swd

View File

@ -3,7 +3,7 @@
# http://www.st.com/web/catalog/tools/FM116/SC959/SS1532/PF259090
#
source [find interface/stlink-v2.cfg]
source [find interface/stlink.cfg]
transport select hla_swd

View File

@ -3,7 +3,7 @@
# http://www.st.com/web/catalog/tools/FM116/CL1620/SC959/SS1532/LN1848/PF262395
#
source [find interface/stlink-v2-1.cfg]
source [find interface/stlink.cfg]
transport select hla_swd

View File

@ -1,7 +1,7 @@
# This is an STM32F4 discovery board with a single STM32F407VGT6 chip.
# http://www.st.com/internet/evalboard/product/252419.jsp
source [find interface/stlink-v2.cfg]
source [find interface/stlink.cfg]
transport select hla_swd

View File

@ -2,7 +2,7 @@
# http://www.st.com/web/catalog/tools/FM116/SC959/SS1532/LN1848/PF261641
# This is for using the onboard STLINK/V2-1
source [find interface/stlink-v2-1.cfg]
source [find interface/stlink.cfg]
transport select hla_swd

View File

@ -1,7 +1,7 @@
# This is an STM32L053 discovery board with a single STM32L053 chip.
# http://www.st.com/web/en/catalog/tools/PF260319
source [find interface/stlink-v2-1.cfg]
source [find interface/stlink.cfg]
transport select hla_swd

View File

@ -4,7 +4,7 @@
# an stlink-v2-1 interface.
# This is for STM32L4 boards that are connected via stlink-v2-1.
source [find interface/stlink-v2-1.cfg]
source [find interface/stlink.cfg]
transport select hla_swd

View File

@ -1,7 +1,7 @@
# This is an STM32L discovery board with a single STM32L152RBT6 chip.
# http://www.st.com/internet/evalboard/product/250990.jsp
source [find interface/stlink-v2.cfg]
source [find interface/stlink.cfg]
transport select hla_swd

View File

@ -1,7 +1,7 @@
# This is an STM32VL discovery board with a single STM32F100RB chip.
# http://www.st.com/internet/evalboard/product/250863.jsp
source [find interface/stlink-v1.cfg]
source [find interface/stlink.cfg]
transport select hla_swd

View File

@ -1,9 +1,2 @@
#
# STMicroelectronics ST-LINK/V1 in-circuit debugger/programmer
#
interface hla
hla_layout stlink
hla_device_desc "ST-LINK/V1"
hla_vid_pid 0x0483 0x3744
echo "WARNING: interface/stlink-v1.cfg is deprecated, please switch to interface/stlink.cfg"
source [find interface/stlink.cfg]

View File

@ -1,16 +1,2 @@
#
# STMicroelectronics ST-LINK/V2-1 in-circuit debugger/programmer
#
interface hla
hla_layout stlink
hla_device_desc "ST-LINK/V2-1"
hla_vid_pid 0x0483 0x374b
# Optionally specify the serial number of ST-LINK/V2 usb device. ST-LINK/V2
# devices seem to have serial numbers with unreadable characters. ST-LINK/V2
# firmware version >= V2.J21.S4 recommended to avoid issues with adapter serial
# number reset issues.
# eg.
#hla_serial "\xaa\xbc\x6e\x06\x50\x75\xff\x55\x17\x42\x19\x3f"
echo "WARNING: interface/stlink-v2-1.cfg is deprecated, please switch to interface/stlink.cfg"
source [find interface/stlink.cfg]

View File

@ -1,16 +1,2 @@
#
# STMicroelectronics ST-LINK/V2 in-circuit debugger/programmer
#
interface hla
hla_layout stlink
hla_device_desc "ST-LINK/V2"
hla_vid_pid 0x0483 0x3748
# Optionally specify the serial number of ST-LINK/V2 usb device. ST-LINK/V2
# devices seem to have serial numbers with unreadable characters. ST-LINK/V2
# firmware version >= V2.J21.S4 recommended to avoid issues with adapter serial
# number reset issues.
# eg.
#hla_serial "\xaa\xbc\x6e\x06\x50\x75\xff\x55\x17\x42\x19\x3f"
echo "WARNING: interface/stlink-v2.cfg is deprecated, please switch to interface/stlink.cfg"
source [find interface/stlink.cfg]

17
tcl/interface/stlink.cfg Normal file
View File

@ -0,0 +1,17 @@
#
# STMicroelectronics ST-LINK/V1, ST-LINK/V2, ST-LINK/V2-1 in-circuit
# debugger/programmer
#
interface hla
hla_layout stlink
hla_device_desc "ST-LINK"
hla_vid_pid 0x0483 0x3744 0x0483 0x3748 0x0483 0x374b
# Optionally specify the serial number of ST-LINK/V2 usb device. ST-LINK/V2
# devices seem to have serial numbers with unreadable characters. ST-LINK/V2
# firmware version >= V2.J21.S4 recommended to avoid issues with adapter serial
# number reset issues.
# eg.
#hla_serial "\xaa\xbc\x6e\x06\x50\x75\xff\x55\x17\x42\x19\x3f"