jtag/drivers/cmsis_dap: introduce packet_usable_size 63/7363/4
authorTomas Vanek <vanekt@fbl.cz>
Sat, 19 Nov 2022 06:16:30 +0000 (07:16 +0100)
committerAntonio Borneo <borneo.antonio@gmail.com>
Sun, 15 Jan 2023 15:08:49 +0000 (15:08 +0000)
USB bulk backend needs to avoid zero sized USB packets
sent after each full sized packed for performance reasons.

HID backend uses fixed size HID reports so the full size
of the report can be utilized.

Introduce packet_usable_size to reflect it.

Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Change-Id: I34094c9edac5730624480711cbd6aa65883c47c7
Reviewed-on: https://review.openocd.org/c/openocd/+/7363
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
src/jtag/drivers/cmsis_dap.c
src/jtag/drivers/cmsis_dap.h
src/jtag/drivers/cmsis_dap_usb_bulk.c
src/jtag/drivers/cmsis_dap_usb_hid.c

index 5e01d064724e81ef6472048df43b74951a8fe3db..364a1774605465d9b5df29145f7d122afe4215e8 100644 (file)
@@ -229,7 +229,7 @@ static int pending_scan_result_count;
 static struct pending_scan_result pending_scan_results[MAX_PENDING_SCAN_RESULTS];
 
 /* queued JTAG sequences that will be executed on the next flush */
-#define QUEUED_SEQ_BUF_LEN (cmsis_dap_handle->packet_size - 3)
+#define QUEUED_SEQ_BUF_LEN (cmsis_dap_handle->packet_usable_size - 3)
 static int queued_seq_count;
 static int queued_seq_buf_end;
 static int queued_seq_tdo_ptr;
index 80044199bcd00e67d73ab03bd7c275ebef321884..72e07fb048803923b4cedee0117f5e9d2e84fd36 100644 (file)
@@ -27,6 +27,7 @@ struct cmsis_dap {
        struct cmsis_dap_backend_data *bdata;
        const struct cmsis_dap_backend *backend;
        unsigned int packet_size;
+       unsigned int packet_usable_size;
        unsigned int packet_buffer_size;
        uint8_t *packet_buffer;
        uint8_t *command;
index 55b9a558a1ccfb921d7ae90aa0a92ca4b0d2813c..6599c414ce9e1bc9cd26712c03cdf8f0427f4df9 100644 (file)
@@ -352,25 +352,17 @@ static int cmsis_dap_usb_open(struct cmsis_dap *dap, uint16_t vids[], uint16_t p
                                return ERROR_FAIL;
                        }
 
-                       dap->packet_size = packet_size;
-                       dap->packet_buffer_size = packet_size;
                        dap->bdata->usb_ctx = ctx;
                        dap->bdata->dev_handle = dev_handle;
                        dap->bdata->ep_out = ep_out;
                        dap->bdata->ep_in = ep_in;
                        dap->bdata->interface = interface_num;
 
-                       dap->packet_buffer = malloc(dap->packet_buffer_size);
-                       if (!dap->packet_buffer) {
-                               LOG_ERROR("unable to allocate memory");
+                       err = cmsis_dap_usb_alloc(dap, packet_size);
+                       if (err != ERROR_OK)
                                cmsis_dap_usb_close(dap);
-                               return ERROR_FAIL;
-                       }
-
-                       dap->command = dap->packet_buffer;
-                       dap->response = dap->packet_buffer;
 
-                       return ERROR_OK;
+                       return err;
                }
 
                libusb_close(dev_handle);
@@ -445,6 +437,8 @@ static int cmsis_dap_usb_alloc(struct cmsis_dap *dap, unsigned int pkt_sz)
        dap->packet_buffer = buf;
        dap->packet_size = pkt_sz;
        dap->packet_buffer_size = pkt_sz;
+       /* Prevent sending zero size USB packets */
+       dap->packet_usable_size = pkt_sz - 1;
 
        dap->command = dap->packet_buffer;
        dap->response = dap->packet_buffer;
index 592eb0925a89961c407c49a87822a28bf806d2e3..52dfd761654a589b421233cf9c6753f4394a2901 100644 (file)
@@ -213,6 +213,7 @@ static int cmsis_dap_hid_alloc(struct cmsis_dap *dap, unsigned int pkt_sz)
 
        dap->packet_buffer = buf;
        dap->packet_size = pkt_sz;
+       dap->packet_usable_size = pkt_sz;
        dap->packet_buffer_size = packet_buffer_size;
 
        dap->command = dap->packet_buffer + REPORT_ID_SIZE;

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)