This is an automated email from Gerrit. "Tomas Vanek <van...@fbl.cz>" just uploaded a new patch set to Gerrit, which you can find at https://review.openocd.org/c/openocd/+/7367
-- gerrit commit e1b7be44d5c4b9cc3c53a1b570ee8390b165f764 Author: Tomas Vanek <van...@fbl.cz> Date: Sat Nov 19 07:23:29 2022 +0100 jtag/drivers/cmsis_dap: debug tweaks Just a development tool, not intened for merging. Signed-off-by: Tomas Vanek <van...@fbl.cz> Change-Id: Idffbb23fe139d9c620ff006b37153bbffd412531 diff --git a/src/jtag/drivers/cmsis_dap.c b/src/jtag/drivers/cmsis_dap.c index c32744874f..3586cdac8e 100644 --- a/src/jtag/drivers/cmsis_dap.c +++ b/src/jtag/drivers/cmsis_dap.c @@ -233,6 +233,8 @@ static unsigned int tfer_command_size; static unsigned int tfer_max_command_size; static unsigned int tfer_response_size; static unsigned int tfer_max_response_size; +static unsigned int tfer_sleep_usec; +static unsigned int tfer_mismatch_guard; /* pointers to buffers that will receive jtag scan results on the next flush */ #define MAX_PENDING_SCAN_RESULTS 256 @@ -776,7 +778,7 @@ static void cmsis_dap_swd_write_from_queue(struct cmsis_dap *dap) tfer_command_size = 0; tfer_response_size = 0; - LOG_DEBUG_IO("Executing %d queued transactions from FIFO index %u", + LOG_DEBUG("Executing %d queued transactions from FIFO index %u", block->transfer_count, dap->pending_fifo_put_idx); if (queued_retval != ERROR_OK) { @@ -860,7 +862,7 @@ static void cmsis_dap_swd_read_process(struct cmsis_dap *dap, enum cmsis_dap_blo /* get reply */ struct timeval tv = { .tv_sec = 0, - .tv_usec = 0 + .tv_usec = tfer_sleep_usec }; int retval = dap->backend->read(dap, LIBUSB_TIMEOUT_MS, blocking ? NULL : &tv); if ((retval == ERROR_TIMEOUT_REACHED || retval == 0) && !blocking) @@ -966,11 +968,15 @@ static void cmsis_dap_swd_queue_cmd(uint8_t cmd, uint32_t *dst, uint32_t data) } if (tfer_command_size + this_rw_command_size > tfer_max_command_size - || tfer_response_size + this_rw_response_size > tfer_max_response_size + || tfer_response_size + this_rw_response_size + + tfer_mismatch_guard * cmsis_dap_handle->pending_fifo_put_idx > tfer_max_response_size || targetsel_cmd) { if (cmsis_dap_handle->pending_fifo_block_count) cmsis_dap_swd_read_process(cmsis_dap_handle, CMSIS_DAP_NON_BLOCKING); + if (cmsis_dap_handle->pending_fifo_block_count >= cmsis_dap_handle->packet_count - 1) + usleep(tfer_sleep_usec); + /* Not enough room in the queue. Run the queue. */ cmsis_dap_swd_write_from_queue(cmsis_dap_handle); @@ -2054,6 +2060,37 @@ COMMAND_HANDLER(cmsis_dap_handle_cmd_command) return ERROR_OK; } +COMMAND_HANDLER(cmsis_dap_handle_tweaks_command) +{ + if (CMD_ARGC >= 1) { + unsigned int count; + COMMAND_PARSE_NUMBER(uint, CMD_ARGV[0], count); + + cmsis_dap_handle->packet_count = MAX(1, MIN(count, MAX_PENDING_REQUESTS)); + } + if (CMD_ARGC >= 2) { + unsigned int command_size; + COMMAND_PARSE_NUMBER(uint, CMD_ARGV[1], command_size); + tfer_max_command_size = MAX(1, MIN(command_size, cmsis_dap_handle->packet_size)); + } + if (CMD_ARGC >= 3) { + unsigned int response_size; + COMMAND_PARSE_NUMBER(uint, CMD_ARGV[2], response_size); + tfer_max_response_size = MAX(1, MIN(response_size, cmsis_dap_handle->packet_size)); + } + if (CMD_ARGC >= 4) + COMMAND_PARSE_NUMBER(uint, CMD_ARGV[3], tfer_sleep_usec); + + if (CMD_ARGC >= 5) + COMMAND_PARSE_NUMBER(uint, CMD_ARGV[4], tfer_mismatch_guard); + + command_print(CMD, "%u pending packets at maximum", cmsis_dap_handle->packet_count); + command_print(CMD, "Max command size %u, max response size %u", + tfer_max_command_size, tfer_max_response_size); + + return ERROR_OK; +} + COMMAND_HANDLER(cmsis_dap_handle_vid_pid_command) { if (CMD_ARGC > MAX_USB_IDS * 2) { @@ -2121,6 +2158,13 @@ static const struct command_registration cmsis_dap_subcommand_handlers[] = { .usage = "", .help = "issue cmsis-dap command", }, + { + .name = "tweaks", + .handler = &cmsis_dap_handle_tweaks_command, + .mode = COMMAND_EXEC, + .usage = "[pending_req [cmd_size [resp_size [wait_before_next_cmd_us [mismatch_guard]]]]]", + .help = "maximal number of packets sent without waiting for a reply and other tweaks", + }, COMMAND_REGISTRATION_DONE }; --