From f98b7274b42d0debb362a9c569b234befaa152bb Mon Sep 17 00:00:00 2001 From: Uwe Bonnes Date: Sun, 20 Dec 2020 13:30:49 +0100 Subject: [PATCH] hosted/stlinkv3: Detect STlinkV3 in bootloader mode. --- src/platforms/hosted/bmp_libusb.c | 13 +------------ src/platforms/hosted/platform.h | 13 +++++++++++++ src/platforms/hosted/stlinkv2.c | 32 ++++++++++++++++--------------- 3 files changed, 31 insertions(+), 27 deletions(-) diff --git a/src/platforms/hosted/bmp_libusb.c b/src/platforms/hosted/bmp_libusb.c index 0264f25..d900090 100644 --- a/src/platforms/hosted/bmp_libusb.c +++ b/src/platforms/hosted/bmp_libusb.c @@ -24,18 +24,6 @@ #include "ftdi_bmp.h" #include "version.h" -#define VENDOR_ID_STLINK 0x0483 -#define PRODUCT_ID_STLINK_MASK 0xffe0 -#define PRODUCT_ID_STLINK_GROUP 0x3740 -#define PRODUCT_ID_STLINKV1 0x3744 -#define PRODUCT_ID_STLINKV2 0x3748 -#define PRODUCT_ID_STLINKV21 0x374b -#define PRODUCT_ID_STLINKV21_MSD 0x3752 -#define PRODUCT_ID_STLINKV3 0x374f -#define PRODUCT_ID_STLINKV3E 0x374e - -#define VENDOR_ID_SEGGER 0x1366 - #define NO_SERIAL_NUMBER "" void bmp_ident(bmp_info_t *info) @@ -177,6 +165,7 @@ int find_debuggers(BMP_CL_OPTIONS_t *cl_opts,bmp_info_t *info) if ((desc.idProduct == PRODUCT_ID_STLINKV2) || (desc.idProduct == PRODUCT_ID_STLINKV21) || (desc.idProduct == PRODUCT_ID_STLINKV21_MSD) || + (desc.idProduct == PRODUCT_ID_STLINKV3_BL) || (desc.idProduct == PRODUCT_ID_STLINKV3) || (desc.idProduct == PRODUCT_ID_STLINKV3E)) { type = BMP_TYPE_STLINKV2; diff --git a/src/platforms/hosted/platform.h b/src/platforms/hosted/platform.h index 129686f..33e4e86 100644 --- a/src/platforms/hosted/platform.h +++ b/src/platforms/hosted/platform.h @@ -14,6 +14,19 @@ void platform_buffer_flush(void); #define PRODUCT_ID_BMP_BL 0x6017 #define PRODUCT_ID_BMP 0x6018 +#define VENDOR_ID_STLINK 0x0483 +#define PRODUCT_ID_STLINK_MASK 0xffe0 +#define PRODUCT_ID_STLINK_GROUP 0x3740 +#define PRODUCT_ID_STLINKV1 0x3744 +#define PRODUCT_ID_STLINKV2 0x3748 +#define PRODUCT_ID_STLINKV21 0x374b +#define PRODUCT_ID_STLINKV21_MSD 0x3752 +#define PRODUCT_ID_STLINKV3_BL 0x374d +#define PRODUCT_ID_STLINKV3 0x374f +#define PRODUCT_ID_STLINKV3E 0x374e + +#define VENDOR_ID_SEGGER 0x1366 + typedef enum bmp_type_s { BMP_TYPE_NONE = 0, BMP_TYPE_BMP, diff --git a/src/platforms/hosted/stlinkv2.c b/src/platforms/hosted/stlinkv2.c index b22b58a..211ad10 100644 --- a/src/platforms/hosted/stlinkv2.c +++ b/src/platforms/hosted/stlinkv2.c @@ -42,16 +42,6 @@ #include "cl_utils.h" -#define VENDOR_ID_STLINK 0x483 -#define PRODUCT_ID_STLINK_MASK 0xffe0 -#define PRODUCT_ID_STLINK_GROUP 0x3740 -#define PRODUCT_ID_STLINKV1 0x3744 -#define PRODUCT_ID_STLINKV2 0x3748 -#define PRODUCT_ID_STLINKV21 0x374b -#define PRODUCT_ID_STLINKV21_MSD 0x3752 -#define PRODUCT_ID_STLINKV3 0x374f -#define PRODUCT_ID_STLINKV3E 0x374e - #define STLINK_SWIM_ERR_OK 0x00 #define STLINK_SWIM_BUSY 0x01 #define STLINK_DEBUG_ERR_OK 0x80 @@ -399,6 +389,9 @@ static int write_retry(uint8_t *cmdbuf, size_t cmdsize, return res; } +/* Version data is at 0x080103f8 with STLINKV3 bootloader flashed with + * STLinkUpgrade_v3[3|5].jar + */ static void stlink_version(bmp_info_t *info) { if (Stlink.ver_hw == 30) { @@ -543,20 +536,29 @@ int stlink_init(bmp_info_t *info) libusb_free_device_list(devs, 1); if (!found) return 0; - if (info->pid == PRODUCT_ID_STLINKV2) { + if (info->vid != VENDOR_ID_STLINK) + return 0; + switch (info->pid) { + case PRODUCT_ID_STLINKV2: Stlink.ver_hw = 20; info->usb_link->ep_tx = 2; Stlink.ep_tx = 2; - } else if ((info->pid == PRODUCT_ID_STLINKV21)|| - (info->pid == PRODUCT_ID_STLINKV21_MSD)) { + break; + case PRODUCT_ID_STLINKV21 : + case PRODUCT_ID_STLINKV21_MSD: Stlink.ver_hw = 21; info->usb_link->ep_tx = 1; Stlink.ep_tx = 1; - } else if ((info->pid == PRODUCT_ID_STLINKV3) || - (info->pid == PRODUCT_ID_STLINKV3E)) { + break; + case PRODUCT_ID_STLINKV3_BL: + case PRODUCT_ID_STLINKV3: + case PRODUCT_ID_STLINKV3E: Stlink.ver_hw = 30; info->usb_link->ep_tx = 1; Stlink.ep_tx = 1; + break; + default: + DEBUG_INFO("Unhandled STM32 device\n"); } info->usb_link->ep_rx = 1; int config;