commit
9318c1603f
9
Makefile
9
Makefile
|
@ -1,9 +0,0 @@
|
||||||
#
|
|
||||||
# This is a project Makefile. It is assumed the directory this Makefile resides in is a
|
|
||||||
# project subdirectory.
|
|
||||||
#
|
|
||||||
|
|
||||||
PROJECT_NAME := tcp_server
|
|
||||||
|
|
||||||
include $(IDF_PATH)/make/project.mk
|
|
||||||
|
|
|
@ -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)
|
__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;
|
uint32_t *pU32Data = (uint32_t *)&dataBuf;
|
||||||
|
|
||||||
DAP_SPI.user.usr_mosi = 0;
|
DAP_SPI.user.usr_mosi = 0;
|
||||||
|
|
|
@ -2,11 +2,12 @@
|
||||||
* @file MSOS20Descriptors.c
|
* @file MSOS20Descriptors.c
|
||||||
* @author windowsair
|
* @author windowsair
|
||||||
* @brief Store related data of Microsoft OS 2.0 descriptor
|
* @brief Store related data of Microsoft OS 2.0 descriptor
|
||||||
* @version 0.1
|
* @change: 2021-5-12 Add support for USB 3.0
|
||||||
* @date 2019-11-21
|
* @version 0.2
|
||||||
*
|
* @date 2021-5-12
|
||||||
* @copyright Copyright (c) 2019
|
*
|
||||||
*
|
* @copyright Copyright (c) 2021
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
////TODO: refactoring into structure
|
////TODO: refactoring into structure
|
||||||
|
@ -29,7 +30,7 @@ const uint8_t msOs20DescriptorSetHeader[kLengthOfMsOS20] =
|
||||||
|
|
||||||
// Support WinUSB
|
// Support WinUSB
|
||||||
// See https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/automatic-installation-of-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)
|
// Microsoft OS 2.0 compatible ID descriptor (Table 13)
|
||||||
0x14, 0x00, // wLength
|
0x14, 0x00, // wLength
|
||||||
USBShort(MS_OS_20_FEATURE_COMPATIBLE_ID), // wDescriptorType
|
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)
|
0x07, 0x00, // wPropertyDataType: REG_MULTI_SZ (Unicode Strings)
|
||||||
0x2A, 0x00, // wPropertyNameLength
|
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,
|
'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
|
// Set to "DeviceInterfaceGUID" to support WinUSB
|
||||||
0x50, 0x00, // wPropertyDataLength
|
0x50, 0x00, // wPropertyDataLength
|
||||||
// WinUSB GUID
|
// 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,
|
'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,
|
'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,
|
'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,
|
// identify a CMSIS-DAP V2 configuration,
|
||||||
// must set to "{CDB3B5AD-293B-4663-AA36-1AAE46463776}"
|
// must set to "{CDB3B5AD-293B-4663-AA36-1AAE46463776}"
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const uint8_t bosDescriptor[kLengthOfBos] =
|
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
|
0x05, // bLength of this descriptor
|
||||||
USB_DESCRIPTOR_TYPE_BOS, // BOS Descriptor type(Constant)
|
USB_DESCRIPTOR_TYPE_BOS, // BOS Descriptor type(Constant)
|
||||||
USBShort(kLengthOfBos), // wLength
|
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
|
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)
|
// Microsoft OS 2.0 platform capability descriptor header (Table 4)
|
||||||
// See also:
|
// 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
|
0x1C, // bLength of this first device capability descriptor
|
||||||
// bLength -> The total length of the remaining arrays containing this field
|
// bLength -> The total length of the remaining arrays containing this field
|
||||||
USB_DESCRIPTOR_TYPE_DEVICE_CAPABILITY, // bDescriptorType
|
USB_DESCRIPTOR_TYPE_DEVICE_CAPABILITY, // bDescriptorType
|
||||||
USB_DEVICE_CAPABILITY_TYPE_PLATFORM, // bDevCapabilityType
|
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
|
0x00, // bReserved
|
||||||
USB_DEVICE_CAPABILITY_UUID, // MS_OS_20_Platform_Capability_ID
|
USB_DEVICE_CAPABILITY_UUID, // MS_OS_20_Platform_Capability_ID
|
||||||
|
|
||||||
|
|
|
@ -1,19 +1,27 @@
|
||||||
/**
|
/**
|
||||||
* @file MSOS20Descriptors.h
|
* @file MSOS20Descriptors.h
|
||||||
* @author windowsair
|
* @author windowsair
|
||||||
* @brief
|
* @brief
|
||||||
* @version 0.1
|
* @version 0.2
|
||||||
* @date 2019-11-21
|
* @date 2021-5-12
|
||||||
*
|
*
|
||||||
* @copyright Copyright (c) 2019
|
* @copyright Copyright (c) 2021
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __MSOS20DESCRIPTORS_H__
|
#ifndef __MSOS20DESCRIPTORS_H__
|
||||||
#define __MSOS20DESCRIPTORS_H__
|
#define __MSOS20DESCRIPTORS_H__
|
||||||
|
|
||||||
|
#include "dap_configuration.h"
|
||||||
|
|
||||||
#define kLengthOfMsOS20 0xA2
|
#define kLengthOfMsOS20 0xA2
|
||||||
|
|
||||||
|
#if (USE_USB_3_0 == 1)
|
||||||
|
#define kLengthOfBos 0x32
|
||||||
|
#else
|
||||||
#define kLengthOfBos 0x21
|
#define kLengthOfBos 0x21
|
||||||
|
#endif // USE_USB_3_0 == 1
|
||||||
|
|
||||||
#define kValueOfbMS_VendorCode 0x01// Just set to 0x01
|
#define kValueOfbMS_VendorCode 0x01// Just set to 0x01
|
||||||
extern const uint8_t bosDescriptor[kLengthOfBos];
|
extern const uint8_t bosDescriptor[kLengthOfBos];
|
||||||
extern const uint8_t msOs20DescriptorSetHeader[kLengthOfMsOS20];
|
extern const uint8_t msOs20DescriptorSetHeader[kLengthOfMsOS20];
|
||||||
|
@ -23,6 +31,11 @@ extern const uint8_t msOs20DescriptorSetHeader[kLengthOfMsOS20];
|
||||||
// Platform capability BOS descriptor, Table 1.
|
// Platform capability BOS descriptor, Table 1.
|
||||||
#define USB_DEVICE_CAPABILITY_TYPE_PLATFORM 5
|
#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.
|
// Platform capability UUID, Table 3.
|
||||||
// {D8DD60DF-4589-4CC7-9CD2-659D9E648A9F}
|
// {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
|
#define USB_DEVICE_CAPABILITY_UUID 0xDF, 0x60, 0xDD, 0xD8, 0x89, 0x45, 0xC7, 0x4C, 0x9C, 0xD2, 0x65, 0x9D, 0x9E, 0x64, 0x8A, 0x9F
|
||||||
|
|
|
@ -2,23 +2,24 @@
|
||||||
/**
|
/**
|
||||||
* @file USBd_config.c
|
* @file USBd_config.c
|
||||||
* @brief Standard USB Descriptor Definitions
|
* @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
|
* @version 0.2
|
||||||
* @date 2020-1-23
|
* @date 2020-1-23
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include "USBd_config.h"
|
#include "USBd_config.h"
|
||||||
#include "usb_defs.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
|
* @brief step 1. Build Standard Device Descriptor
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Standard Device Descriptor
|
// Standard Device Descriptor
|
||||||
|
@ -28,18 +29,28 @@ const uint8_t kUSBd0DeviceDescriptor[0x12] =
|
||||||
USB_DT_DEVICE, // bDescriptorType
|
USB_DT_DEVICE, // bDescriptorType
|
||||||
|
|
||||||
#if (USE_WINUSB == 1)
|
#if (USE_WINUSB == 1)
|
||||||
USBShort(0x0210), // bcdUSB
|
|
||||||
|
#if (USE_USB_3_0 == 1)
|
||||||
|
USBShort(0x0300), // bcdUSB
|
||||||
#else
|
#else
|
||||||
USBShort(0x0200), // bcdUSB
|
USBShort(0x210), // bcdUSB
|
||||||
#endif
|
#endif // USE_USB_3_0 == 1
|
||||||
|
|
||||||
|
#else
|
||||||
|
USBShort(0x0200), // bcdUSB
|
||||||
|
#endif // (USE_WINUSB == 1)
|
||||||
////TODO: Is it also available elsewhere?
|
////TODO: Is it also available elsewhere?
|
||||||
|
|
||||||
// We need to use a device other than the USB-IF standard, set to 0x00
|
// We need to use a device other than the USB-IF standard, set to 0x00
|
||||||
0x00, // bDeviceClass
|
0x00, // bDeviceClass
|
||||||
0x00, // bDeviceSubClass
|
0x00, // bDeviceSubClass
|
||||||
0x00, // bDeviceProtocol
|
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.
|
USBD0_MAX_PACKET0, // bMaxPacketSize0 Maximum packet size for default pipe.
|
||||||
|
#endif
|
||||||
USBShort(USBD0_DEV_DESC_IDVENDOR), // idVendor Vendor ID (VID).
|
USBShort(USBD0_DEV_DESC_IDVENDOR), // idVendor Vendor ID (VID).
|
||||||
USBShort(USBD0_DEV_DESC_IDPRODUCT), // idProduct Product ID (PID).
|
USBShort(USBD0_DEV_DESC_IDPRODUCT), // idProduct Product ID (PID).
|
||||||
USBShort(USBD0_DEV_DESC_BCDDEVICE), // bcdDevice Device Version BCD.
|
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
|
* @brief step 2. Buid Standard Configuration Descriptor
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
// Standard Interface Descriptor
|
// Standard Interface Descriptor
|
||||||
|
|
||||||
#if (USE_WINUSB ==1)
|
#if (USE_WINUSB ==1)
|
||||||
const uint8_t kUSBd0InterfaceDescriptor[0x1E]=
|
const uint8_t kUSBd0InterfaceDescriptor[]=
|
||||||
{
|
{
|
||||||
0x09, // bLength
|
0x09, // bLength
|
||||||
USB_DT_INTERFACE, // bDescriptorType
|
USB_DT_INTERFACE, // bDescriptorType
|
||||||
USBD_CUSTOM_CLASS0_IF0_NUM, // bInterfaceNumber
|
USBD_CUSTOM_CLASS0_IF0_NUM, // bInterfaceNumber
|
||||||
USBD_CUSTOM_CLASS0_IF0_ALT, // bAlternateSetting
|
USBD_CUSTOM_CLASS0_IF0_ALT, // bAlternateSetting
|
||||||
0x03, // bNumEndpoints(we will use 3 endpoints)
|
0x03, // bNumEndpoints(we will use 3 endpoints)
|
||||||
//
|
//
|
||||||
USBD_CUSTOM_CLASS0_IF0_CLASS, // bInterfaceClass
|
USBD_CUSTOM_CLASS0_IF0_CLASS, // bInterfaceClass
|
||||||
USBD_CUSTOM_CLASS0_IF0_SUBCLASS, // bInterfaceSubClass
|
USBD_CUSTOM_CLASS0_IF0_SUBCLASS, // bInterfaceSubClass
|
||||||
USBD_CUSTOM_CLASS0_IF0_PROTOCOL, // bInterfaceProtocol
|
USBD_CUSTOM_CLASS0_IF0_PROTOCOL, // bInterfaceProtocol
|
||||||
0x00, // iInterface
|
0x00, // iInterface
|
||||||
// Index of string descriptor describing this interface
|
// Index of string descriptor describing this interface
|
||||||
////TODO: fix this 0x04 ?
|
////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 1: Bulk Out – used for commands received from host PC.
|
||||||
// Endpoint 2: Bulk In – used for responses send to host PC.
|
// Endpoint 2: Bulk In – used for responses send to host PC.
|
||||||
// Endpoint 3: Bulk In (optional) – used for streaming SWO trace
|
// 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 indeed included two "endpoints": Bulk OUT and Bulk IN
|
||||||
// physical endpoint 1 -> Endpoint 1 & Endpoint 2
|
// physical endpoint 1 -> Endpoint 1 & Endpoint 2
|
||||||
// physical endpoint 2 -> Endpoint 3
|
// physical endpoint 2 -> Endpoint 3
|
||||||
|
|
||||||
// See also :
|
// 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 */
|
/* Pysical endpoint 1 */
|
||||||
|
|
||||||
// "Endpoint 1: Bulk Out – used for commands received from host PC." PC -> Device
|
// "Endpoint 1: Bulk Out – used for commands received from host PC." PC -> Device
|
||||||
0x07, // bLength
|
0x07, // bLength
|
||||||
USB_DT_ENDPOINT, // bDescriptorType
|
USB_DT_ENDPOINT, // bDescriptorType
|
||||||
0x01, // bEndpointAddress
|
0x01, // bEndpointAddress
|
||||||
USB_ENDPOINT_ATTR_BULK, // bmAttributes
|
USB_ENDPOINT_ATTR_BULK, // bmAttributes
|
||||||
USBShort(512), // wMaxPacketSize
|
USBShort(USB_ENDPOINT_SIZE), // wMaxPacketSize
|
||||||
// We assume that it always runs in High Speed.
|
0x00, // bInterval
|
||||||
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 */
|
/* Pysical endpoint 1 */
|
||||||
|
|
||||||
// "Endpoint 2: Bulk In – used for responses send to host PC." Device -> PC
|
// "Endpoint 2: Bulk In – used for responses send to host PC." Device -> PC
|
||||||
0x07, // bLength
|
0x07, // bLength
|
||||||
USB_DT_ENDPOINT, // bDescriptorType
|
USB_DT_ENDPOINT, // bDescriptorType
|
||||||
0x81, // bEndpointAddress
|
0x81, // bEndpointAddress
|
||||||
USB_ENDPOINT_ATTR_BULK, // bmAttributes
|
USB_ENDPOINT_ATTR_BULK, // bmAttributes
|
||||||
USBShort(512), // wMaxPacketSize
|
USBShort(USB_ENDPOINT_SIZE), // wMaxPacketSize
|
||||||
0x00, // bInterval
|
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 */
|
/* 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
|
0x09, // bLength
|
||||||
USB_DT_INTERFACE, // bDescriptorType
|
USB_DT_INTERFACE, // bDescriptorType
|
||||||
USBD_CUSTOM_CLASS0_IF0_NUM, // bInterfaceNumber
|
USBD_CUSTOM_CLASS0_IF0_NUM, // bInterfaceNumber
|
||||||
USBD_CUSTOM_CLASS0_IF0_ALT, // bAlternateSetting
|
USBD_CUSTOM_CLASS0_IF0_ALT, // bAlternateSetting
|
||||||
0x02, // bNumEndpoints ----> 2 endpoint for USB HID
|
0x02, // bNumEndpoints ----> 2 endpoint for USB HID
|
||||||
//
|
//
|
||||||
USBD_CUSTOM_CLASS0_IF0_CLASS, // bInterfaceClass
|
USBD_CUSTOM_CLASS0_IF0_CLASS, // bInterfaceClass
|
||||||
USBD_CUSTOM_CLASS0_IF0_SUBCLASS, // bInterfaceSubClass
|
USBD_CUSTOM_CLASS0_IF0_SUBCLASS, // bInterfaceSubClass
|
||||||
USBD_CUSTOM_CLASS0_IF0_PROTOCOL, // bInterfaceProtocol
|
USBD_CUSTOM_CLASS0_IF0_PROTOCOL, // bInterfaceProtocol
|
||||||
0x00, // iInterface
|
0x00, // iInterface
|
||||||
// Index of string descriptor describing this interface
|
// Index of string descriptor describing this interface
|
||||||
|
|
||||||
// HID Descriptor
|
// HID Descriptor
|
||||||
0x09, // bLength
|
0x09, // bLength
|
||||||
0x21, // bDescriptorType
|
0x21, // bDescriptorType
|
||||||
|
@ -147,29 +185,29 @@ const uint8_t kUSBd0InterfaceDescriptor[0x20]=
|
||||||
0x00, // bCountryCode
|
0x00, // bCountryCode
|
||||||
0x01, // bNumDescriptors
|
0x01, // bNumDescriptors
|
||||||
0x22, // bDescriptorType1
|
0x22, // bDescriptorType1
|
||||||
0x21, 0x00, // wDescriptorLength1
|
0x21, 0x00, // wDescriptorLength1
|
||||||
|
|
||||||
// Standard Endpoint Descriptor
|
// Standard Endpoint Descriptor
|
||||||
|
|
||||||
// We perform all transfer operations on Pysical endpoint 1.
|
// We perform all transfer operations on Pysical endpoint 1.
|
||||||
|
|
||||||
/* Pysical endpoint 1 */
|
/* Pysical endpoint 1 */
|
||||||
|
|
||||||
0x07, // bLength
|
0x07, // bLength
|
||||||
USB_DT_ENDPOINT, // bDescriptorType
|
USB_DT_ENDPOINT, // bDescriptorType
|
||||||
0x81, // bEndpointAddress
|
0x81, // bEndpointAddress
|
||||||
USB_ENDPOINT_ATTR_INTERRUPT, // bmAttributes
|
USB_ENDPOINT_ATTR_INTERRUPT, // bmAttributes
|
||||||
USBShort(64), // wMaxPacketSize
|
USBShort(64), // wMaxPacketSize
|
||||||
0x01, // bInterval
|
0x01, // bInterval
|
||||||
|
|
||||||
/* Pysical endpoint 1 */
|
/* Pysical endpoint 1 */
|
||||||
|
|
||||||
0x07, // bLength
|
0x07, // bLength
|
||||||
USB_DT_ENDPOINT, // bDescriptorType
|
USB_DT_ENDPOINT, // bDescriptorType
|
||||||
0x01, // bEndpointAddress
|
0x01, // bEndpointAddress
|
||||||
USB_ENDPOINT_ATTR_INTERRUPT, // bmAttributes
|
USB_ENDPOINT_ATTR_INTERRUPT, // bmAttributes
|
||||||
USBShort(64), // wMaxPacketSize
|
USBShort(64), // wMaxPacketSize
|
||||||
0x01, // bInterval
|
0x01, // bInterval
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -182,12 +220,12 @@ const uint8_t kUSBd0ConfigDescriptor[LENGTHOFCONFIGDESCRIPTOR] =
|
||||||
// Configuration descriptor header.
|
// Configuration descriptor header.
|
||||||
|
|
||||||
0x09, // bLength
|
0x09, // bLength
|
||||||
USB_DT_CONFIGURATION, // bDescriptorType
|
USB_DT_CONFIGURATION, // bDescriptorType
|
||||||
|
|
||||||
USBShort((sizeof(kUSBd0InterfaceDescriptor)) + (LENGTHOFCONFIGDESCRIPTOR)),
|
USBShort((sizeof(kUSBd0InterfaceDescriptor)) + (LENGTHOFCONFIGDESCRIPTOR)),
|
||||||
// wTotalLength
|
// wTotalLength
|
||||||
|
|
||||||
0x01, // bNumInterfaces
|
0x01, // bNumInterfaces
|
||||||
// There is only one interface in the CMSIS-DAP project
|
// There is only one interface in the CMSIS-DAP project
|
||||||
0x01, // bConfigurationValue: 0x01 is used to select this configuration */
|
0x01, // bConfigurationValue: 0x01 is used to select this configuration */
|
||||||
0x00, // iConfiguration: no string to describe this configuration */
|
0x00, // iConfiguration: no string to describe this configuration */
|
||||||
|
@ -202,12 +240,12 @@ const uint8_t kUSBd0ConfigDescriptor[LENGTHOFCONFIGDESCRIPTOR] =
|
||||||
// Configuration descriptor header.
|
// Configuration descriptor header.
|
||||||
|
|
||||||
0x09, // bLength
|
0x09, // bLength
|
||||||
USB_DT_CONFIGURATION, // bDescriptorType
|
USB_DT_CONFIGURATION, // bDescriptorType
|
||||||
|
|
||||||
USBShort((sizeof(kUSBd0InterfaceDescriptor)) + (LENGTHOFCONFIGDESCRIPTOR)),
|
USBShort((sizeof(kUSBd0InterfaceDescriptor)) + (LENGTHOFCONFIGDESCRIPTOR)),
|
||||||
// wTotalLength
|
// wTotalLength
|
||||||
|
|
||||||
0x01, // bNumInterfaces
|
0x01, // bNumInterfaces
|
||||||
// There is only one interface in the CMSIS-DAP project
|
// There is only one interface in the CMSIS-DAP project
|
||||||
0x01, // bConfigurationValue: 0x01 is used to select this configuration */
|
0x01, // bConfigurationValue: 0x01 is used to select this configuration */
|
||||||
0x00, // iConfiguration: no string to describe 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
|
* @brief step 3. Build String Descriptor
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
@ -265,7 +303,7 @@ const uint8_t kLangDescriptor[0x04] =
|
||||||
* 3. Serial number string -> "0001A0000000"
|
* 3. Serial number string -> "0001A0000000"
|
||||||
* 4. Interface string -> "LPC-Link-II CMSIS-DAP"
|
* 4. Interface string -> "LPC-Link-II CMSIS-DAP"
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const uint8_t kManufacturerString[0x28] =
|
const uint8_t kManufacturerString[0x28] =
|
||||||
|
@ -286,7 +324,7 @@ const uint8_t kProductString[0x18] =
|
||||||
'I', 0
|
'I', 0
|
||||||
};
|
};
|
||||||
|
|
||||||
const uint8_t kSerialNumberString[0x1A] =
|
const uint8_t kSerialNumberString[0x1A] =
|
||||||
{
|
{
|
||||||
0x1A, // bLength
|
0x1A, // bLength
|
||||||
0x03, // bDescriptorType
|
0x03, // bDescriptorType
|
||||||
|
@ -301,7 +339,7 @@ const uint8_t kInterfaceString[0x2C] =
|
||||||
0x03, // bDescriptorType
|
0x03, // bDescriptorType
|
||||||
// "LPC-Link-II CMSIS-DAP"
|
// "LPC-Link-II CMSIS-DAP"
|
||||||
'L', 0, 'P', 0, 'C', 0, '-', 0, 'L', 0, 'i', 0, 'n', 0, 'k', 0, '-', 0, 'I', 0,
|
'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
|
'P', 0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,13 @@ extern const uint8_t kProductString[0x18];
|
||||||
extern const uint8_t kSerialNumberString[0x1A];
|
extern const uint8_t kSerialNumberString[0x1A];
|
||||||
|
|
||||||
#if (USE_WINUSB == 1)
|
#if (USE_WINUSB == 1)
|
||||||
|
|
||||||
|
#if (USE_USB_3_0 == 1)
|
||||||
|
extern const uint8_t kUSBd0InterfaceDescriptor[0x30];
|
||||||
|
#else
|
||||||
extern const uint8_t kUSBd0InterfaceDescriptor[0x1E];
|
extern const uint8_t kUSBd0InterfaceDescriptor[0x1E];
|
||||||
|
#endif // USE_USB_3_0 == 1
|
||||||
|
|
||||||
extern const uint8_t kUSBd0ConfigDescriptor[0x09];
|
extern const uint8_t kUSBd0ConfigDescriptor[0x09];
|
||||||
extern const uint8_t kInterfaceString[0x2C];
|
extern const uint8_t kInterfaceString[0x2C];
|
||||||
|
|
||||||
|
|
|
@ -3,9 +3,9 @@
|
||||||
* @brief Modify
|
* @brief Modify
|
||||||
* @version 0.1
|
* @version 0.1
|
||||||
* @date 2020-01-22
|
* @date 2020-01-22
|
||||||
*
|
*
|
||||||
* @copyright Copyright (c) 2020
|
* @copyright Copyright (c) 2020
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -119,6 +119,7 @@ typedef struct
|
||||||
#define USB_DT_OTHER_SPEED_CONFIGURATION 7
|
#define USB_DT_OTHER_SPEED_CONFIGURATION 7
|
||||||
#define USB_DT_INTERFACE_POWER 8
|
#define USB_DT_INTERFACE_POWER 8
|
||||||
#define USB_DT_BOS 15
|
#define USB_DT_BOS 15
|
||||||
|
#define USB_DT_SUPERSPEED_USB_ENDPOINT_COMPANION 48
|
||||||
/* From ECNs */
|
/* From ECNs */
|
||||||
#define USB_DT_OTG 9
|
#define USB_DT_OTG 9
|
||||||
#define USB_DT_DEBUG 10
|
#define USB_DT_DEBUG 10
|
||||||
|
@ -234,7 +235,7 @@ typedef struct
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////
|
||||||
/* USB Standard Endpoint Descriptor - Table 9-13 */
|
/* USB Standard Endpoint Descriptor - Table 9-13 */
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
uint8_t bLength;
|
uint8_t bLength;
|
||||||
uint8_t bDescriptorType;
|
uint8_t bDescriptorType;
|
||||||
|
|
|
@ -31,44 +31,40 @@
|
||||||
#include "lwip/sys.h"
|
#include "lwip/sys.h"
|
||||||
#include <lwip/netdb.h>
|
#include <lwip/netdb.h>
|
||||||
|
|
||||||
|
#if (USE_WINUSB == 1)
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint32_t length;
|
||||||
|
uint8_t buf[DAP_PACKET_SIZE];
|
||||||
|
} DapPacket_t;
|
||||||
|
#else
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint8_t buf[DAP_PACKET_SIZE];
|
||||||
|
} DapPacket_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define DAP_HANDLE_SIZE (sizeof(DapPacket_t))
|
||||||
|
|
||||||
|
|
||||||
extern int kSock;
|
extern int kSock;
|
||||||
extern TaskHandle_t kDAPTaskHandle;
|
extern TaskHandle_t kDAPTaskHandle;
|
||||||
|
|
||||||
int kRestartDAPHandle = 0;
|
int kRestartDAPHandle = 0;
|
||||||
|
|
||||||
|
|
||||||
#if (USE_WINUSB == 1)
|
static DapPacket_t DAPDataProcessed;
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
uint32_t length;
|
|
||||||
uint8_t buf[DAP_PACKET_SIZE];
|
|
||||||
} DAPPacetDataType;
|
|
||||||
#else
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
uint8_t buf[DAP_PACKET_SIZE];
|
|
||||||
} DAPPacetDataType;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#define DAP_HANDLE_SIZE (sizeof(DAPPacetDataType))
|
|
||||||
|
|
||||||
static DAPPacetDataType DAPDataProcessed;
|
|
||||||
static int dap_respond = 0;
|
static int dap_respond = 0;
|
||||||
|
|
||||||
|
|
||||||
// SWO Trace
|
// SWO Trace
|
||||||
static uint8_t *swo_data_to_send = NULL;
|
static uint8_t *swo_data_to_send = NULL;
|
||||||
static uint32_t swo_data_num;
|
static uint32_t swo_data_num;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// DAP handle
|
// DAP handle
|
||||||
static RingbufHandle_t dap_dataIN_handle = NULL;
|
static RingbufHandle_t dap_dataIN_handle = NULL;
|
||||||
static RingbufHandle_t dap_dataOUT_handle = NULL;
|
static RingbufHandle_t dap_dataOUT_handle = NULL;
|
||||||
static SemaphoreHandle_t data_response_mux = NULL;
|
static SemaphoreHandle_t data_response_mux = NULL;
|
||||||
|
|
||||||
static void unpack(void *data, int size);
|
|
||||||
|
|
||||||
void handle_dap_data_request(usbip_stage2_header *header, uint32_t length)
|
void handle_dap_data_request(usbip_stage2_header *header, uint32_t length)
|
||||||
{
|
{
|
||||||
|
@ -149,7 +145,7 @@ void DAP_Thread(void *argument)
|
||||||
data_response_mux = xSemaphoreCreateMutex();
|
data_response_mux = xSemaphoreCreateMutex();
|
||||||
size_t packetSize;
|
size_t packetSize;
|
||||||
int resLength;
|
int resLength;
|
||||||
DAPPacetDataType *item;
|
DapPacket_t *item;
|
||||||
|
|
||||||
if (dap_dataIN_handle == NULL || dap_dataIN_handle == NULL ||
|
if (dap_dataIN_handle == NULL || dap_dataIN_handle == NULL ||
|
||||||
data_response_mux == NULL)
|
data_response_mux == NULL)
|
||||||
|
@ -180,8 +176,8 @@ void DAP_Thread(void *argument)
|
||||||
|
|
||||||
ulTaskNotifyTake(pdFALSE, portMAX_DELAY);
|
ulTaskNotifyTake(pdFALSE, portMAX_DELAY);
|
||||||
packetSize = 0;
|
packetSize = 0;
|
||||||
item = (DAPPacetDataType *)xRingbufferReceiveUpTo(dap_dataIN_handle, &packetSize,
|
item = (DapPacket_t *)xRingbufferReceiveUpTo(dap_dataIN_handle, &packetSize,
|
||||||
pdMS_TO_TICKS(1), DAP_HANDLE_SIZE);
|
pdMS_TO_TICKS(1), DAP_HANDLE_SIZE);
|
||||||
if (packetSize == 0)
|
if (packetSize == 0)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
|
@ -201,14 +197,14 @@ void DAP_Thread(void *argument)
|
||||||
}
|
}
|
||||||
|
|
||||||
resLength = DAP_ProcessCommand((uint8_t *)item->buf, (uint8_t *)DAPDataProcessed.buf); // use first 4 byte to save length
|
resLength = DAP_ProcessCommand((uint8_t *)item->buf, (uint8_t *)DAPDataProcessed.buf); // use first 4 byte to save length
|
||||||
resLength &= 0xFFFF; // res length in lower 16 bits
|
resLength &= 0xFFFF; // res length in lower 16 bits
|
||||||
|
|
||||||
vRingbufferReturnItem(dap_dataIN_handle, (void *)item); // process done.
|
vRingbufferReturnItem(dap_dataIN_handle, (void *)item); // process done.
|
||||||
|
|
||||||
// now prepare to reply
|
// now prepare to reply
|
||||||
#if (USE_WINUSB == 1)
|
#if (USE_WINUSB == 1)
|
||||||
DAPDataProcessed.length = resLength;
|
DAPDataProcessed.length = resLength;
|
||||||
#endif
|
#endif
|
||||||
xRingbufferSend(dap_dataOUT_handle, (void *)&DAPDataProcessed, DAP_HANDLE_SIZE, portMAX_DELAY);
|
xRingbufferSend(dap_dataOUT_handle, (void *)&DAPDataProcessed, DAP_HANDLE_SIZE, portMAX_DELAY);
|
||||||
|
|
||||||
if (xSemaphoreTake(data_response_mux, portMAX_DELAY) == pdTRUE)
|
if (xSemaphoreTake(data_response_mux, portMAX_DELAY) == pdTRUE)
|
||||||
|
@ -222,25 +218,25 @@ void DAP_Thread(void *argument)
|
||||||
|
|
||||||
int fast_reply(uint8_t *buf, uint32_t length)
|
int fast_reply(uint8_t *buf, uint32_t length)
|
||||||
{
|
{
|
||||||
if (length == 48 && buf[3] == 1 && buf[15] == 1 && buf[19] == 1)
|
usbip_stage2_header *buf_header = (usbip_stage2_header *)buf;
|
||||||
|
if (length == 48 &&
|
||||||
|
buf_header->base.command == PP_HTONL(USBIP_STAGE2_REQ_SUBMIT) &&
|
||||||
|
buf_header->base.direction == PP_HTONL(USBIP_DIR_IN) &&
|
||||||
|
buf_header->base.ep == PP_HTONL(1))
|
||||||
{
|
{
|
||||||
if (dap_respond > 0)
|
if (dap_respond > 0)
|
||||||
{
|
{
|
||||||
DAPPacetDataType *item;
|
DapPacket_t *item;
|
||||||
size_t packetSize = 0;
|
size_t packetSize = 0;
|
||||||
item = (DAPPacetDataType *)xRingbufferReceiveUpTo(dap_dataOUT_handle, &packetSize,
|
item = (DapPacket_t *)xRingbufferReceiveUpTo(dap_dataOUT_handle, &packetSize,
|
||||||
pdMS_TO_TICKS(10), DAP_HANDLE_SIZE);
|
pdMS_TO_TICKS(10), DAP_HANDLE_SIZE);
|
||||||
if (packetSize == DAP_HANDLE_SIZE)
|
if (packetSize == DAP_HANDLE_SIZE)
|
||||||
{
|
{
|
||||||
unpack((uint32_t *)buf, sizeof(usbip_stage2_header));
|
#if (USE_WINUSB == 1)
|
||||||
|
send_stage2_submit_data_fast((usbip_stage2_header *)buf, item->buf, item->length);
|
||||||
#if (USE_WINUSB == 1)
|
#else
|
||||||
uint32_t resLength = item->length;
|
send_stage2_submit_data_fast((usbip_stage2_header *)buf, item->buf, DAP_HANDLE_SIZE);
|
||||||
send_stage2_submit_data_fast((usbip_stage2_header *)buf, 0, item->buf, resLength);
|
#endif
|
||||||
#else
|
|
||||||
send_stage2_submit_data_fast((usbip_stage2_header *)buf, 0, item->buf, DAP_HANDLE_SIZE);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
if (xSemaphoreTake(data_response_mux, portMAX_DELAY) == pdTRUE)
|
if (xSemaphoreTake(data_response_mux, portMAX_DELAY) == pdTRUE)
|
||||||
{
|
{
|
||||||
|
@ -259,28 +255,14 @@ int fast_reply(uint8_t *buf, uint32_t length)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//// TODO: ep0 dir 0 ?
|
buf_header->base.command = PP_HTONL(USBIP_STAGE2_RSP_SUBMIT);
|
||||||
buf[0x3] = 0x3; // command
|
buf_header->base.direction = PP_HTONL(USBIP_DIR_OUT);
|
||||||
buf[0xF] = 0; // direction
|
buf_header->u.ret_submit.status = 0;
|
||||||
buf[0x16] = 0;
|
buf_header->u.ret_submit.data_length = 0;
|
||||||
buf[0x17] = 0;
|
buf_header->u.ret_submit.error_count = 0;
|
||||||
buf[27] = 0;
|
|
||||||
buf[39] = 0;
|
|
||||||
send(kSock, buf, 48, 0);
|
send(kSock, buf, 48, 0);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void unpack(void *data, int size)
|
|
||||||
{
|
|
||||||
// Ignore the setup field
|
|
||||||
int sz = (size / sizeof(uint32_t)) - 2;
|
|
||||||
uint32_t *ptr = (uint32_t *)data;
|
|
||||||
|
|
||||||
for (int i = 0; i < sz; i++)
|
|
||||||
{
|
|
||||||
ptr[i] = ntohl(ptr[i]);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -13,6 +13,21 @@
|
||||||
*/
|
*/
|
||||||
#define USE_SPI_SIO 1
|
#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.
|
/// Maximum Package Size for Command and Response data.
|
||||||
/// This configuration settings is used to optimize the communication performance with the
|
/// 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,
|
/// debugger and depends on the USB peripheral. Typical vales are 64 for Full-speed USB HID or WinUSB,
|
||||||
|
|
|
@ -3,9 +3,9 @@
|
||||||
* @brief Handle main tcp tasks
|
* @brief Handle main tcp tasks
|
||||||
* @version 0.1
|
* @version 0.1
|
||||||
* @date 2020-01-22
|
* @date 2020-01-22
|
||||||
*
|
*
|
||||||
* @copyright Copyright (c) 2020
|
* @copyright Copyright (c) 2020
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#include "tcp_server.h"
|
#include "tcp_server.h"
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ int kSock = -1;
|
||||||
|
|
||||||
void tcp_server_task(void *pvParameters)
|
void tcp_server_task(void *pvParameters)
|
||||||
{
|
{
|
||||||
uint8_t tcp_rx_buffer[1024];
|
uint8_t tcp_rx_buffer[1500];
|
||||||
char addr_str[128];
|
char addr_str[128];
|
||||||
int addr_family;
|
int addr_family;
|
||||||
int ip_protocol;
|
int ip_protocol;
|
||||||
|
|
|
@ -339,7 +339,7 @@ void send_stage2_submit(usbip_stage2_header *req_header, int32_t status, int32_t
|
||||||
|
|
||||||
req_header->u.ret_submit.status = status;
|
req_header->u.ret_submit.status = status;
|
||||||
req_header->u.ret_submit.data_length = data_length;
|
req_header->u.ret_submit.data_length = data_length;
|
||||||
|
// already unpacked
|
||||||
pack(req_header, sizeof(usbip_stage2_header));
|
pack(req_header, sizeof(usbip_stage2_header));
|
||||||
send(kSock, req_header, sizeof(usbip_stage2_header), 0);
|
send(kSock, req_header, sizeof(usbip_stage2_header), 0);
|
||||||
}
|
}
|
||||||
|
@ -355,19 +355,16 @@ void send_stage2_submit_data(usbip_stage2_header *req_header, int32_t status, co
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void send_stage2_submit_data_fast(usbip_stage2_header *req_header, int32_t status, const void *const data, int32_t data_length)
|
void send_stage2_submit_data_fast(usbip_stage2_header *req_header, const void *const data, int32_t data_length)
|
||||||
{
|
{
|
||||||
uint8_t * send_buf = (uint8_t *)req_header;
|
uint8_t * send_buf = (uint8_t *)req_header;
|
||||||
|
|
||||||
req_header->base.command = USBIP_STAGE2_RSP_SUBMIT;
|
req_header->base.command = PP_HTONL(USBIP_STAGE2_RSP_SUBMIT);
|
||||||
req_header->base.direction = !(req_header->base.direction);
|
req_header->base.direction = htonl(!(req_header->base.direction));
|
||||||
|
|
||||||
memset(&(req_header->u.ret_submit), 0, sizeof(usbip_stage2_header_ret_submit));
|
memset(&(req_header->u.ret_submit), 0, sizeof(usbip_stage2_header_ret_submit));
|
||||||
|
req_header->u.ret_submit.data_length = htonl(data_length);
|
||||||
|
|
||||||
req_header->u.ret_submit.status = status;
|
|
||||||
req_header->u.ret_submit.data_length = data_length;
|
|
||||||
|
|
||||||
pack(req_header, sizeof(usbip_stage2_header));
|
|
||||||
|
|
||||||
// payload
|
// payload
|
||||||
memcpy(&send_buf[sizeof(usbip_stage2_header)], data, data_length);
|
memcpy(&send_buf[sizeof(usbip_stage2_header)], data, data_length);
|
||||||
|
|
|
@ -15,7 +15,7 @@ int attach(uint8_t *buffer, uint32_t length);
|
||||||
int emulate(uint8_t *buffer, uint32_t length);
|
int emulate(uint8_t *buffer, uint32_t length);
|
||||||
void send_stage2_submit_data(usbip_stage2_header *req_header, int32_t status, const void * const data, int32_t data_length);
|
void send_stage2_submit_data(usbip_stage2_header *req_header, int32_t status, const void * const data, int32_t data_length);
|
||||||
void send_stage2_submit(usbip_stage2_header *req_header, int32_t status, int32_t data_length);
|
void send_stage2_submit(usbip_stage2_header *req_header, int32_t status, int32_t data_length);
|
||||||
void send_stage2_submit_data_fast(usbip_stage2_header *req_header, int32_t status, const void *const data, int32_t data_length);
|
void send_stage2_submit_data_fast(usbip_stage2_header *req_header, const void *const data, int32_t data_length);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
Loading…
Reference in New Issue