add AT32F425 WINUSB support

pull/13/head
XIVN1987 1 year ago
parent 4e6b0561a8
commit f9fa614f43
  1. 24
      AT32F425/src/CSL/AT32F425_USB_Lib/usbd_sdr.c
  2. 19
      AT32F425/src/descriptor.c
  3. 6
      AT32F425/src/hid_transfer.h
  4. 6
      AT32F425/src/main.c
  5. 7
      AT32F425/src/usb_conf.h
  6. 4
      README.md

@ -80,6 +80,14 @@ static usb_sts_type usbd_get_descriptor(usbd_core_type *udev)
case USB_DESCIPTOR_TYPE_CONFIGURATION: case USB_DESCIPTOR_TYPE_CONFIGURATION:
desc = udev->desc_handler->get_device_configuration(); desc = udev->desc_handler->get_device_configuration();
break; 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: case USB_DESCIPTOR_TYPE_STRING:
{ {
uint8_t str_desc = (uint8_t)udev->setup.wValue; 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_sts_type ret = USB_OK;
usb_setup_type *setup = &udev->setup; 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); udev->class_handler->setup_handler(udev, &udev->setup);
return ret; return ret;

@ -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, 5,
0x0F, DESC_BOS,
5+20+8, 0, // wTotalLength 5+20+8, 0, // wTotalLength
1, // bNumDeviceCaps 1, // bNumDeviceCaps
/*** MS OS 2.0 descriptor platform capability descriptor ***/ /*** MS OS 2.0 descriptor platform capability descriptor ***/
28, 28,
0x10, DESC_CAPABILITY,
5, // bDevCapabilityType: PLATFORM (05H) 5, // bDevCapabilityType: PLATFORM (05H)
0x00, 0x00,
0xDF, 0x60, 0xDD, 0xD8, // PlatformCapabilityUUID: MS_OS_20_Platform_Capability_ID (D8DD60DF-4589-4CC7-9CD2-659D9E648A9F) 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 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_SET_HEADER_DESCRIPTOR 0x00
#define MS_OS_20_SUBSET_HEADER_CONFIGURATION 0x01 #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_CCGP_DEVICE 0x07
#define MS_OS_20_FEATURE_VENDOR_REVISION 0x08 #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 ***/ /*** Microsoft OS 2.0 Descriptor Set Header ***/
10, 0, 10, 0,

@ -2,11 +2,11 @@
#define __HID_TRANSFER_H__ #define __HID_TRANSFER_H__
#define USBD_VID 0x0416 #define USBD_VID 0x2E3C
#ifdef DAP_FW_V1 #ifdef DAP_FW_V1
#define USBD_PID 0x5021 #define USBD_PID 0x5021
#else #else
#define USBD_PID 0x7687 #define USBD_PID 0x7021
#endif #endif
@ -26,8 +26,6 @@
#define CDC_BULK_OUT_SZ 64 #define CDC_BULK_OUT_SZ 64
#define WINUSB_VENDOR_CODE 0x34
uint8_t usbd_hid_process(void); uint8_t usbd_hid_process(void);

@ -7,6 +7,12 @@
#include "hid_transfer.h" #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; otg_core_type Otg;

@ -24,6 +24,13 @@
#define DESC_BOS 0x0F
#define DESC_CAPABILITY 0x10
#define WINUSB_VENDOR_CODE 0x34
void usb_delay_ms(uint32_t ms); void usb_delay_ms(uint32_t ms);

@ -4,6 +4,10 @@ DAPLink (CMSIS-DAP) porting to Artery AT32F425, WCH CH32V203 and WCH CH32V305.
## DAPLink-AT32F425 ## DAPLink-AT32F425
DAPLink (CMSIS-DAP) based on Artery AT32F425 (support crystal-less USB), supports SWD, JTAG and CDC. 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 ### Pin map
| FUNC | Pin | | FUNC | Pin |
| :---- | :---- | | :---- | :---- |

Loading…
Cancel
Save