From 761e0230d42dbc25be0a2b744d34770dd839a880 Mon Sep 17 00:00:00 2001 From: Uwe Bonnes Date: Sat, 9 Oct 2021 22:59:32 +0200 Subject: [PATCH] cmsis-dap: Print messages when transfers fail. Expect signal integrity errors when using jumper cables. Often probes switch the SWJ GPIO with highest speed, resulting in possible reflections. Additional ground wires may help. If there is isolation between probe and targets, additional ground wires are a must or ground shift will wrack the transfer! --- src/platforms/hosted/cmsis_dap.c | 4 +++- src/platforms/hosted/dap.c | 20 ++++++++++++++------ src/target/adiv5_swdp.c | 2 +- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/platforms/hosted/cmsis_dap.c b/src/platforms/hosted/cmsis_dap.c index 77c77992..d01c2b8b 100644 --- a/src/platforms/hosted/cmsis_dap.c +++ b/src/platforms/hosted/cmsis_dap.c @@ -83,8 +83,10 @@ int dap_init(bmp_info_t *info) report_size = 64 + 1; } handle = hid_open(info->vid, info->pid, (serial[0]) ? serial : NULL); - if (!handle) + if (!handle) { + DEBUG_WARN("hid_open failed\n"); return -1; + } } else if (type == CMSIS_TYPE_BULK) { DEBUG_INFO("Using bulk transfer\n"); usb_handle = libusb_open_device_with_vid_pid(info->libusb_ctx, info->vid, info->pid); diff --git a/src/platforms/hosted/dap.c b/src/platforms/hosted/dap.c index b2827bf0..7fbe72a3 100644 --- a/src/platforms/hosted/dap.c +++ b/src/platforms/hosted/dap.c @@ -333,12 +333,14 @@ static uint32_t wait_word(uint8_t *buf, int size, int len, uint8_t *dp_fault) } while (buf[1] == DAP_TRANSFER_WAIT); if (buf[1] > DAP_TRANSFER_WAIT) { -// DEBUG_WARN("dap_read_reg fault\n"); + DEBUG_WARN("dap wait_word reg %x fault %x\n", + cmd_copy[3] & 0x7c, buf[1]); *dp_fault = 1; - } - if (buf[1] == DAP_TRANSFER_ERROR) { - DEBUG_WARN("dap_read_reg, protocoll error\n"); - dap_line_reset(); + if (buf[1] == DAP_TRANSFER_ERROR) { + DEBUG_WARN("dap_read_reg, protocoll error\n"); + dap_line_reset(); + } + return 0; } uint32_t res = ((uint32_t)buf[5] << 24) | ((uint32_t)buf[4] << 16) | @@ -568,7 +570,7 @@ void dap_ap_mem_access_setup(ADIv5_AP_t *ap, uint32_t addr, enum align align) uint32_t dap_ap_read(ADIv5_AP_t *ap, uint16_t addr) { - DEBUG_PROBE("dap_ap_read_start\n"); + DEBUG_PROBE("dap_ap_read_start addr %x\n", addr); uint8_t buf[63], *p = buf; buf[0] = ID_DAP_TRANSFER; uint8_t dap_index = 0; @@ -584,6 +586,9 @@ uint32_t dap_ap_read(ADIv5_AP_t *ap, uint16_t addr) *p++ = (addr & 0x0c) | DAP_TRANSFER_RnW | ((addr & 0x100) ? DAP_TRANSFER_APnDP : 0); uint32_t res = wait_word(buf, 63, p - buf, &ap->dp->fault); + if ((buf[0] != 2) || (buf[1] != 1)) { + DEBUG_WARN("dap_ap_read error %x\n", buf[1]); + } return res; } @@ -607,6 +612,9 @@ void dap_ap_write(ADIv5_AP_t *ap, uint16_t addr, uint32_t value) *p++ = (value >> 16) & 0xff; *p++ = (value >> 24) & 0xff; dbg_dap_cmd(buf, sizeof(buf), p - buf); + if ((buf[0] != 2) || (buf[1] != 1)) { + DEBUG_WARN("dap_ap_write error %x\n", buf[1]); + } } void dap_read_single(ADIv5_AP_t *ap, void *dest, uint32_t src, enum align align) diff --git a/src/target/adiv5_swdp.c b/src/target/adiv5_swdp.c index 2af37c00..2e584316 100644 --- a/src/target/adiv5_swdp.c +++ b/src/target/adiv5_swdp.c @@ -124,7 +124,7 @@ int adiv5_swdp_scan(uint32_t targetid) idcode = initial_dp->low_access(initial_dp, ADIV5_LOW_READ, ADIV5_DP_IDCODE, 0); } - if (e2.type) { + if (e2.type || initial_dp->fault) { DEBUG_WARN("No usable DP found\n"); return 0; }