From 7ccbdd98c0bd18c2a672ed50aa1f96aff97dd4af Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Tue, 5 Oct 2021 22:02:24 +0200 Subject: [PATCH] hosted/dap: Copy command buffer in wait/retry loop. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The same buffer is used for both command and response, causing part of the command to be overwritten before it’s retried. Solve this by saving and restoring a copy of the command before retrying. --- src/platforms/hosted/dap.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/platforms/hosted/dap.c b/src/platforms/hosted/dap.c index 7da956b8..35bce96b 100644 --- a/src/platforms/hosted/dap.c +++ b/src/platforms/hosted/dap.c @@ -323,10 +323,14 @@ static void dap_line_reset(void) static uint32_t wait_word(uint8_t *buf, int size, int len, uint8_t *dp_fault) { + uint8_t cmd_copy[len]; + memcpy(cmd_copy, buf, len); do { dbg_dap_cmd(buf, size, len); if (buf[1] < DAP_TRANSFER_WAIT) break; + if (buf[1] == DAP_TRANSFER_WAIT) + memcpy(buf, cmd_copy, len); } while (buf[1] == DAP_TRANSFER_WAIT); if (buf[1] > DAP_TRANSFER_WAIT) {