stlink: add comment of firmware version for each flag bit
[openocd.git] / src / jtag / drivers / stlink_usb.c
index 813af55785cbeaa912cc7511e56167a0ca1f4b62..1a1963425a87428d276efdc3d4e1d14af41cb137 100644 (file)
@@ -35,6 +35,7 @@
 /* project specific includes */
 #include <helper/binarybuffer.h>
 #include <helper/bits.h>
+#include <helper/system.h>
 #include <jtag/interface.h>
 #include <jtag/hla/hla_layout.h>
 #include <jtag/hla/hla_transport.h>
@@ -412,17 +413,17 @@ static inline int stlink_usb_xfer_noerrcheck(void *handle, const uint8_t *buf, i
  * Map the relevant features, quirks and workaround for specific firmware
  * version of stlink
  */
-#define STLINK_F_HAS_TRACE              BIT(0)
-#define STLINK_F_HAS_SWD_SET_FREQ       BIT(1)
-#define STLINK_F_HAS_JTAG_SET_FREQ      BIT(2)
-#define STLINK_F_HAS_MEM_16BIT          BIT(3)
-#define STLINK_F_HAS_GETLASTRWSTATUS2   BIT(4)
-#define STLINK_F_HAS_DAP_REG            BIT(5)
-#define STLINK_F_QUIRK_JTAG_DP_READ     BIT(6)
-#define STLINK_F_HAS_AP_INIT            BIT(7)
-#define STLINK_F_HAS_DPBANKSEL          BIT(8)
-#define STLINK_F_HAS_RW8_512BYTES       BIT(9)
-#define STLINK_F_FIX_CLOSE_AP           BIT(10)
+#define STLINK_F_HAS_TRACE              BIT(0)  /* v2>=j13 || v3 */
+#define STLINK_F_HAS_SWD_SET_FREQ       BIT(1)  /* v2>=j22 */
+#define STLINK_F_HAS_JTAG_SET_FREQ      BIT(2)  /* v2>=j24 */
+#define STLINK_F_HAS_MEM_16BIT          BIT(3)  /* v2>=j26 || v3 */
+#define STLINK_F_HAS_GETLASTRWSTATUS2   BIT(4)  /* v2>=j15 || v3 */
+#define STLINK_F_HAS_DAP_REG            BIT(5)  /* v2>=j24 || v3 */
+#define STLINK_F_QUIRK_JTAG_DP_READ     BIT(6)  /* v2>=j24 && v2<j32 */
+#define STLINK_F_HAS_AP_INIT            BIT(7)  /* v2>=j28 || v3 */
+#define STLINK_F_HAS_DPBANKSEL          BIT(8)  /* v2>=j32 || v3>=j2 */
+#define STLINK_F_HAS_RW8_512BYTES       BIT(9)  /* v3>=j6 */
+#define STLINK_F_FIX_CLOSE_AP           BIT(10) /* v2>=j29 || v3 */
 
 /* aliases */
 #define STLINK_F_HAS_TARGET_VOLT        STLINK_F_HAS_TRACE
@@ -1967,7 +1968,7 @@ static int stlink_usb_trace_read(void *handle, uint8_t *buf, size_t *size)
                        return res;
 
                size_t bytes_avail = le_to_h_u16(h->databuf);
-               *size = bytes_avail < *size ? bytes_avail : *size - 1;
+               *size = bytes_avail < *size ? bytes_avail : *size;
 
                if (*size > 0) {
                        res = stlink_usb_read_trace(handle, buf, *size);
@@ -3016,7 +3017,7 @@ static int stlink_close(void *handle)
  *    based on the length (0x1a = 26) we could easily decide if we have to fixup the serial
  *    and then we have just to convert the raw data into printable characters using sprintf
  */
-static char *stlink_usb_get_alternate_serial(libusb_device_handle *device,
+static char *stlink_usb_get_alternate_serial(struct libusb_device_handle *device,
                struct libusb_device_descriptor *dev_desc)
 {
        int usb_retval;
@@ -3528,8 +3529,20 @@ static int stlink_config_trace(void *handle, bool enabled,
 {
        struct stlink_usb_handle_s *h = handle;
 
-       if (enabled && (!(h->version.flags & STLINK_F_HAS_TRACE) ||
-                       pin_protocol != TPIU_PIN_PROTOCOL_ASYNC_UART)) {
+       if (!(h->version.flags & STLINK_F_HAS_TRACE)) {
+               LOG_ERROR("The attached ST-LINK version doesn't support trace");
+               return ERROR_FAIL;
+       }
+
+       if (!enabled) {
+               stlink_usb_trace_disable(h);
+               return ERROR_OK;
+       }
+
+       assert(trace_freq != NULL);
+       assert(prescaler != NULL);
+
+       if (pin_protocol != TPIU_PIN_PROTOCOL_ASYNC_UART) {
                LOG_ERROR("The attached ST-LINK version doesn't support this trace mode");
                return ERROR_FAIL;
        }
@@ -3538,14 +3551,12 @@ static int stlink_config_trace(void *handle, bool enabled,
                        STLINK_V3_TRACE_MAX_HZ : STLINK_TRACE_MAX_HZ;
 
        /* Only concern ourselves with the frequency if the STlink is processing it. */
-       if (enabled && *trace_freq > max_trace_freq) {
+       if (*trace_freq > max_trace_freq) {
                LOG_ERROR("ST-LINK doesn't support SWO frequency higher than %u",
                          max_trace_freq);
                return ERROR_FAIL;
        }
 
-       stlink_usb_trace_disable(h);
-
        if (!*trace_freq)
                *trace_freq = max_trace_freq;
 
@@ -3567,8 +3578,7 @@ static int stlink_config_trace(void *handle, bool enabled,
 
        *prescaler = presc;
 
-       if (!enabled)
-               return ERROR_OK;
+       stlink_usb_trace_disable(h);
 
        h->trace.source_hz = *trace_freq;
 

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)