Skip to content

Commit 9a9afb0

Browse files
jfischer-noaescolar
authored andcommitted
dap: implement DAP SWD sequence command
DAP SWD sequence command is a requirement to support CMSIS-DAPv2. Raise supported version to "2.1.0". Signed-off-by: Maximilian Deubel <[email protected]> Signed-off-by: Johann Fischer <[email protected]>
1 parent e31cdc0 commit 9a9afb0

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

subsys/dap/cmsis_dap.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,52 @@ static uint16_t dap_transfer(struct dap_context *const ctx,
638638
return retval;
639639
}
640640

641+
static uint16_t dap_swdp_sequence(struct dap_context *const ctx,
642+
const uint8_t *const request,
643+
uint8_t *const response)
644+
{
645+
const struct swdp_api *api = ctx->swdp_dev->api;
646+
const uint8_t *request_data = request + 1;
647+
uint8_t *response_data = response + 1;
648+
uint8_t count = request[0];
649+
uint8_t num_cycles;
650+
uint32_t num_bytes;
651+
bool input;
652+
653+
switch (ctx->debug_port) {
654+
case DAP_PORT_SWD:
655+
response[0] = DAP_OK;
656+
break;
657+
case DAP_PORT_JTAG:
658+
default:
659+
LOG_ERR("port unsupported");
660+
response[0] = DAP_ERROR;
661+
return 1U;
662+
}
663+
664+
for (size_t i = 0; i < count; ++i) {
665+
input = *request_data & BIT(7);
666+
num_cycles = *request_data & BIT_MASK(7);
667+
num_bytes = (num_cycles + 7) >> 3; /* rounded up to full bytes */
668+
669+
if (num_cycles == 0) {
670+
num_cycles = 64;
671+
}
672+
673+
request_data += 1;
674+
675+
if (input) {
676+
api->swdp_input_sequence(ctx->swdp_dev, num_cycles, response_data);
677+
response_data += num_bytes;
678+
} else {
679+
api->swdp_output_sequence(ctx->swdp_dev, num_cycles, request_data);
680+
request_data += num_bytes;
681+
}
682+
}
683+
684+
return response_data - response;
685+
}
686+
641687
/*
642688
* Process SWD DAP_TransferBlock command and prepare response.
643689
* pyOCD counterpart is _encode_transfer_block_data.
@@ -865,6 +911,9 @@ static uint16_t dap_process_cmd(struct dap_context *const ctx,
865911
case ID_DAP_SWDP_CONFIGURE:
866912
retval = dap_swdp_configure(ctx, request, response);
867913
break;
914+
case ID_DAP_SWDP_SEQUENCE:
915+
retval = dap_swdp_sequence(ctx, request, response);
916+
break;
868917
case ID_DAP_JTAG_SEQUENCE:
869918
LOG_ERR("JTAG sequence unsupported");
870919
retval = 1;

subsys/dap/cmsis_dap.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include <zephyr/kernel.h>
2323

2424
/* Firmware Version */
25-
#define DAP_FW_VER "1.10"
25+
#define DAP_FW_VER "2.1.0"
2626

2727
/* DAP Command IDs */
2828
#define ID_DAP_INFO 0x00U
@@ -42,6 +42,7 @@
4242
#define ID_DAP_SWJ_SEQUENCE 0x12U
4343

4444
#define ID_DAP_SWDP_CONFIGURE 0x13U
45+
#define ID_DAP_SWDP_SEQUENCE 0x1DU
4546

4647
#define ID_DAP_JTAG_SEQUENCE 0x14U
4748
#define ID_DAP_JTAG_CONFIGURE 0x15U

0 commit comments

Comments
 (0)