Compare commits

..

6 Commits

Author SHA1 Message Date
XIVN1987 e8d6eb35f4 simplify VCOM code 6 months ago
XIVN1987 f124c3a685 simplify VCOM code 6 months ago
XIVN1987 dc2c8d401a remove unused variable 6 months ago
XIVN1987 94e69f6ca9 add doc 7 months ago
XIVN1987 a8d3bd67fa fix usb non-standard request processing 7 months ago
XIVN1987 9f8c3ce112 add CH32V305 WINUSB support 7 months ago
  1. BIN
      AT32F425/out/DAPLink.bin
  2. 1233
      AT32F425/out/DAPLink.hex
  3. 1
      AT32F425/src/hid_transfer.c
  4. 6
      AT32F425/src/vcom_serial.c
  5. 3
      AT32F425/src/vcom_serial.h
  6. BIN
      CH32V203/obj/DAPLink.bin
  7. 3026
      CH32V203/obj/DAPLink.hex
  8. 3
      CH32V203/src/USBUsr/usb_istr.c
  9. 2
      CH32V203/src/USBUsr/usb_prop.c
  10. 10
      CH32V203/src/vcom_serial.c
  11. 4
      CH32V203/src/vcom_serial.h
  12. BIN
      CH32V305/obj/DAPLink.bin
  13. 2475
      CH32V305/obj/DAPLink.hex
  14. 67
      CH32V305/src/USBD/ch32v30x_usbhs_device.c
  15. 85
      CH32V305/src/USBD/usb_desc.c
  16. 8
      CH32V305/src/USBD/usb_desc.h
  17. 6
      CH32V305/src/main.c
  18. 10
      CH32V305/src/vcom_serial.c
  19. 4
      CH32V305/src/vcom_serial.h
  20. 5
      README.md
  21. BIN
      doc/DAPLink-HS.eprj
  22. 9291
      doc/DAPLink-HS.pdf
  23. BIN
      doc/DAPLink-HS.png
  24. BIN
      doc/DAPLink.eprj
  25. 8686
      doc/DAPLink.pdf
  26. BIN
      doc/DAPLink.png

Binary file not shown.

File diff suppressed because it is too large Load Diff

@ -212,7 +212,6 @@ static usb_sts_type class_out_handler(void *udev, uint8_t ept_num)
case CDC_BULK_OUT_EP: case CDC_BULK_OUT_EP:
Vcom.out_bytes = recv_len; Vcom.out_bytes = recv_len;
Vcom.out_ready = 1;
break; break;
} }

@ -154,16 +154,16 @@ void VCOM_TransferData(void)
} }
/* 从主机接收到数据,且前面的数据 DMA 已发送完 */ /* 从主机接收到数据,且前面的数据 DMA 已发送完 */
if(Vcom.out_ready && (dma_data_number_get(DMA1_CHANNEL1) == 0)) if(Vcom.out_bytes && (dma_data_number_get(DMA1_CHANNEL1) == 0))
{ {
Vcom.out_ready = 0;
memcpy(TXBuffer, (uint8_t *)Vcom.out_buff, Vcom.out_bytes); memcpy(TXBuffer, (uint8_t *)Vcom.out_buff, Vcom.out_bytes);
dma_channel_enable(DMA1_CHANNEL1, FALSE); dma_channel_enable(DMA1_CHANNEL1, FALSE);
dma_data_number_set(DMA1_CHANNEL1, Vcom.out_bytes); dma_data_number_set(DMA1_CHANNEL1, Vcom.out_bytes);
dma_channel_enable(DMA1_CHANNEL1, TRUE); dma_channel_enable(DMA1_CHANNEL1, TRUE);
Vcom.out_bytes = 0;
/* Ready for next BULK OUT */ /* Ready for next BULK OUT */
usbd_ept_recv(&Otg.dev, CDC_BULK_OUT_EP, (uint8_t *)Vcom.out_buff, CDC_BULK_OUT_SZ); usbd_ept_recv(&Otg.dev, CDC_BULK_OUT_EP, (uint8_t *)Vcom.out_buff, CDC_BULK_OUT_SZ);
} }

@ -7,11 +7,9 @@
typedef struct { typedef struct {
uint8_t rx_buff[RX_BUFF_SIZE]; uint8_t rx_buff[RX_BUFF_SIZE];
uint16_t rx_bytes;
uint16_t rx_wrptr; uint16_t rx_wrptr;
uint16_t rx_rdptr; uint16_t rx_rdptr;
uint8_t tx_buff[TX_BUFF_SIZE]; uint8_t tx_buff[TX_BUFF_SIZE];
uint16_t tx_bytes;
uint16_t tx_wrptr; uint16_t tx_wrptr;
uint16_t tx_rdptr; uint16_t tx_rdptr;
@ -22,7 +20,6 @@ typedef struct {
uint16_t in_ready; uint16_t in_ready;
uint8_t out_buff[64]; uint8_t out_buff[64];
uint16_t out_bytes; uint16_t out_bytes;
uint16_t out_ready;
} VCOM; } VCOM;
extern volatile VCOM Vcom; extern volatile VCOM Vcom;

Binary file not shown.

File diff suppressed because it is too large Load Diff

@ -214,15 +214,12 @@ void EP2_IN_Callback(void)
void EP3_IN_Callback(void) void EP3_IN_Callback(void)
{ {
Vcom.in_ready = 1;
} }
void EP3_OUT_Callback(void) void EP3_OUT_Callback(void)
{ {
Vcom.out_bytes = USB_SIL_Read(EP3_OUT, (uint8_t *)Vcom.out_buff); Vcom.out_bytes = USB_SIL_Read(EP3_OUT, (uint8_t *)Vcom.out_buff);
Vcom.out_ready = 1;
} }

@ -259,8 +259,6 @@ void USBD_Reset(void)
SetDeviceAddress(0); SetDeviceAddress(0);
bDeviceState = ATTACHED; bDeviceState = ATTACHED;
Vcom.in_ready = 1;
} }
/********************************************************************* /*********************************************************************

@ -127,7 +127,7 @@ void VCOM_TransferData(void)
static uint32_t last_ms = 0; static uint32_t last_ms = 0;
static uint32_t last_pos = 0; static uint32_t last_pos = 0;
if(Vcom.in_ready) // 可以向主机发送数据 if(GetEPTxStatus(ENDP3) == EP_TX_NAK) // 可以向主机发送数据
{ {
uint32_t pos = RXDMA_SZ - DMA_GetCurrDataCounter(DMA1_Channel6); uint32_t pos = RXDMA_SZ - DMA_GetCurrDataCounter(DMA1_Channel6);
if((pos - last_pos >= CDC_BULK_IN_SZ) || ((pos != last_pos) && (SysTick_ms != last_ms))) if((pos - last_pos >= CDC_BULK_IN_SZ) || ((pos != last_pos) && (SysTick_ms != last_ms)))
@ -140,8 +140,6 @@ void VCOM_TransferData(void)
Vcom.in_bytes = pos - last_pos; Vcom.in_bytes = pos - last_pos;
Vcom.in_ready = 0;
USB_SIL_Write(EP3_IN, &RXBuffer[last_pos], Vcom.in_bytes); USB_SIL_Write(EP3_IN, &RXBuffer[last_pos], Vcom.in_bytes);
SetEPTxValid(ENDP3); SetEPTxValid(ENDP3);
@ -164,16 +162,16 @@ void VCOM_TransferData(void)
} }
/* 从主机接收到数据,且前面的数据 DMA 已发送完 */ /* 从主机接收到数据,且前面的数据 DMA 已发送完 */
if(Vcom.out_ready && (DMA_GetCurrDataCounter(DMA1_Channel7) == 0)) if(Vcom.out_bytes && (DMA_GetCurrDataCounter(DMA1_Channel7) == 0))
{ {
Vcom.out_ready = 0;
memcpy(TXBuffer, (uint8_t *)Vcom.out_buff, Vcom.out_bytes); memcpy(TXBuffer, (uint8_t *)Vcom.out_buff, Vcom.out_bytes);
DMA_Cmd(DMA1_Channel7, DISABLE); DMA_Cmd(DMA1_Channel7, DISABLE);
DMA_SetCurrDataCounter(DMA1_Channel7, Vcom.out_bytes); DMA_SetCurrDataCounter(DMA1_Channel7, Vcom.out_bytes);
DMA_Cmd(DMA1_Channel7, ENABLE); DMA_Cmd(DMA1_Channel7, ENABLE);
Vcom.out_bytes = 0;
/* Ready for next BULK OUT */ /* Ready for next BULK OUT */
SetEPRxValid(ENDP3); SetEPRxValid(ENDP3);
} }

@ -7,11 +7,9 @@
typedef struct { typedef struct {
uint8_t rx_buff[RX_BUFF_SIZE]; uint8_t rx_buff[RX_BUFF_SIZE];
uint16_t rx_bytes;
uint16_t rx_wrptr; uint16_t rx_wrptr;
uint16_t rx_rdptr; uint16_t rx_rdptr;
uint8_t tx_buff[TX_BUFF_SIZE]; uint8_t tx_buff[TX_BUFF_SIZE];
uint16_t tx_bytes;
uint16_t tx_wrptr; uint16_t tx_wrptr;
uint16_t tx_rdptr; uint16_t tx_rdptr;
@ -19,10 +17,8 @@ typedef struct {
uint8_t in_buff[64]; uint8_t in_buff[64];
uint16_t in_bytes; uint16_t in_bytes;
uint16_t in_ready;
uint8_t out_buff[64]; uint8_t out_buff[64];
uint16_t out_bytes; uint16_t out_bytes;
uint16_t out_ready;
} VCOM; } VCOM;
extern volatile VCOM Vcom; extern volatile VCOM Vcom;

Binary file not shown.

File diff suppressed because it is too large Load Diff

@ -102,8 +102,6 @@ void USBHS_Device_Endp_Init(void)
USBHSD->UEP3_TX_LEN = 0; USBHSD->UEP3_TX_LEN = 0;
USBHSD->UEP3_TX_CTRL = USBHS_UEP_T_RES_NAK; USBHSD->UEP3_TX_CTRL = USBHS_UEP_T_RES_NAK;
USBHSD->UEP3_RX_CTRL = USBHS_UEP_R_RES_ACK; USBHSD->UEP3_RX_CTRL = USBHS_UEP_R_RES_ACK;
Vcom.in_ready = 1;
} }
@ -258,6 +256,11 @@ void USBHS_IRQHandler( void )
len = USB_StringSerialNbr[0]; len = USB_StringSerialNbr[0];
break; break;
case 4:
pUSBHS_Descr = USB_StringInterface;
len = USB_StringInterface[0];
break;
default: default:
error = 0xFF; error = 0xFF;
break; break;
@ -269,9 +272,12 @@ void USBHS_IRQHandler( void )
len = USB_QualifierDesc[0]; len = USB_QualifierDesc[0];
break; break;
#ifndef DAP_FW_V1
case USB_DESCR_TYP_BOS: case USB_DESCR_TYP_BOS:
error = 0xFF; pUSBHS_Descr = BOS_Descriptor;
len = BOS_Descriptor[0] + BOS_Descriptor[5];
break; break;
#endif
default : default :
error = 0xFF; error = 0xFF;
@ -433,16 +439,7 @@ void USBHS_IRQHandler( void )
break; break;
case HID_GET_REPORT: case HID_GET_REPORT:
if(USBHS_DevSpeed == USBHS_USB_SPEED_HIGH) error = 0xFF;
{
len = (USBHS_Setup.wLength >= USB_MAX_EP0_SZ) ? USB_MAX_EP0_SZ : USBHS_Setup.wLength;
memcpy(USBHS_EP0_Buf, HID_ReportDesc_HS, len);
}
else
{
len = (USBHS_Setup.wLength >= USB_MAX_EP0_SZ) ? USB_MAX_EP0_SZ : USBHS_Setup.wLength;
memcpy(USBHS_EP0_Buf, HID_ReportDesc_FS, len);
}
break; break;
case HID_SET_IDLE: case HID_SET_IDLE:
@ -451,7 +448,6 @@ void USBHS_IRQHandler( void )
case HID_GET_IDLE: case HID_GET_IDLE:
USBHS_EP0_Buf[0] = USBHS_HID_Idle; USBHS_EP0_Buf[0] = USBHS_HID_Idle;
len = 1;
break; break;
case HID_SET_PROTOCOL: case HID_SET_PROTOCOL:
@ -460,15 +456,13 @@ void USBHS_IRQHandler( void )
case HID_GET_PROTOCOL: case HID_GET_PROTOCOL:
USBHS_EP0_Buf[0] = USBHS_HID_Protocol; USBHS_EP0_Buf[0] = USBHS_HID_Protocol;
len = 1;
break; break;
case CDC_SET_LINE_CODING: case CDC_SET_LINE_CODING:
break; break;
case CDC_GET_LINE_CODING: case CDC_GET_LINE_CODING:
pUSBHS_Descr = (uint8_t *)&LineCfg; memcpy(USBHS_EP0_Buf, (uint8_t *)&LineCfg, 7);
len = 7;
break; break;
case CDC_SET_LINE_CTLSTE: case CDC_SET_LINE_CTLSTE:
@ -481,18 +475,28 @@ void USBHS_IRQHandler( void )
} }
else if(USBHS_Setup.bRequestType & USB_REQ_TYP_VENDOR) else if(USBHS_Setup.bRequestType & USB_REQ_TYP_VENDOR)
{ {
error = 0xFF; if((USBHS_Setup.bRequest == WINUSB_VENDOR_CODE) && (USBHS_Setup.wIndex == 7))
}
else
{ {
error = 0xFF; pUSBHS_Descr = MS_OS_20_DescriptorSet;
} len = MS_OS_20_DescriptorSet[8];
/* Copy Descriptors to Endp0 DMA buffer */ /* Copy Descriptors to Endp0 DMA buffer */
if(USBHS_Setup.wLength > len)
{
USBHS_Setup.wLength = len;
}
len = (USBHS_Setup.wLength >= USB_MAX_EP0_SZ) ? USB_MAX_EP0_SZ : USBHS_Setup.wLength; len = (USBHS_Setup.wLength >= USB_MAX_EP0_SZ) ? USB_MAX_EP0_SZ : USBHS_Setup.wLength;
memcpy(USBHS_EP0_Buf, pUSBHS_Descr, len); memcpy(USBHS_EP0_Buf, pUSBHS_Descr, len);
pUSBHS_Descr += len; pUSBHS_Descr += len;
} }
else
error = 0xFF;
}
else
{
error = 0xFF;
}
}
if(error == 0xFF) if(error == 0xFF)
{ {
@ -505,8 +509,8 @@ void USBHS_IRQHandler( void )
if(USBHS_Setup.bRequestType & USB_EPT_IN) if(USBHS_Setup.bRequestType & USB_EPT_IN)
{ {
len = (USBHS_Setup.wLength > USB_MAX_EP0_SZ) ? USB_MAX_EP0_SZ : USBHS_Setup.wLength; len = (USBHS_Setup.wLength > USB_MAX_EP0_SZ) ? USB_MAX_EP0_SZ : USBHS_Setup.wLength;
USBHS_Setup.wLength -= len; USBHS_Setup.wLength -= len;
USBHSD->UEP0_TX_LEN = len; USBHSD->UEP0_TX_LEN = len;
USBHSD->UEP0_TX_CTRL = USBHS_UEP_T_TOG_DATA1 | USBHS_UEP_T_RES_ACK; USBHSD->UEP0_TX_CTRL = USBHS_UEP_T_TOG_DATA1 | USBHS_UEP_T_RES_ACK;
} }
@ -564,6 +568,16 @@ void USBHS_IRQHandler( void )
break; break;
} }
} }
else if((USBHS_Setup.bRequestType & USB_REQ_TYP_MASK) == USB_REQ_TYP_VENDOR)
{
len = USBHS_Setup.wLength >= USB_MAX_EP0_SZ ? USB_MAX_EP0_SZ : USBHS_Setup.wLength;
memcpy(USBHS_EP0_Buf, pUSBHS_Descr, len);
USBHS_Setup.wLength -= len;
pUSBHS_Descr += len;
USBHSD->UEP0_TX_LEN = len;
USBHSD->UEP0_TX_CTRL ^= USBHS_UEP_T_TOG_DATA1;
}
else else
{ {
/* Non-standard request endpoint 0 Data upload */ /* Non-standard request endpoint 0 Data upload */
@ -585,8 +599,6 @@ void USBHS_IRQHandler( void )
case CDC_BULK_IN_EP & 0x0F: case CDC_BULK_IN_EP & 0x0F:
USBHSD->UEP3_TX_CTRL = (USBHSD->UEP3_TX_CTRL & ~USBHS_UEP_T_RES_MASK) | USBHS_UEP_T_RES_NAK; USBHSD->UEP3_TX_CTRL = (USBHSD->UEP3_TX_CTRL & ~USBHS_UEP_T_RES_MASK) | USBHS_UEP_T_RES_NAK;
USBHSD->UEP3_TX_CTRL ^= USBHS_UEP_T_TOG_DATA1; USBHSD->UEP3_TX_CTRL ^= USBHS_UEP_T_TOG_DATA1;
Vcom.in_ready = 1;
break; break;
default: default:
@ -617,10 +629,6 @@ void USBHS_IRQHandler( void )
VCOM_LineCoding(&LineCfg); VCOM_LineCoding(&LineCfg);
} }
else if(USBHS_Setup.bRequest == HID_SET_REPORT)
{
error = 0xFF;
}
} }
if(USBHS_Setup.wLength == 0) if(USBHS_Setup.wLength == 0)
@ -645,7 +653,6 @@ void USBHS_IRQHandler( void )
USBHSD->UEP3_RX_CTRL = (USBHSD->UEP3_RX_CTRL & ~USBHS_UEP_R_RES_MASK) | USBHS_UEP_R_RES_NAK; USBHSD->UEP3_RX_CTRL = (USBHSD->UEP3_RX_CTRL & ~USBHS_UEP_R_RES_MASK) | USBHS_UEP_R_RES_NAK;
Vcom.out_bytes = len; Vcom.out_bytes = len;
Vcom.out_ready = 1;
break; break;
default: default:

@ -97,7 +97,7 @@ const uint8_t USB_CfgDesc_FS[] =
#endif #endif
0x00, // bInterfaceSubClass 0x00, // bInterfaceSubClass
0x00, // bInterfaceProtocol 0x00, // bInterfaceProtocol
0x00, // iInterface 0x04, // iInterface
#ifdef DAP_FW_V1 #ifdef DAP_FW_V1
// HID Descriptor // HID Descriptor
@ -246,7 +246,7 @@ const uint8_t USB_CfgDesc_HS[] =
#endif #endif
0x00, // bInterfaceSubClass 0x00, // bInterfaceSubClass
0x00, // bInterfaceProtocol 0x00, // bInterfaceProtocol
0x00, // iInterface 0x04, // iInterface
#ifdef DAP_FW_V1 #ifdef DAP_FW_V1
// HID Descriptor // HID Descriptor
@ -410,6 +410,15 @@ uint8_t USB_StringSerialNbr[] =
}; };
/* Interface Descriptor */
const uint8_t USB_StringInterface[] =
{
USB_SIZE_STRING_PRODUCT,
USB_DESCR_TYP_STRING,
'X', 0, 'V', 0, '-', 0, 'L', 0, 'i', 0, 'n', 0, 'k', 0, ' ', 0, 'C', 0, 'M', 0, 'S', 0, 'I', 0, 'S', 0, '-', 0, 'D', 0, 'A', 0, 'P', 0
};
/* Device Qualified Descriptor */ /* Device Qualified Descriptor */
const uint8_t USB_QualifierDesc[] = const uint8_t USB_QualifierDesc[] =
{ {
@ -423,3 +432,75 @@ const uint8_t USB_QualifierDesc[] =
0x01, // bNumConfigurations 0x01, // bNumConfigurations
0x00, // bReserved 0x00, // bReserved
}; };
const uint8_t BOS_Descriptor[] =
{
5,
USB_DESCR_TYP_BOS,
5+20+8, 0, // wTotalLength
1, // bNumDeviceCaps
/*** MS OS 2.0 descriptor platform capability descriptor ***/
28,
DESC_CAPABILITY,
5, // bDevCapabilityType: PLATFORM (05H)
0x00,
0xDF, 0x60, 0xDD, 0xD8, // PlatformCapabilityUUID: MS_OS_20_Platform_Capability_ID (D8DD60DF-4589-4CC7-9CD2-659D9E648A9F)
0x89, 0x45, 0xC7, 0x4C,
0x9C, 0xD2, 0x65, 0x9D,
0x9E, 0x64, 0x8A, 0x9F,
0x00, 0x00, 0x03, 0x06, // dwWindowsVersion: 0x06030000 for Windows 8.1
10+8+20+128, 0x00, // wTotalLength: size of MS OS 2.0 descriptor set
WINUSB_VENDOR_CODE, // bMS_VendorCode
0x00, // bAltEnumCmd
};
#define MS_OS_20_SET_HEADER_DESCRIPTOR 0x00
#define MS_OS_20_SUBSET_HEADER_CONFIGURATION 0x01
#define MS_OS_20_SUBSET_HEADER_FUNCTION 0x02
#define MS_OS_20_FEATURE_COMPATIBLE_ID 0x03
#define MS_OS_20_FEATURE_REG_PROPERTY 0x04
#define MS_OS_20_FEATURE_MIN_RESUME_TIME 0x05
#define MS_OS_20_FEATURE_MODEL_ID 0x06
#define MS_OS_20_FEATURE_CCGP_DEVICE 0x07
#define MS_OS_20_FEATURE_VENDOR_REVISION 0x08
const uint8_t MS_OS_20_DescriptorSet[] =
{
/*** Microsoft OS 2.0 Descriptor Set Header ***/
10, 0,
MS_OS_20_SET_HEADER_DESCRIPTOR, 0,
0x00, 0x00, 0x03, 0x06, // dwWindowsVersion: 0x06030000 for Windows 8.1
10+8+20+128, 0, // wTotalLength
/*** Microsoft OS 2.0 function subset header ***/
8, 0,
MS_OS_20_SUBSET_HEADER_FUNCTION, 0,
0, // bFirstInterface, first interface to which this subset applies
0,
8+20+128, 0, // wSubsetLength
/*** Microsoft OS 2.0 compatible ID descriptor ***/
20, 0,
MS_OS_20_FEATURE_COMPATIBLE_ID, 0,
'W', 'I', 'N', 'U', 'S', 'B', 0x00, 0x00, // CompatibleID
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // SubCompatibleID
/*** MS OS 2.0 registry property descriptor ***/
128, 0,
MS_OS_20_FEATURE_REG_PROPERTY, 0,
1, 0, // wPropertyDataType: 1 = Unicode REG_SZ
40, 0x00, // wPropertyNameLength
'D', 0, 'e', 0, 'v', 0, 'i', 0, 'c', 0, 'e', 0, 'I', 0, 'n', 0, 't', 0, 'e', 0,
'r', 0, 'f', 0, 'a', 0, 'c', 0, 'e', 0, 'G', 0, 'U', 0, 'I', 0, 'D', 0, 0, 0, // PropertyName: "DeviceInterfaceGUID"
78, 0x00, // wPropertyDataLength
'{', 0, 'C', 0, 'D', 0, 'B', 0, '3', 0, 'B', 0, '5', 0, 'A', 0, 'D', 0, '-', 0,
'2', 0, '9', 0, '3', 0, 'B', 0, '-', 0, '4', 0, '6', 0, '6', 0, '3', 0, '-', 0,
'A', 0, 'A', 0, '3', 0, '6', 0, '-', 0, '1', 0, 'A', 0, 'A', 0, 'E', 0, '4', 0,
'6', 0, '4', 0, '6', 0, '3', 0, '7', 0, '7', 0, '6', 0, '}', 0, 0, 0, // PropertyData: "{CDB3B5AD-293B-4663-AA36-1AAE46463776}"
};

@ -63,9 +63,17 @@ extern const uint8_t USB_StringLangID[];
extern const uint8_t USB_StringVendor[]; extern const uint8_t USB_StringVendor[];
extern const uint8_t USB_StringProduct[]; extern const uint8_t USB_StringProduct[];
extern uint8_t USB_StringSerialNbr[]; extern uint8_t USB_StringSerialNbr[];
extern const uint8_t USB_StringInterface[];
extern const uint8_t USB_QualifierDesc[]; extern const uint8_t USB_QualifierDesc[];
extern const uint8_t HID_ReportDesc_FS[]; extern const uint8_t HID_ReportDesc_FS[];
extern const uint8_t HID_ReportDesc_HS[]; extern const uint8_t HID_ReportDesc_HS[];
extern const uint8_t BOS_Descriptor[];
extern const uint8_t MS_OS_20_DescriptorSet[];
#define DESC_CAPABILITY 0x10
#define WINUSB_VENDOR_CODE 0x34
#endif // __USB_DESC_H__ #endif // __USB_DESC_H__

@ -7,6 +7,12 @@
#include "hid_transfer.h" #include "hid_transfer.h"
/* 在 Properties for DAPLink -> C/C++ Build -> Settings -> C Compiler -> Preprocessor 中:
DAP_FW_V1 CMSIS-DAP v1 使 HID
DAP_FW_V1 CMSIS-DAP v2 使 WINUSB
*/
volatile uint32_t SysTick_ms = 0; volatile uint32_t SysTick_ms = 0;

@ -128,7 +128,7 @@ void VCOM_TransferData(void)
static uint32_t last_ms = 0; static uint32_t last_ms = 0;
static uint32_t last_pos = 0; static uint32_t last_pos = 0;
if(Vcom.in_ready) // 可以向主机发送数据 if((USBHSD->UEP3_TX_CTRL & USBHS_UEP_T_RES_MASK) == USBHS_UEP_T_RES_NAK) // 可以向主机发送数据
{ {
uint32_t pos = RXDMA_SZ - DMA_GetCurrDataCounter(DMA1_Channel3); uint32_t pos = RXDMA_SZ - DMA_GetCurrDataCounter(DMA1_Channel3);
if((pos - last_pos >= CDC_BULK_IN_SZ_HS) || ((pos != last_pos) && (SysTick_ms != last_ms))) if((pos - last_pos >= CDC_BULK_IN_SZ_HS) || ((pos != last_pos) && (SysTick_ms != last_ms)))
@ -141,8 +141,6 @@ void VCOM_TransferData(void)
Vcom.in_bytes = pos - last_pos; Vcom.in_bytes = pos - last_pos;
Vcom.in_ready = 0;
USBHSD->UEP3_TX_DMA = (uint32_t)&RXBuffer[last_pos]; USBHSD->UEP3_TX_DMA = (uint32_t)&RXBuffer[last_pos];
USBHSD->UEP3_TX_LEN = Vcom.in_bytes; USBHSD->UEP3_TX_LEN = Vcom.in_bytes;
USBHSD->UEP3_TX_CTRL = (USBHSD->UEP3_TX_CTRL & ~USBHS_UEP_T_RES_MASK) | USBHS_UEP_T_RES_ACK; USBHSD->UEP3_TX_CTRL = (USBHSD->UEP3_TX_CTRL & ~USBHS_UEP_T_RES_MASK) | USBHS_UEP_T_RES_ACK;
@ -167,16 +165,16 @@ void VCOM_TransferData(void)
xfer_out: xfer_out:
/* 从主机接收到数据,且前面的数据 DMA 已发送完 */ /* 从主机接收到数据,且前面的数据 DMA 已发送完 */
if(Vcom.out_ready && (DMA_GetCurrDataCounter(DMA1_Channel2) == 0)) if(Vcom.out_bytes && (DMA_GetCurrDataCounter(DMA1_Channel2) == 0))
{ {
Vcom.out_ready = 0;
memcpy(TXBuffer, USBHS_EP3_Rx_Buf, Vcom.out_bytes); memcpy(TXBuffer, USBHS_EP3_Rx_Buf, Vcom.out_bytes);
DMA_Cmd(DMA1_Channel2, DISABLE); DMA_Cmd(DMA1_Channel2, DISABLE);
DMA_SetCurrDataCounter(DMA1_Channel2, Vcom.out_bytes); DMA_SetCurrDataCounter(DMA1_Channel2, Vcom.out_bytes);
DMA_Cmd(DMA1_Channel2, ENABLE); DMA_Cmd(DMA1_Channel2, ENABLE);
Vcom.out_bytes = 0;
/* Ready for next BULK OUT */ /* Ready for next BULK OUT */
USBHSD->UEP3_RX_CTRL = (USBHSD->UEP3_RX_CTRL & ~USBHS_UEP_R_RES_MASK) | USBHS_UEP_R_RES_ACK; USBHSD->UEP3_RX_CTRL = (USBHSD->UEP3_RX_CTRL & ~USBHS_UEP_R_RES_MASK) | USBHS_UEP_R_RES_ACK;
} }

@ -7,11 +7,9 @@
typedef struct { typedef struct {
uint8_t rx_buff[RX_BUFF_SIZE]; uint8_t rx_buff[RX_BUFF_SIZE];
uint16_t rx_bytes;
uint16_t rx_wrptr; uint16_t rx_wrptr;
uint16_t rx_rdptr; uint16_t rx_rdptr;
uint8_t tx_buff[TX_BUFF_SIZE]; uint8_t tx_buff[TX_BUFF_SIZE];
uint16_t tx_bytes;
uint16_t tx_wrptr; uint16_t tx_wrptr;
uint16_t tx_rdptr; uint16_t tx_rdptr;
@ -19,10 +17,8 @@ typedef struct {
uint8_t in_buff[512]; uint8_t in_buff[512];
uint16_t in_bytes; uint16_t in_bytes;
uint16_t in_ready;
uint8_t out_buff[512]; uint8_t out_buff[512];
uint16_t out_bytes; uint16_t out_bytes;
uint16_t out_ready;
} VCOM; } VCOM;
extern volatile VCOM Vcom; extern volatile VCOM Vcom;

@ -44,6 +44,10 @@ Sch & PCB: [https://oshwhub.com/xivn1987/daplink](https://oshwhub.com/xivn1987/d
## DAPLink-CH32V305 ## DAPLink-CH32V305
DAPLink (CMSIS-DAP) based on WCH CH32V305 (High Speed USB with on-chip PHY), supports SWD, JTAG and CDC. DAPLink (CMSIS-DAP) based on WCH CH32V305 (High Speed USB with on-chip PHY), supports SWD, JTAG and CDC.
On Properties for DAPLink -> C/C++ Build -> Settings -> C Compiler -> Preprocessor page:
* 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 |
| :---- | :---- | | :---- | :---- |
@ -72,3 +76,4 @@ pyocd flash -t stm32f411ce -f 5mhz random_512k.bin
| CH32V203 HID | Erased 524288 bytes (8 sectors), programmed 524288 bytes (512 pages), skipped 0 bytes (0 pages) at 17.26 kB/s | | CH32V203 HID | Erased 524288 bytes (8 sectors), programmed 524288 bytes (512 pages), skipped 0 bytes (0 pages) at 17.26 kB/s |
| CH32V203 WINUSB | Erased 524288 bytes (8 sectors), programmed 524288 bytes (512 pages), skipped 0 bytes (0 pages) at 38.16 kB/s | | CH32V203 WINUSB | Erased 524288 bytes (8 sectors), programmed 524288 bytes (512 pages), skipped 0 bytes (0 pages) at 38.16 kB/s |
| CH32V305 HID | Erased 524288 bytes (8 sectors), programmed 524288 bytes (512 pages), skipped 0 bytes (0 pages) at 35.44 kB/s | | CH32V305 HID | Erased 524288 bytes (8 sectors), programmed 524288 bytes (512 pages), skipped 0 bytes (0 pages) at 35.44 kB/s |
| CH32V305 WINUSB | Erased 524288 bytes (8 sectors), programmed 524288 bytes (512 pages), skipped 0 bytes (0 pages) at 39.40 kB/s |

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 288 KiB

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 284 KiB

Loading…
Cancel
Save