0
0
Fork 0

feat: Add support for USB 3.0

This commit is contained in:
windowsair 2021-05-13 00:23:20 +08:00
parent c4bacc62ce
commit c9113ee08f
9 changed files with 199 additions and 99 deletions

View File

@ -182,7 +182,7 @@ __FORCEINLINE void DAP_SPI_Send_Header(const uint8_t packetHeaderData, uint8_t *
*/
__FORCEINLINE void DAP_SPI_Read_Data(uint32_t *resData, uint8_t *resParity)
{
uint64_t dataBuf;
volatile uint64_t dataBuf;
uint32_t *pU32Data = (uint32_t *)&dataBuf;
DAP_SPI.user.usr_mosi = 0;

View File

@ -2,11 +2,12 @@
* @file MSOS20Descriptors.c
* @author windowsair
* @brief Store related data of Microsoft OS 2.0 descriptor
* @version 0.1
* @date 2019-11-21
*
* @copyright Copyright (c) 2019
*
* @change: 2021-5-12 Add support for USB 3.0
* @version 0.2
* @date 2021-5-12
*
* @copyright Copyright (c) 2021
*
*/
////TODO: refactoring into structure
@ -29,7 +30,7 @@ const uint8_t msOs20DescriptorSetHeader[kLengthOfMsOS20] =
// Support WinUSB
// See https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/automatic-installation-of-winusb
// Microsoft OS 2.0 compatible ID descriptor (Table 13)
0x14, 0x00, // wLength
USBShort(MS_OS_20_FEATURE_COMPATIBLE_ID), // wDescriptorType
@ -42,37 +43,63 @@ const uint8_t msOs20DescriptorSetHeader[kLengthOfMsOS20] =
0x07, 0x00, // wPropertyDataType: REG_MULTI_SZ (Unicode Strings)
0x2A, 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,'s',0,0,0,
'f',0,'a',0,'c',0,'e',0,'G',0,'U',0,'I',0,'D',0,'s',0,0,0,
// Set to "DeviceInterfaceGUID" to support WinUSB
0x50, 0x00, // wPropertyDataLength
// WinUSB GUID
'{',0,'C',0,'D',0,'B',0,'3',0,'B',0,'5',0,'A',0,'D',0,'-',0,
'{',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,0,0,
// identify a CMSIS-DAP V2 configuration,
// must set to "{CDB3B5AD-293B-4663-AA36-1AAE46463776}"
};
const uint8_t bosDescriptor[kLengthOfBos] =
{
// Universal Serial Bus 3.0 Specification, Table 9-9.
// USB 3.0 Specification, Table 9-9.
0x05, // bLength of this descriptor
USB_DESCRIPTOR_TYPE_BOS, // BOS Descriptor type(Constant)
USBShort(kLengthOfBos), // wLength
#if (USE_USB_3_0 == 1)
0x03, // bNumDeviceCaps -> USB2.0 extension & SuperSpeed USB Device & OS2.0 descriptor
#else
0x01, // bNumDeviceCaps -> only 0x01 for OS2.0 descriptor
#endif // USE_USB_3_0 == 1
#if (USE_USB_3_0 == 1)
// USB 2.0 extension, USB 3.0 Specification, Table 9-12.
0x07, // bLength of this descriptor
USB_DESCRIPTOR_TYPE_DEVICE_CAPABILITY, // DEVICE CAPABILITY Descriptor type
USB_DEVICE_CAPABILITY_TYPE_USB2_0_EXTENSION, // Capability type: USB 2.0 EXTENSION
0x02, 0x00, 0x00, 0x00, // bmAttributes -> LPM Support
// SuperSpeed USB Device, USB 3.0 Specification, Table 9-13.
0x0A, // bLength of this descriptor
USB_DESCRIPTOR_TYPE_DEVICE_CAPABILITY, // DEVICE CAPABILITY Descriptor type
USB_DEVICE_CAPABILITY_TYPE_SUPERSPEED_USB, // Capability type: SUPERSPEED_USB
0x00, // bmAttributes -> LTM Capable
0x08, 0x00, // wSpeedsSupported -> only support SuperSpeed
0x03, // bFunctionalitySupport
0x00, // bU1DevExitLat -> 0 may be ok
0x00, 0x00, // wU2DevExitLat -> 0 may be ok
#endif // USE_USB_3_0 == 1
// Microsoft OS 2.0 platform capability descriptor header (Table 4)
// See also:
// Universal Serial Bus 3.0 Specification : Format of a Device Capability Descriptor, Table 9-10.
// USB 3.0 Specification : Format of a Device Capability Descriptor, Table 9-10.
0x1C, // bLength of this first device capability descriptor
// bLength -> The total length of the remaining arrays containing this field
USB_DESCRIPTOR_TYPE_DEVICE_CAPABILITY, // bDescriptorType
USB_DEVICE_CAPABILITY_TYPE_PLATFORM, // bDevCapabilityType
// Capability-Dependent (See USB3.0 Specification Table 9-10.)
// Capability-Dependent (See USB 3.0 Specification Table 9-10.)
0x00, // bReserved
USB_DEVICE_CAPABILITY_UUID, // MS_OS_20_Platform_Capability_ID

View File

@ -1,19 +1,27 @@
/**
* @file MSOS20Descriptors.h
* @author windowsair
* @brief
* @version 0.1
* @date 2019-11-21
*
* @copyright Copyright (c) 2019
*
* @brief
* @version 0.2
* @date 2021-5-12
*
* @copyright Copyright (c) 2021
*
*/
#ifndef __MSOS20DESCRIPTORS_H__
#define __MSOS20DESCRIPTORS_H__
#include "dap_configuration.h"
#define kLengthOfMsOS20 0xA2
#if (USE_USB_3_0 == 1)
#define kLengthOfBos 0x32
#else
#define kLengthOfBos 0x21
#endif // USE_USB_3_0 == 1
#define kValueOfbMS_VendorCode 0x01// Just set to 0x01
extern const uint8_t bosDescriptor[kLengthOfBos];
extern const uint8_t msOs20DescriptorSetHeader[kLengthOfMsOS20];
@ -23,6 +31,11 @@ extern const uint8_t msOs20DescriptorSetHeader[kLengthOfMsOS20];
// Platform capability BOS descriptor, Table 1.
#define USB_DEVICE_CAPABILITY_TYPE_PLATFORM 5
// USB 2.0 Extension Descriptor, USB3.0 Specification Table 9-11
#define USB_DEVICE_CAPABILITY_TYPE_USB2_0_EXTENSION 2
// SuperSpeed USB specific device level capabilities, USB3.0 Specification Table 9-11
#define USB_DEVICE_CAPABILITY_TYPE_SUPERSPEED_USB 3
// Platform capability UUID, Table 3.
// {D8DD60DF-4589-4CC7-9CD2-659D9E648A9F}
#define USB_DEVICE_CAPABILITY_UUID 0xDF, 0x60, 0xDD, 0xD8, 0x89, 0x45, 0xC7, 0x4C, 0x9C, 0xD2, 0x65, 0x9D, 0x9E, 0x64, 0x8A, 0x9F

View File

@ -2,23 +2,24 @@
/**
* @file USBd_config.c
* @brief Standard USB Descriptor Definitions
fix bugs 2020-1-23
* @change: 2020-1-23 : fix bugs
* 2021-5-12 : Add support for USB 3.0
* @version 0.2
* @date 2020-1-23
*
*
*
*
*/
#include <stdint.h>
#include <stdbool.h>
#include "USBd_config.h"
#include "usb_defs.h"
#define USBShort(ui16Value) ((ui16Value) & 0xff), ((ui16Value) >> 8) //((ui16Value) & 0xFF),(((ui16Value) >> 8) & 0xFF)
#define USBShort(ui16Value) ((ui16Value) & 0xff), ((ui16Value) >> 8)
/**
* @brief step 1. Build Standard Device Descriptor
*
*
*/
// Standard Device Descriptor
@ -28,18 +29,28 @@ const uint8_t kUSBd0DeviceDescriptor[0x12] =
USB_DT_DEVICE, // bDescriptorType
#if (USE_WINUSB == 1)
USBShort(0x0210), // bcdUSB
#if (USE_USB_3_0 == 1)
USBShort(0x0300), // bcdUSB
#else
USBShort(0x0200), // bcdUSB
#endif
USBShort(0x210), // bcdUSB
#endif // USE_USB_3_0 == 1
#else
USBShort(0x0200), // bcdUSB
#endif // (USE_WINUSB == 1)
////TODO: Is it also available elsewhere?
// We need to use a device other than the USB-IF standard, set to 0x00
0x00, // bDeviceClass
0x00, // bDeviceSubClass
0x00, // bDeviceProtocol
#if (USE_USB_3_0 == 1)
0x09, // bMaxPacketSize0, for USB 3.0 must set to 0x09(2^9)
#else
USBD0_MAX_PACKET0, // bMaxPacketSize0 Maximum packet size for default pipe.
#endif
USBShort(USBD0_DEV_DESC_IDVENDOR), // idVendor Vendor ID (VID).
USBShort(USBD0_DEV_DESC_IDPRODUCT), // idProduct Product ID (PID).
USBShort(USBD0_DEV_DESC_BCDDEVICE), // bcdDevice Device Version BCD.
@ -54,25 +65,25 @@ const uint8_t kUSBd0DeviceDescriptor[0x12] =
/**
* @brief step 2. Buid Standard Configuration Descriptor
*
*
*/
// Standard Interface Descriptor
#if (USE_WINUSB ==1)
const uint8_t kUSBd0InterfaceDescriptor[0x1E]=
const uint8_t kUSBd0InterfaceDescriptor[]=
{
0x09, // bLength
USB_DT_INTERFACE, // bDescriptorType
USBD_CUSTOM_CLASS0_IF0_NUM, // bInterfaceNumber
USBD_CUSTOM_CLASS0_IF0_ALT, // bAlternateSetting
USBD_CUSTOM_CLASS0_IF0_NUM, // bInterfaceNumber
USBD_CUSTOM_CLASS0_IF0_ALT, // bAlternateSetting
0x03, // bNumEndpoints(we will use 3 endpoints)
//
USBD_CUSTOM_CLASS0_IF0_CLASS, // bInterfaceClass
USBD_CUSTOM_CLASS0_IF0_SUBCLASS, // bInterfaceSubClass
//
USBD_CUSTOM_CLASS0_IF0_CLASS, // bInterfaceClass
USBD_CUSTOM_CLASS0_IF0_SUBCLASS, // bInterfaceSubClass
USBD_CUSTOM_CLASS0_IF0_PROTOCOL, // bInterfaceProtocol
0x00, // iInterface
0x00, // iInterface
// Index of string descriptor describing this interface
////TODO: fix this 0x04 ?
@ -82,46 +93,73 @@ const uint8_t kUSBd0InterfaceDescriptor[0x1E]=
// Endpoint 1: Bulk Out used for commands received from host PC.
// Endpoint 2: Bulk In used for responses send to host PC.
// Endpoint 3: Bulk In (optional) used for streaming SWO trace
// ATTENTION:
// ATTENTION:
// physical endpoint 1 indeed included two "endpoints": Bulk OUT and Bulk IN
// physical endpoint 1 -> Endpoint 1 & Endpoint 2
// physical endpoint 2 -> Endpoint 3
// See also :
// http://www.keil.com/pack/doc/CMSIS/DAP/html/group__DAP__ConfigUSB__gr.html
// http://www.keil.com/pack/doc/CMSIS/DAP/html/group__DAP__ConfigUSB__gr.html
/* Pysical endpoint 1 */
// "Endpoint 1: Bulk Out used for commands received from host PC." PC -> Device
0x07, // bLength
USB_DT_ENDPOINT, // bDescriptorType
0x07, // bLength
USB_DT_ENDPOINT, // bDescriptorType
0x01, // bEndpointAddress
USB_ENDPOINT_ATTR_BULK, // bmAttributes
USBShort(512), // wMaxPacketSize
// We assume that it always runs in High Speed.
0x00, // bInterval
USB_ENDPOINT_ATTR_BULK, // bmAttributes
USBShort(USB_ENDPOINT_SIZE), // wMaxPacketSize
0x00, // bInterval
/* SuperSpeed Endpoint Companion */
#if (USE_USB_3_0 == 1)
0x06, // bLength
USB_DT_SUPERSPEED_USB_ENDPOINT_COMPANION, // bDescriptorType
0x00, // bMaxBurst
0x00, // bmAttributes(MaxStream for Bulk)
0x00, 0x00, // wBytesPerInterval -> 0 for Bulk
#endif // USE_USB_3_0 == 1
/* Pysical endpoint 1 */
// "Endpoint 2: Bulk In used for responses send to host PC." Device -> PC
0x07, // bLength
USB_DT_ENDPOINT, // bDescriptorType
0x07, // bLength
USB_DT_ENDPOINT, // bDescriptorType
0x81, // bEndpointAddress
USB_ENDPOINT_ATTR_BULK, // bmAttributes
USBShort(512), // wMaxPacketSize
0x00, // bInterval
USB_ENDPOINT_ATTR_BULK, // bmAttributes
USBShort(USB_ENDPOINT_SIZE), // wMaxPacketSize
0x00, // bInterval
/* SuperSpeed Endpoint Companion */
#if (USE_USB_3_0 == 1)
0x06, // bLength
USB_DT_SUPERSPEED_USB_ENDPOINT_COMPANION, // bDescriptorType
0x00, // bMaxBurst
0x00, // bmAttributes(MaxStream for Bulk)
0x00, 0x00, // wBytesPerInterval -> 0 for Bulk
#endif // USE_USB_3_0 == 1
/* Pysical endpoint 2 */
// "Endpoint 3: Bulk In (optional) used for streaming SWO trace" Device -> PC
0x07, // bLength
USB_DT_ENDPOINT, // bDescriptorType
0x82, // bEndpointAddress
USB_ENDPOINT_ATTR_BULK, // bmAttributes
USBShort(512), // wMaxPacketSize
0x00, // bInterval
// "Endpoint 3: Bulk In (optional) used for streaming SWO trace" Device -> PC
0x07, // bLength
USB_DT_ENDPOINT, // bDescriptorType
0x82, // bEndpointAddress
USB_ENDPOINT_ATTR_BULK, // bmAttributes
USBShort(USB_ENDPOINT_SIZE), // wMaxPacketSize
0x00, // bInterval
/* SuperSpeed Endpoint Companion */
#if (USE_USB_3_0 == 1)
0x06, // bLength
USB_DT_SUPERSPEED_USB_ENDPOINT_COMPANION, // bDescriptorType
0x00, // bMaxBurst
0x00, // bmAttributes(MaxStream for Bulk)
0x00, 0x00, // wBytesPerInterval -> 0 for Bulk
#endif // USE_USB_3_0 == 1
};
@ -130,16 +168,16 @@ const uint8_t kUSBd0InterfaceDescriptor[0x20]=
{
0x09, // bLength
USB_DT_INTERFACE, // bDescriptorType
USBD_CUSTOM_CLASS0_IF0_NUM, // bInterfaceNumber
USBD_CUSTOM_CLASS0_IF0_ALT, // bAlternateSetting
USBD_CUSTOM_CLASS0_IF0_NUM, // bInterfaceNumber
USBD_CUSTOM_CLASS0_IF0_ALT, // bAlternateSetting
0x02, // bNumEndpoints ----> 2 endpoint for USB HID
//
USBD_CUSTOM_CLASS0_IF0_CLASS, // bInterfaceClass
USBD_CUSTOM_CLASS0_IF0_SUBCLASS, // bInterfaceSubClass
//
USBD_CUSTOM_CLASS0_IF0_CLASS, // bInterfaceClass
USBD_CUSTOM_CLASS0_IF0_SUBCLASS, // bInterfaceSubClass
USBD_CUSTOM_CLASS0_IF0_PROTOCOL, // bInterfaceProtocol
0x00, // iInterface
0x00, // iInterface
// Index of string descriptor describing this interface
// HID Descriptor
0x09, // bLength
0x21, // bDescriptorType
@ -147,29 +185,29 @@ const uint8_t kUSBd0InterfaceDescriptor[0x20]=
0x00, // bCountryCode
0x01, // bNumDescriptors
0x22, // bDescriptorType1
0x21, 0x00, // wDescriptorLength1
0x21, 0x00, // wDescriptorLength1
// Standard Endpoint Descriptor
// We perform all transfer operations on Pysical endpoint 1.
/* Pysical endpoint 1 */
0x07, // bLength
USB_DT_ENDPOINT, // bDescriptorType
0x07, // bLength
USB_DT_ENDPOINT, // bDescriptorType
0x81, // bEndpointAddress
USB_ENDPOINT_ATTR_INTERRUPT, // bmAttributes
USBShort(64), // wMaxPacketSize
0x01, // bInterval
USB_ENDPOINT_ATTR_INTERRUPT, // bmAttributes
USBShort(64), // wMaxPacketSize
0x01, // bInterval
/* Pysical endpoint 1 */
0x07, // bLength
USB_DT_ENDPOINT, // bDescriptorType
0x07, // bLength
USB_DT_ENDPOINT, // bDescriptorType
0x01, // bEndpointAddress
USB_ENDPOINT_ATTR_INTERRUPT, // bmAttributes
USBShort(64), // wMaxPacketSize
0x01, // bInterval
USB_ENDPOINT_ATTR_INTERRUPT, // bmAttributes
USBShort(64), // wMaxPacketSize
0x01, // bInterval
};
#endif
@ -182,12 +220,12 @@ const uint8_t kUSBd0ConfigDescriptor[LENGTHOFCONFIGDESCRIPTOR] =
// Configuration descriptor header.
0x09, // bLength
USB_DT_CONFIGURATION, // bDescriptorType
USBShort((sizeof(kUSBd0InterfaceDescriptor)) + (LENGTHOFCONFIGDESCRIPTOR)),
USB_DT_CONFIGURATION, // bDescriptorType
USBShort((sizeof(kUSBd0InterfaceDescriptor)) + (LENGTHOFCONFIGDESCRIPTOR)),
// wTotalLength
0x01, // bNumInterfaces
0x01, // bNumInterfaces
// There is only one interface in the CMSIS-DAP project
0x01, // bConfigurationValue: 0x01 is used to select this configuration */
0x00, // iConfiguration: no string to describe this configuration */
@ -202,12 +240,12 @@ const uint8_t kUSBd0ConfigDescriptor[LENGTHOFCONFIGDESCRIPTOR] =
// Configuration descriptor header.
0x09, // bLength
USB_DT_CONFIGURATION, // bDescriptorType
USBShort((sizeof(kUSBd0InterfaceDescriptor)) + (LENGTHOFCONFIGDESCRIPTOR)),
USB_DT_CONFIGURATION, // bDescriptorType
USBShort((sizeof(kUSBd0InterfaceDescriptor)) + (LENGTHOFCONFIGDESCRIPTOR)),
// wTotalLength
0x01, // bNumInterfaces
0x01, // bNumInterfaces
// There is only one interface in the CMSIS-DAP project
0x01, // bConfigurationValue: 0x01 is used to select this configuration */
0x00, // iConfiguration: no string to describe this configuration */
@ -246,7 +284,7 @@ const uint8_t kHidReportDescriptor[0x21] = {
/**
* @brief step 3. Build String Descriptor
*
*
*/
@ -265,7 +303,7 @@ const uint8_t kLangDescriptor[0x04] =
* 3. Serial number string -> "0001A0000000"
* 4. Interface string -> "LPC-Link-II CMSIS-DAP"
*
*
*
*/
const uint8_t kManufacturerString[0x28] =
@ -286,7 +324,7 @@ const uint8_t kProductString[0x18] =
'I', 0
};
const uint8_t kSerialNumberString[0x1A] =
const uint8_t kSerialNumberString[0x1A] =
{
0x1A, // bLength
0x03, // bDescriptorType
@ -301,7 +339,7 @@ const uint8_t kInterfaceString[0x2C] =
0x03, // bDescriptorType
// "LPC-Link-II CMSIS-DAP"
'L', 0, 'P', 0, 'C', 0, '-', 0, 'L', 0, 'i', 0, 'n', 0, 'k', 0, '-', 0, 'I', 0,
'I', 0, ' ', 0, 'C', 0, 'M', 0, 'S', 0, 'I', 0, 'S', 0, '-', 0, 'D', 0, 'A', 0,
'I', 0, ' ', 0, 'C', 0, 'M', 0, 'S', 0, 'I', 0, 'S', 0, '-', 0, 'D', 0, 'A', 0,
'P', 0
};

View File

@ -51,7 +51,13 @@ extern const uint8_t kProductString[0x18];
extern const uint8_t kSerialNumberString[0x1A];
#if (USE_WINUSB == 1)
#if (USE_USB_3_0 == 1)
extern const uint8_t kUSBd0InterfaceDescriptor[0x30];
#else
extern const uint8_t kUSBd0InterfaceDescriptor[0x1E];
#endif // USE_USB_3_0 == 1
extern const uint8_t kUSBd0ConfigDescriptor[0x09];
extern const uint8_t kInterfaceString[0x2C];

View File

@ -3,9 +3,9 @@
* @brief Modify
* @version 0.1
* @date 2020-01-22
*
*
* @copyright Copyright (c) 2020
*
*
*/
//
@ -119,6 +119,7 @@ typedef struct
#define USB_DT_OTHER_SPEED_CONFIGURATION 7
#define USB_DT_INTERFACE_POWER 8
#define USB_DT_BOS 15
#define USB_DT_SUPERSPEED_USB_ENDPOINT_COMPANION 48
/* From ECNs */
#define USB_DT_OTG 9
#define USB_DT_DEBUG 10
@ -234,7 +235,7 @@ typedef struct
///////////////////////////////////////////////////////////////
/* USB Standard Endpoint Descriptor - Table 9-13 */
typedef struct
typedef struct
{
uint8_t bLength;
uint8_t bDescriptorType;

View File

@ -13,6 +13,21 @@
*/
#define USE_SPI_SIO 1
/**
* @brief Specify to enable USB 3.0
*
*/
#define USE_USB_3_0 0
// For USB 3.0, it must be 1024 byte.
#if (USE_USB_3_0 == 1)
#define USB_ENDPOINT_SIZE 1024U
#else
#define USB_ENDPOINT_SIZE 512U
#endif
/// Maximum Package Size for Command and Response data.
/// This configuration settings is used to optimize the communication performance with the
/// debugger and depends on the USB peripheral. Typical vales are 64 for Full-speed USB HID or WinUSB,

View File

@ -3,9 +3,9 @@
* @brief Handle main tcp tasks
* @version 0.1
* @date 2020-01-22
*
*
* @copyright Copyright (c) 2020
*
*
*/
#include "tcp_server.h"
@ -37,7 +37,7 @@ int kSock = -1;
void tcp_server_task(void *pvParameters)
{
uint8_t tcp_rx_buffer[1024];
uint8_t tcp_rx_buffer[1500];
char addr_str[128];
int addr_family;
int ip_protocol;