From 166eb3ee3eb736ece3e874738e8eb564e3f08cbb Mon Sep 17 00:00:00 2001 From: Uwe Bonnes Date: Mon, 11 Oct 2021 20:57:49 +0200 Subject: [PATCH] cmsis_dap: Always transfer 65 bytes with hid_read|write() CMSIS-DAP Dragonprobe works on some devices. E.g. it does not work on NUCLEO-F103 --- src/platforms/hosted/cmsis_dap.c | 7 +++++-- src/platforms/hosted/dap.c | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/platforms/hosted/cmsis_dap.c b/src/platforms/hosted/cmsis_dap.c index d01c2b8..d9fff76 100644 --- a/src/platforms/hosted/cmsis_dap.c +++ b/src/platforms/hosted/cmsis_dap.c @@ -220,15 +220,18 @@ int dbg_dap_cmd(uint8_t *data, int size, int rsize) DEBUG_WIRE("%02x.", buffer[i]); DEBUG_WIRE("\n"); if (type == CMSIS_TYPE_HID) { - res = hid_write(handle, buffer, rsize + 1); + res = hid_write(handle, buffer, 65); if (res < 0) { DEBUG_WARN( "Error: %ls\n", hid_error(handle)); exit(-1); } - res = hid_read(handle, buffer, report_size + 1); + res = hid_read_timeout(handle, buffer, 65, 1000); if (res < 0) { DEBUG_WARN( "debugger read(): %ls\n", hid_error(handle)); exit(-1); + } else if (res == 0) { + DEBUG_WARN( "timeout\n"); + exit(-1); } } else if (type == CMSIS_TYPE_BULK) { int transferred = 0; diff --git a/src/platforms/hosted/dap.c b/src/platforms/hosted/dap.c index 7fbe72a..1db9482 100644 --- a/src/platforms/hosted/dap.c +++ b/src/platforms/hosted/dap.c @@ -197,10 +197,10 @@ void dap_connect(bool jtag) //----------------------------------------------------------------------------- void dap_disconnect(void) { - uint8_t buf[1]; + uint8_t buf[65]; buf[0] = ID_DAP_DISCONNECT; - dbg_dap_cmd(buf, sizeof(buf), 1); + dbg_dap_cmd(buf, sizeof(buf), 65); } static uint32_t swj_clock;