+ if (queued_retval != ERROR_OK) {
+ LOG_DEBUG("Skipping due to previous errors: %d", queued_retval);
+ goto skip;
+ }
+
+ if (!pending_transfer_count)
+ goto skip;
+
+ size_t idx = 0;
+ buffer[idx++] = 0; /* report number */
+ buffer[idx++] = CMD_DAP_TFER;
+ buffer[idx++] = 0x00; /* DAP Index */
+ buffer[idx++] = pending_transfer_count;
+
+ for (int i = 0; i < pending_transfer_count; i++) {
+ uint8_t cmd = pending_transfers[i].cmd;
+ uint32_t data = pending_transfers[i].data;
+
+ LOG_DEBUG("%s %s reg %x %"PRIx32,
+ cmd & SWD_CMD_APnDP ? "AP" : "DP",
+ cmd & SWD_CMD_RnW ? "read" : "write",
+ (cmd & SWD_CMD_A32) >> 1, data);
+
+ /* When proper WAIT handling is implemented in the
+ * common SWD framework, this kludge can be
+ * removed. However, this might lead to minor
+ * performance degradation as the adapter wouldn't be
+ * able to automatically retry anything (because ARM
+ * has forgotten to implement sticky error flags
+ * clearing). See also comments regarding
+ * cmsis_dap_cmd_DAP_TFER_Configure() and
+ * cmsis_dap_cmd_DAP_SWD_Configure() in
+ * cmsis_dap_init().
+ */
+ if (!(cmd & SWD_CMD_RnW) &&
+ !(cmd & SWD_CMD_APnDP) &&
+ (cmd & SWD_CMD_A32) >> 1 == DP_CTRL_STAT &&
+ (data & CORUNDETECT)) {
+ LOG_DEBUG("refusing to enable sticky overrun detection");
+ data &= ~CORUNDETECT;
+ }
+
+ buffer[idx++] = (cmd >> 1) & 0x0f;
+ if (!(cmd & SWD_CMD_RnW)) {
+ buffer[idx++] = (data) & 0xff;
+ buffer[idx++] = (data >> 8) & 0xff;
+ buffer[idx++] = (data >> 16) & 0xff;
+ buffer[idx++] = (data >> 24) & 0xff;
+ }
+ }