aboutsummaryrefslogtreecommitdiff
path: root/src/jtag/drivers/cmsis_dap_usb_hid.c
diff options
context:
space:
mode:
authorTomas Vanek <vanekt@fbl.cz>2021-03-23 09:12:26 +0100
committerTomas Vanek <vanekt@fbl.cz>2021-04-10 20:54:43 +0100
commit01030fb893546ddd522a1557d8c00868b3e45f60 (patch)
tree2e1ff14e06d2f921d60dd54caf7671a2e28b1658 /src/jtag/drivers/cmsis_dap_usb_hid.c
parentfed42ccfd3dff0c3dcfa7f017bbd26eff3d4f15c (diff)
downloadriscv-openocd-01030fb893546ddd522a1557d8c00868b3e45f60.zip
riscv-openocd-01030fb893546ddd522a1557d8c00868b3e45f60.tar.gz
riscv-openocd-01030fb893546ddd522a1557d8c00868b3e45f60.tar.bz2
drivers/cmsis-dap: tidy up buffer access
Each one of CMSIS-DAP command handlers was responsible for setting HID report number, which in case of USB bulk transport was not used at all. The command had to be filled with 1 byte offset whereas the response was read without an offset. Introduce 'command' and 'response' pointers into struct cmsis_dap. Use them for filling the command and read the response respectively. CMSIS-DAP command parameter are now at positions as documented in https://arm-software.github.io/CMSIS_5/DAP/html/group__DAP__Commands__gr.html Adjust buffer allocation for HID and USB bulk transports. While on it, use h_u32_to_le() and h_u16_to_le() instead of per-byte writes. Change-Id: Ib0808d6826ba0e254c1007ace8b743405536332a Signed-off-by: Tomas Vanek <vanekt@fbl.cz> Reviewed-on: http://openocd.zylin.com/6120 Reviewed-by: Adrian M Negreanu <adrian.negreanu@nxp.com> Tested-by: jenkins Reviewed-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
Diffstat (limited to 'src/jtag/drivers/cmsis_dap_usb_hid.c')
-rw-r--r--src/jtag/drivers/cmsis_dap_usb_hid.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/jtag/drivers/cmsis_dap_usb_hid.c b/src/jtag/drivers/cmsis_dap_usb_hid.c
index b290d6f..e83ad1f 100644
--- a/src/jtag/drivers/cmsis_dap_usb_hid.c
+++ b/src/jtag/drivers/cmsis_dap_usb_hid.c
@@ -164,6 +164,8 @@ static int cmsis_dap_hid_open(struct cmsis_dap *dap, uint16_t vids[], uint16_t p
return ERROR_FAIL;
}
+ dap->command = dap->packet_buffer + REPORT_ID_SIZE;
+ dap->response = dap->packet_buffer;
return ERROR_OK;
}
@@ -195,8 +197,10 @@ static int cmsis_dap_hid_write(struct cmsis_dap *dap, int txlen, int timeout_ms)
{
(void) timeout_ms;
+ dap->packet_buffer[0] = 0; /* HID report number */
+
/* Pad the rest of the TX buffer with 0's */
- memset(dap->packet_buffer + txlen, 0, dap->packet_buffer_size - txlen);
+ memset(dap->command + txlen, 0, dap->packet_size - txlen);
/* write data to device */
int retval = hid_write(dap->bdata->dev_handle, dap->packet_buffer, dap->packet_buffer_size);
@@ -221,6 +225,9 @@ static int cmsis_dap_hid_alloc(struct cmsis_dap *dap, unsigned int pkt_sz)
dap->packet_size = pkt_sz;
dap->packet_buffer_size = packet_buffer_size;
+ dap->command = dap->packet_buffer + REPORT_ID_SIZE;
+ dap->response = dap->packet_buffer;
+
return ERROR_OK;
}