From 7b4e00d0f8c79785426661de627649854066dbcd Mon Sep 17 00:00:00 2001 From: Maximilian Deubel Date: Wed, 30 Aug 2023 13:50:48 +0200 Subject: [PATCH] review changes --- samples/subsys/dap/src/cmsis_dap_usb.c | 15 +++++++----- subsys/dap/cmsis_dap.c | 34 +++++++++++++++----------- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/samples/subsys/dap/src/cmsis_dap_usb.c b/samples/subsys/dap/src/cmsis_dap_usb.c index 8a42f701299f2ff..8f00f6af54def47 100644 --- a/samples/subsys/dap/src/cmsis_dap_usb.c +++ b/samples/subsys/dap/src/cmsis_dap_usb.c @@ -10,6 +10,9 @@ #include "cmsis_dap_usb.h" +#define DAP_USB_EP_IN 0x81 +#define DAP_USB_EP_OUT 0x01 + uint8_t rx_buf[CONFIG_CMSIS_DAP_PACKET_SIZE]; uint8_t tx_buf[CONFIG_CMSIS_DAP_PACKET_SIZE]; @@ -40,7 +43,7 @@ LOG_MODULE_REGISTER(cmsis_dap); #define COMPATIBLE_ID_WINUSB \ 'W', 'I', 'N', 'U', 'S', 'B', 0x00, 0x00 -static struct msosv2_descriptor_t { +static struct msosv2_descriptor_type { struct msosv2_descriptor_set_header header; #if defined(CONFIG_USB_COMPOSITE_DEVICE) struct msosv2_function_subset_header cmsis_dap_v2_subset_header; @@ -55,7 +58,7 @@ static struct msosv2_descriptor_t { .wLength = sizeof(struct msosv2_descriptor_set_header), .wDescriptorType = MS_OS_20_SET_HEADER_DESCRIPTOR, .dwWindowsVersion = 0x06030000, - .wTotalLength = sizeof(struct msosv2_descriptor_t), + .wTotalLength = sizeof(struct msosv2_descriptor_type), }, #if defined(CONFIG_USB_COMPOSITE_DEVICE) .cmsis_dap_v2_subset_header = { @@ -245,9 +248,9 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) struct { struct usb_ep_descriptor if0_in_ep; } __packed dapusb_desc = { .if0 = INITIALIZER_IF(2, USB_BCC_VENDOR), - .if0_out_ep = INITIALIZER_IF_EP(AUTO_EP_OUT, USB_DC_EP_BULK, + .if0_out_ep = INITIALIZER_IF_EP(DAP_USB_EP_OUT, USB_DC_EP_BULK, CONFIG_CMSIS_DAP_PACKET_SIZE, 0), - .if0_in_ep = INITIALIZER_IF_EP(AUTO_EP_IN, USB_DC_EP_BULK, + .if0_in_ep = INITIALIZER_IF_EP(DAP_USB_EP_IN, USB_DC_EP_BULK, CONFIG_CMSIS_DAP_PACKET_SIZE, 0), }; @@ -255,11 +258,11 @@ USBD_CLASS_DESCR_DEFINE(primary, 0) struct { static struct usb_ep_cfg_data dapusb_ep_data[] = { { .ep_cb = usb_transfer_ep_callback, - .ep_addr = AUTO_EP_OUT + .ep_addr = DAP_USB_EP_OUT }, { .ep_cb = usb_transfer_ep_callback, - .ep_addr = AUTO_EP_IN + .ep_addr = DAP_USB_EP_IN } }; diff --git a/subsys/dap/cmsis_dap.c b/subsys/dap/cmsis_dap.c index 19cae13be3396c3..5db3034999a7637 100644 --- a/subsys/dap/cmsis_dap.c +++ b/subsys/dap/cmsis_dap.c @@ -78,13 +78,15 @@ static uint16_t dap_info(struct dap_context *const ctx, switch (id) { case DAP_ID_VENDOR: LOG_DBG("ID_VENDOR"); - memcpy(info, CONFIG_CMSIS_DAP_PROBE_VENDOR, sizeof(CONFIG_CMSIS_DAP_PROBE_VENDOR)); - length = (uint8_t)sizeof(CONFIG_CMSIS_DAP_PROBE_VENDOR); + memcpy(info, CONFIG_CMSIS_DAP_PROBE_VENDOR, + sizeof(CONFIG_CMSIS_DAP_PROBE_VENDOR)); + length = sizeof(CONFIG_CMSIS_DAP_PROBE_VENDOR); break; case DAP_ID_PRODUCT: LOG_DBG("ID_PRODUCT"); - memcpy(info, CONFIG_CMSIS_DAP_PROBE_NAME, sizeof(CONFIG_CMSIS_DAP_PROBE_NAME)); - length = (uint8_t)sizeof(CONFIG_CMSIS_DAP_PROBE_NAME); + memcpy(info, CONFIG_CMSIS_DAP_PROBE_NAME, + sizeof(CONFIG_CMSIS_DAP_PROBE_NAME)); + length = sizeof(CONFIG_CMSIS_DAP_PROBE_NAME); break; case DAP_ID_SER_NUM: /* optional to implement */ @@ -93,26 +95,30 @@ static uint16_t dap_info(struct dap_context *const ctx, case DAP_ID_FW_VER: LOG_DBG("ID_FW_VER"); memcpy(info, DAP_FW_VER, sizeof(DAP_FW_VER)); - length = (uint8_t)sizeof(DAP_FW_VER); + length = sizeof(DAP_FW_VER); break; case DAP_ID_DEVICE_VENDOR: LOG_DBG("ID_DEVICE_VENDOR"); - memcpy(info, CONFIG_CMSIS_DAP_DEVICE_VENDOR, sizeof(CONFIG_CMSIS_DAP_DEVICE_VENDOR)); - length = (uint8_t)sizeof(CONFIG_CMSIS_DAP_DEVICE_VENDOR); + memcpy(info, CONFIG_CMSIS_DAP_DEVICE_VENDOR, + sizeof(CONFIG_CMSIS_DAP_DEVICE_VENDOR)); + length = sizeof(CONFIG_CMSIS_DAP_DEVICE_VENDOR); break; case DAP_ID_DEVICE_NAME: LOG_DBG("ID_DEVICE_NAME"); - memcpy(info, CONFIG_CMSIS_DAP_DEVICE_NAME, sizeof(CONFIG_CMSIS_DAP_DEVICE_NAME)); - length = (uint8_t)sizeof(CONFIG_CMSIS_DAP_DEVICE_NAME); + memcpy(info, CONFIG_CMSIS_DAP_DEVICE_NAME, + sizeof(CONFIG_CMSIS_DAP_DEVICE_NAME)); + length = sizeof(CONFIG_CMSIS_DAP_DEVICE_NAME); break; case DAP_ID_BOARD_VENDOR: LOG_DBG("ID_BOARD_VENDOR"); - memcpy(info, CONFIG_CMSIS_DAP_BOARD_VENDOR, sizeof(CONFIG_CMSIS_DAP_BOARD_VENDOR)); - length = (uint8_t)sizeof(CONFIG_CMSIS_DAP_BOARD_VENDOR); + memcpy(info, CONFIG_CMSIS_DAP_BOARD_VENDOR, + sizeof(CONFIG_CMSIS_DAP_BOARD_VENDOR)); + length = sizeof(CONFIG_CMSIS_DAP_BOARD_VENDOR); break; case DAP_ID_BOARD_NAME: - memcpy(info, CONFIG_CMSIS_DAP_BOARD_NAME, sizeof(CONFIG_CMSIS_DAP_BOARD_NAME)); - length = (uint8_t)sizeof(CONFIG_CMSIS_DAP_BOARD_NAME); + memcpy(info, CONFIG_CMSIS_DAP_BOARD_NAME, + sizeof(CONFIG_CMSIS_DAP_BOARD_NAME)); + length = sizeof(CONFIG_CMSIS_DAP_BOARD_NAME); LOG_DBG("ID_BOARD_NAME"); break; case DAP_ID_PRODUCT_FW_VER: @@ -151,7 +157,7 @@ static uint16_t dap_info(struct dap_context *const ctx, break; } - response[0] = (uint8_t)length; + response[0] = length; return length + 1U; }