diff --git a/AT32F425/src/CSL/AT32F425_USB_Lib/usbd_sdr.c b/AT32F425/src/CSL/AT32F425_USB_Lib/usbd_sdr.c index d0b58a9..35745f9 100644 --- a/AT32F425/src/CSL/AT32F425_USB_Lib/usbd_sdr.c +++ b/AT32F425/src/CSL/AT32F425_USB_Lib/usbd_sdr.c @@ -80,6 +80,14 @@ static usb_sts_type usbd_get_descriptor(usbd_core_type *udev) case USB_DESCIPTOR_TYPE_CONFIGURATION: desc = udev->desc_handler->get_device_configuration(); break; + +#ifndef DAP_FW_V1 + usbd_desc_t *get_bos_descriptor(void); + case DESC_BOS: + desc = get_bos_descriptor(); + break; +#endif + case USB_DESCIPTOR_TYPE_STRING: { uint8_t str_desc = (uint8_t)udev->setup.wValue; @@ -351,7 +359,21 @@ usb_sts_type usbd_device_request(usbd_core_type *udev) { usb_sts_type ret = USB_OK; usb_setup_type *setup = &udev->setup; - if((setup->bmRequestType & USB_REQ_TYPE_RESERVED) != USB_REQ_TYPE_STANDARD) + +#ifndef DAP_FW_V1 + extern uint8_t MS_OS_20_DescriptorSet[]; + if((setup->bmRequestType & USB_REQ_TYPE_RESERVED) == USB_REQ_TYPE_VENDOR) + { + if((setup->bRequest == WINUSB_VENDOR_CODE) && ((setup->wIndex & 0xFF) == 7)) + usbd_ctrl_send((usbd_core_type *)udev, MS_OS_20_DescriptorSet, MIN(setup->wLength, MS_OS_20_DescriptorSet[8] | (MS_OS_20_DescriptorSet[9] << 8))); + else + usbd_ctrl_unsupport((usbd_core_type *)udev); + + return ret; + } +#endif + + if((setup->bmRequestType & USB_REQ_TYPE_RESERVED) == USB_REQ_TYPE_CLASS) { udev->class_handler->setup_handler(udev, &udev->setup); return ret; diff --git a/AT32F425/src/descriptor.c b/AT32F425/src/descriptor.c index 9d80a46..c098507 100644 --- a/AT32F425/src/descriptor.c +++ b/AT32F425/src/descriptor.c @@ -379,16 +379,16 @@ static void int_to_unicode(uint32_t value , uint8_t *pbuf , uint8_t len) -uint8_t BOS_Descriptor[] = +ALIGNED_HEAD uint8_t BOS_Descriptor[] ALIGNED_TAIL = { 5, - 0x0F, + DESC_BOS, 5+20+8, 0, // wTotalLength 1, // bNumDeviceCaps /*** MS OS 2.0 descriptor platform capability descriptor ***/ 28, - 0x10, + DESC_CAPABILITY, 5, // bDevCapabilityType: PLATFORM (05H) 0x00, 0xDF, 0x60, 0xDD, 0xD8, // PlatformCapabilityUUID: MS_OS_20_Platform_Capability_ID (D8DD60DF-4589-4CC7-9CD2-659D9E648A9F) @@ -402,6 +402,17 @@ uint8_t BOS_Descriptor[] = 0x00, // bAltEnumCmd }; +usbd_desc_t *get_bos_descriptor(void) +{ + static usbd_desc_t bos_descriptor = + { + sizeof(BOS_Descriptor), + BOS_Descriptor + }; + + return &bos_descriptor; +} + #define MS_OS_20_SET_HEADER_DESCRIPTOR 0x00 #define MS_OS_20_SUBSET_HEADER_CONFIGURATION 0x01 @@ -413,7 +424,7 @@ uint8_t BOS_Descriptor[] = #define MS_OS_20_FEATURE_CCGP_DEVICE 0x07 #define MS_OS_20_FEATURE_VENDOR_REVISION 0x08 -uint8_t MS_OS_20_DescriptorSet[] = +ALIGNED_HEAD uint8_t MS_OS_20_DescriptorSet[] ALIGNED_TAIL = { /*** Microsoft OS 2.0 Descriptor Set Header ***/ 10, 0, diff --git a/AT32F425/src/hid_transfer.h b/AT32F425/src/hid_transfer.h index ae21f4e..da3a158 100644 --- a/AT32F425/src/hid_transfer.h +++ b/AT32F425/src/hid_transfer.h @@ -2,11 +2,11 @@ #define __HID_TRANSFER_H__ -#define USBD_VID 0x0416 +#define USBD_VID 0x2E3C #ifdef DAP_FW_V1 #define USBD_PID 0x5021 #else -#define USBD_PID 0x7687 +#define USBD_PID 0x7021 #endif @@ -26,8 +26,6 @@ #define CDC_BULK_OUT_SZ 64 -#define WINUSB_VENDOR_CODE 0x34 - uint8_t usbd_hid_process(void); diff --git a/AT32F425/src/main.c b/AT32F425/src/main.c index eeca533..d2a8d7c 100644 --- a/AT32F425/src/main.c +++ b/AT32F425/src/main.c @@ -7,6 +7,12 @@ #include "hid_transfer.h" +/* 在 Option 弹窗的 C/C++ 页中: + 定义 DAP_FW_V1: 生成 CMSIS-DAP v1 固件,使用 HID 传输协议 + 不定义 DAP_FW_V1: 生成 CMSIS-DAP v2 固件,使用 WINUSB 传输协议 +*/ + + otg_core_type Otg; diff --git a/AT32F425/src/usb_conf.h b/AT32F425/src/usb_conf.h index c9cad39..5474afb 100644 --- a/AT32F425/src/usb_conf.h +++ b/AT32F425/src/usb_conf.h @@ -24,6 +24,13 @@ +#define DESC_BOS 0x0F +#define DESC_CAPABILITY 0x10 + +#define WINUSB_VENDOR_CODE 0x34 + + + void usb_delay_ms(uint32_t ms); diff --git a/README.md b/README.md index 3a21ea9..7a20d5b 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,10 @@ DAPLink (CMSIS-DAP) porting to Artery AT32F425, WCH CH32V203 and WCH CH32V305. ## DAPLink-AT32F425 DAPLink (CMSIS-DAP) based on Artery AT32F425 (support crystal-less USB), supports SWD, JTAG and CDC. +On C/C++ page of Keil Option Window: +* Define `DAP_FW_V1`: generate CMSIS-DAP V1 firmware, using HID transport protocol. +* Do not define `DAP_FW_V1`: Generate CMSIS-DAP V2 firmware, using WINUSB transfer protocol. + ### Pin map | FUNC | Pin | | :---- | :---- |