aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAntonio Borneo <borneo.antonio@gmail.com>2018-09-20 10:49:43 +0200
committerSpencer Oliver <spen@spen-soft.co.uk>2018-12-06 10:03:14 +0000
commit9252a94218b2f5af2507ededb6e62352a26ec32c (patch)
tree5f171ee12f9267d0b135a9bc07d9698e9248c85c /src
parent1822c2fb9487d56b2787d114275dadf42cb55053 (diff)
stlink: simplify maintenance of version and features
The number of stlink firmware version is growing, each carrying new features. Today's code has several check distributed here and there and it's already hard to track them and verify the correctness. The introduction of STLINK-V3 will make the situation much worst, and the code much less readable. Add a "flags" bitmask in the struct stlink_usb_version to allow setting individual bits for each feature available or for specific quirks and workarounds. This patch does not implement setting nor testing "flags"; it would be introduced in following patches, one bit at a time. Change-Id: I09d78202646a6c8330731f8aa96dc9d295fa5655 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/4706 Tested-by: jenkins Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
Diffstat (limited to 'src')
-rw-r--r--src/jtag/drivers/stlink_usb.c34
1 files changed, 28 insertions, 6 deletions
diff --git a/src/jtag/drivers/stlink_usb.c b/src/jtag/drivers/stlink_usb.c
index 49d7391f..9d6e2220 100644
--- a/src/jtag/drivers/stlink_usb.c
+++ b/src/jtag/drivers/stlink_usb.c
@@ -89,6 +89,8 @@ struct stlink_usb_version {
int swim;
/** highest supported jtag api version */
enum stlink_jtag_api_version jtag_api_max;
+ /** one bit for each feature supported. See macros STLINK_F_* */
+ uint32_t flags;
};
/** */
@@ -272,6 +274,13 @@ enum stlink_mode {
#define REQUEST_SENSE 0x03
#define REQUEST_SENSE_LENGTH 18
+/*
+ * Map the relevant features, quirks and workaround for specific firmware
+ * version of stlink
+ */
+
+/* aliases */
+
struct speed_map {
int speed;
int speed_divisor;
@@ -622,6 +631,7 @@ static void stlink_usb_init_buffer(void *handle, uint8_t direction, uint32_t siz
static int stlink_usb_version(void *handle)
{
int res;
+ uint32_t flags;
uint16_t v;
struct stlink_usb_handle_s *h = handle;
@@ -644,13 +654,25 @@ static int stlink_usb_version(void *handle)
h->vid = buf_get_u32(h->databuf, 16, 16);
h->pid = buf_get_u32(h->databuf, 32, 16);
- /* set the supported jtag api version
- * API V2 is supported since JTAG V11
- */
- if (h->version.jtag >= 11)
+ flags = 0;
+ switch (h->version.stlink) {
+ case 1:
+ /* ST-LINK/V1 from J11 switch to api-v2 (and support SWD) */
+ if (h->version.jtag >= 11)
+ h->version.jtag_api_max = STLINK_JTAG_API_V2;
+ else
+ h->version.jtag_api_max = STLINK_JTAG_API_V1;
+
+ break;
+ case 2:
+ /* all ST-LINK/V2 and ST-Link/V2.1 use api-v2 */
h->version.jtag_api_max = STLINK_JTAG_API_V2;
- else
- h->version.jtag_api_max = STLINK_JTAG_API_V1;
+
+ break;
+ default:
+ break;
+ }
+ h->version.flags = flags;
LOG_INFO("STLINK v%d JTAG v%d API v%d SWIM v%d VID 0x%04X PID 0x%04X",
h->version.stlink,