]> git.sur5r.net Git - openocd/commitdiff
jtag: drivers: stlink: handle all versions with single config
authorPaul Fertser <fercerpav@gmail.com>
Thu, 26 Jan 2017 20:41:40 +0000 (23:41 +0300)
committerSpencer Oliver <spen@spen-soft.co.uk>
Tue, 12 Dec 2017 21:13:55 +0000 (21:13 +0000)
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>
31 files changed:
doc/openocd.texi
src/jtag/drivers/stlink_usb.c
src/jtag/drivers/ti_icdi_usb.c
src/jtag/hla/hla_interface.c
src/jtag/hla/hla_interface.h
tcl/board/st_nucleo_f0.cfg
tcl/board/st_nucleo_f103rb.cfg
tcl/board/st_nucleo_f3.cfg
tcl/board/st_nucleo_f4.cfg
tcl/board/st_nucleo_l1.cfg
tcl/board/st_nucleo_l476rg.cfg
tcl/board/stm320518_eval_stlink.cfg
tcl/board/stm3220g_eval_stlink.cfg
tcl/board/stm3241g_eval_stlink.cfg
tcl/board/stm32429i_eval_stlink.cfg
tcl/board/stm32439i_eval_stlink.cfg
tcl/board/stm32f0discovery.cfg
tcl/board/stm32f3discovery.cfg
tcl/board/stm32f429disc1.cfg
tcl/board/stm32f429discovery.cfg
tcl/board/stm32f469discovery.cfg
tcl/board/stm32f4discovery.cfg
tcl/board/stm32f7discovery.cfg
tcl/board/stm32l0discovery.cfg
tcl/board/stm32l4discovery.cfg
tcl/board/stm32ldiscovery.cfg
tcl/board/stm32vldiscovery.cfg
tcl/interface/stlink-v1.cfg
tcl/interface/stlink-v2-1.cfg
tcl/interface/stlink-v2.cfg
tcl/interface/stlink.cfg [new file with mode: 0644]

index ac491b144cb28a767e808e9fbb33b3e159388743..7de0db8b708804e40043c9c2592893a7d0b4f6e4 100644 (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
index 0bdcd316b70df27c2b6b4345e1cdd875e3be659e..64868ea9e3d2eed26775196d85f20f93c730feda 100644 (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;
-
-       LOG_DEBUG("transport: %d vid: 0x%04x pid: 0x%04x serial: %s",
-                       param->transport, param->vid, param->pid,
-                       param->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[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;
 
index 171ac66c471f5641af30675038cccc1477e2f30f..f316c8256e596ba43f3f2bf7a7b38d4ca99b6d38 100644 (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;
index 9217631b08fefa0477d4686d8d28d8ca9e3c1238..62a8f59477f8b30c1438ffca7a655973a125098d 100644 (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;
 }
index 0992d1cad7fdf8a49da61a7ae2e5da538a64e3b8..262025e9818b7e59e3bc46bd133f19d80cfd49bf 100644 (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;
        /** */
index e9fda19a690ae4c72717b7c3ef24ed54b65aef47..e6a03bba8d031eb6af591939650b1b66d9ecc2a8 100644 (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
 
index 71a92f704e312bd37451bd3b34e97d37bd6fe7ef..e1990dcf4795641bea9360ef028cbb404c3d71ac 100644 (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
 
index 9dffdcbbdec3ed81875f660b6ee8ee28fb06393c..fec612b3983d1ac15f83bbba8e17451d7a05869f 100644 (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
 
index b5a78c1c094f2bd5248540ff2d1fef0316890d1a..11f6f8778351b58932d2b809dd653dd24f2764f4 100644 (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
 
index 56e275627be838b5df6c19b11099ffe5e23c7d0f..d97eb7c17d23a22d25e518c175422edbb94da7d5 100644 (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
 
index 2baa34e76ce8d4e70e4e89ad4bb01ad761ceee8b..4426c3bc9e00dafb79a006b356433b6f13399afd 100644 (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
 
index ce074cbf2a37e19fb3ba7d74b6f2e3466f3ae8a1..a7fef0765307a3fe44595b12cd161af0ba1cacd2 100644 (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
 
index 43a4df98601c5fff70f015942e5291d1fbf5cb3a..b58e42fe5d85ed30490f51056330a74daa138c18 100644 (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
 
index 9c7ad5d95fa914d624261bcfafb3bc22fc0f61d7..b1c54a2c6799649fb7a390aa771015a81f30c517 100644 (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
 
index 2b51cea675907cdca7554f0aeb7ebed4175f406d..010d37198532592b2454b1c7b047d29a1069af65 100644 (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
 
index 5995fb1d286c81668d43b5abdeb725d87cee1bfc..b722ce67c1887088c3e5f96980bfe9d878bfab3e 100644 (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
 
index bae9a69ba0d40f43ca69c6bbc74e6d33927abf91..e2b5e38444a13c7a27f7f8c50ab829dea9f97ead 100644 (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
 
index 5a17b4c992f609a81cc49df66d3918b050abd92c..9bb62f5f2a33cc18eb7a6f062362fc289b8c4627 100644 (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
 
index 9d3cdd7575ac665586bbbd3d79cb3ec0ba566686..c0bcebae4e64a558c31660ab43722abd512c7fc2 100644 (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
 
index e06d2a51c5b09f3782934007d6229e3e206d2cb7..7aef09d4f08aa497514d4bc736c777eb73acc291 100644 (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
 
index 63b13638afa3b19ddde6261c93cb959a2800b71f..a9559a756b222e8a5a4df122cd67a981608fa3a1 100644 (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
 
index 963e0f95931daf202ecc72c4ac8ea255866afbac..60b7f42b5cbaedbaf41de1ece7323d0ea26357ff 100644 (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
 
index 085340f306a928fa8c2a51cbb8b8a715a138b71d..7d1bc9665c98dea9e34698ed1e40ff075da7ae54 100755 (executable)
@@ -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
 
index a035062242f36e286d38f394744c083066c6e21c..aabbf8170a25d4b91bba82408b4ec3ff7ce8ed23 100644 (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
 
index eb19331163f2ce05348d407729d4407a3cf7a754..8b79841ed83e12a996677f8fed933527db660bbf 100644 (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
 
index 8678d290bd144dd79672ce01258b32fdb212f0e8..3e397cba4b46234e9af884d8f175480a4092bf51 100644 (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
 
index 970b5101e81ecb6b9e6a1bcb64e48c357582542c..60805b32c365cf33391663ac0a041020186524ea 100644 (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
 
index 13f207dc6b467f76ec8e3df342a75d04a25598ce..0004227251dc3ec8295f3660a7ffca58c6b6f510 100644 (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]
index 093e80177078667dbc03e166ac5d7e997086b4f2..62f37dc336fb505691df7fabeb7ba8531e053dea 100644 (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]
index ae545a1187762bbdbb80e24913dbe746421310f5..070e4695846dbba9adf25a4a6780d799f28a4aa2 100644 (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]
diff --git a/tcl/interface/stlink.cfg b/tcl/interface/stlink.cfg
new file mode 100644 (file)
index 0000000..d747d85
--- /dev/null
@@ -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"
+