cmsis-dap: don't update the packet size across backends.
authorAdrian Negreanu <adrian.negreanu@nxp.com>
Fri, 6 Nov 2020 09:57:04 +0000 (11:57 +0200)
committerTomas Vanek <vanekt@fbl.cz>
Sat, 10 Apr 2021 19:51:30 +0000 (20:51 +0100)
commitfed42ccfd3dff0c3dcfa7f017bbd26eff3d4f15c
tree2eec34af583550b812f3ebb8dec260846a335e20
parent68e50415a115f3b80b7d1a1b580287745b281a5c
cmsis-dap: don't update the packet size across backends.

The hidapi cmsis-dap backend is using a packet_size of
64+1: 64 is the bMaxPacketSize0 and 1 is the hid Report-Id.

In hidapi::hid_write(), the packet_size is decremented by 1 and
stored for the next transfer.
The packet_size is now valid bMaxPacketSize0=64,
so when hid_read() is called, libusb_bulk_transfer() finishes w/o timeout.

For the libusb bulk backend, the same packet_size of 64+1 is used,
but there's no hid_write() to decrement and store it for the next read.

So the next time a read is done, it will try to read 64+1 bytes.

Fix this by putting the packet logic within each backend.
Use calloc() to allocate the struct cmsis_dap to be on safer side.

Change-Id: I0c450adbc7674d5fcd8208dd23062d5cdd209efd
Signed-off-by: Adrian Negreanu <adrian.negreanu@nxp.com>
Reviewed-on: http://openocd.zylin.com/5920
Tested-by: jenkins
Reviewed-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
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