fix: Fixed some rookie mistakes
This is a temporary "stable" release. See the Readme.md file in the root directory for more instructions.
This commit is contained in:
parent
1070f63074
commit
ad6b9b3609
10
README.md
10
README.md
|
@ -1,5 +1,7 @@
|
|||
# Setup
|
||||
1. DAP_Setup()
|
||||
2. Server begin
|
||||
# Attention
|
||||
|
||||
# Loop
|
||||
At present, the adaptation to WCID, WinUSB, etc. has all been completed. However, when transmitting data on the endpoint, we received an error message from USBIP. This is most likely a problem with the USBIP project itself.
|
||||
|
||||
Due to the completeness of the USBIP protocol document, we have not yet understood its role in the Bulk transmission process, which may also lead to errors in subsequent processes.
|
||||
|
||||
We will continue to try to make it work under USB HID. Once the USBIP problem is solved, we will immediately transfer it to work under WinUSB
|
|
@ -29,6 +29,7 @@
|
|||
#define __DAP_CONFIG_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include "cmsis_compiler.h"
|
||||
#include "gpio.h"
|
||||
#include "gpio_struct.h"
|
||||
|
@ -153,8 +154,9 @@ __STATIC_INLINE uint8_t DAP_GetVendorString(char *str)
|
|||
////TODO: fill this
|
||||
// In fact, Keil can get the corresponding information through USB
|
||||
// without filling in this information.
|
||||
(void)str;
|
||||
return (0U);
|
||||
// (void)str;
|
||||
strcpy(str, "windowsair");
|
||||
return (sizeof("windowsair"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -165,8 +167,9 @@ __STATIC_INLINE uint8_t DAP_GetVendorString(char *str)
|
|||
*/
|
||||
__STATIC_INLINE uint8_t DAP_GetProductString(char *str)
|
||||
{
|
||||
(void)str;
|
||||
return (0U);
|
||||
//(void)str;
|
||||
strcpy(str, "CMSIS-DAP v2");
|
||||
return (sizeof("CMSIS-DAP v2"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -177,8 +180,8 @@ __STATIC_INLINE uint8_t DAP_GetProductString(char *str)
|
|||
*/
|
||||
__STATIC_INLINE uint8_t DAP_GetSerNumString(char *str)
|
||||
{
|
||||
(void)str;
|
||||
return (0U);
|
||||
strcpy(str, "1234");
|
||||
return (sizeof("1234"));
|
||||
}
|
||||
|
||||
///@}
|
||||
|
|
|
@ -1,4 +1,2 @@
|
|||
# TODO
|
||||
1. adapt to special hardware
|
||||
2. USB
|
||||
3. Significant Bit is difficult to judge, may need to dive into the details of usbip
|
||||
1. USB
|
|
@ -19,6 +19,12 @@
|
|||
#include "usb_defs.h"
|
||||
#include "MSOS20Descriptors.h"
|
||||
|
||||
const char *strings_list[] = {
|
||||
0, // reserved: available languages
|
||||
"windowsair",
|
||||
"CMSIS-DAP v2",
|
||||
"1234",
|
||||
};
|
||||
// handle functions
|
||||
static void handleGetDescriptor(usbip_stage2_header *header);
|
||||
|
||||
|
@ -192,7 +198,7 @@ static void handleGetDescriptor(usbip_stage2_header *header)
|
|||
{
|
||||
case USB_DT_DEVICE: // get device descriptor
|
||||
os_printf("* GET 0x01 DEVICE DESCRIPTOR\r\n");
|
||||
send_stage2_submit_data(header, 0, kUSBd0DeviceDescriptor, sizeof(kUSBd0DeviceDescriptor));
|
||||
send_stage2_submit_data(header, 0, &kUSBd0DeviceDescriptor[0], sizeof(kUSBd0DeviceDescriptor));
|
||||
break;
|
||||
|
||||
case USB_DT_CONFIGURATION: // get configuration descriptor
|
||||
|
@ -223,9 +229,29 @@ static void handleGetDescriptor(usbip_stage2_header *header)
|
|||
os_printf("** REQUESTED list of supported languages\r\n");
|
||||
send_stage2_submit_data(header, 0, kLangDescriptor, sizeof(kLangDescriptor));
|
||||
}
|
||||
else if (header->u.cmd_submit.request.wValue.u8lo != 0xee)
|
||||
{
|
||||
os_printf("low bit : %d\r\n", (int)header->u.cmd_submit.request.wValue.u8lo);
|
||||
os_printf("high bit : %d\r\n", (int)header->u.cmd_submit.request.wValue.u8hi);
|
||||
int slen = strlen(strings_list[header->u.cmd_submit.request.wValue.u8lo]);
|
||||
int wslen = slen * 2;
|
||||
int buff_len = sizeof(usb_string_descriptor) + wslen;
|
||||
char temp_buff[256];
|
||||
usb_string_descriptor *desc = (usb_string_descriptor *)temp_buff;
|
||||
desc->bLength = buff_len;
|
||||
desc->bDescriptorType = USB_DT_STRING;
|
||||
for (int i = 0; i < slen; i++)
|
||||
{
|
||||
desc->wData[i] = strings_list[header->u.cmd_submit.request.wValue.u8lo][i];
|
||||
send_stage2_submit_data(header, 0, (uint8_t *)temp_buff, buff_len);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
os_printf("***Unsupported operation***\r\n");
|
||||
os_printf("low bit : %d\r\n", (int)header->u.cmd_submit.request.wValue.u8lo);
|
||||
os_printf("high bit : %d\r\n", (int)header->u.cmd_submit.request.wValue.u8hi);
|
||||
os_printf("***Unsupported String descriptor***\r\n");
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -242,7 +268,7 @@ static void handleGetDescriptor(usbip_stage2_header *header)
|
|||
break;
|
||||
|
||||
case USB_DT_DEVICE_QUALIFIER:
|
||||
os_printf("* GET 0x06 DEVICE QUALIFIER DESCRIPTOR");
|
||||
os_printf("* GET 0x06 DEVICE QUALIFIER DESCRIPTOR\r\n");
|
||||
|
||||
usb_device_qualifier_descriptor desc;
|
||||
|
||||
|
@ -252,13 +278,13 @@ static void handleGetDescriptor(usbip_stage2_header *header)
|
|||
break;
|
||||
|
||||
case USB_DT_OTHER_SPEED_CONFIGURATION:
|
||||
os_printf("GET 0x07 [UNIMPLEMENTED] USB_DT_OTHER_SPEED_CONFIGURATION");
|
||||
os_printf("GET 0x07 [UNIMPLEMENTED] USB_DT_OTHER_SPEED_CONFIGURATION\r\n");
|
||||
////TODO:UNIMPLEMENTED
|
||||
send_stage2_submit(header, 0, 0);
|
||||
break;
|
||||
|
||||
case USB_DT_INTERFACE_POWER:
|
||||
os_printf("GET 0x08 [UNIMPLEMENTED] USB_DT_INTERFACE_POWER");
|
||||
os_printf("GET 0x08 [UNIMPLEMENTED] USB_DT_INTERFACE_POWER\r\n");
|
||||
////TODO:UNIMPLEMENTED
|
||||
send_stage2_submit(header, 0, 0);
|
||||
break;
|
||||
|
@ -268,7 +294,7 @@ static void handleGetDescriptor(usbip_stage2_header *header)
|
|||
send_stage2_submit_data(header, 0, bosDescriptor, sizeof(bosDescriptor));
|
||||
break;
|
||||
default:
|
||||
os_printf("USB unknown Get Descriptor requested:%d", header->u.cmd_submit.request.wValue.u8lo);
|
||||
os_printf("USB unknown Get Descriptor requested:%d\r\n", header->u.cmd_submit.request.wValue.u8lo);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
const uint8_t kUSBd0DeviceDescriptor[0x12] =
|
||||
{
|
||||
0x12, // bLength
|
||||
USB_DT_DEVICE, // bDescriptorType (constant)
|
||||
USB_DT_DEVICE, // bDescriptorType
|
||||
USBShort(0x0210), // bcdUSB
|
||||
////TODO: Is it also available elsewhere?
|
||||
|
||||
|
@ -34,14 +34,14 @@ const uint8_t kUSBd0DeviceDescriptor[0x12] =
|
|||
0x00, // bDeviceSubClass
|
||||
0x00, // bDeviceProtocol
|
||||
|
||||
USBD0_MAX_PACKET0, // Maximum packet size for default pipe.
|
||||
USBShort(USBD0_DEV_DESC_IDVENDOR), // Vendor ID (VID).
|
||||
USBShort(USBD0_DEV_DESC_IDPRODUCT), // Product ID (PID).
|
||||
USBShort(USBD0_DEV_DESC_BCDDEVICE), // Device Version BCD.
|
||||
0x01, // Index of Manufacturer string identifier.
|
||||
0x02, // Index of Product string identifier.
|
||||
0x03 * USBD0_STR_DESC_SER_EN, // Index of Product serial number.
|
||||
0x01 // Number of configurations.
|
||||
USBD0_MAX_PACKET0, // bMaxPacketSize0 Maximum packet size for default pipe.
|
||||
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.
|
||||
0x01, // iManufacturer Index of Manufacturer string identifier.
|
||||
0x02, // iProduct Index of Product string identifier.
|
||||
0x03 * USBD0_STR_DESC_SER_EN, // iSerialNumber Index of Product serial number.
|
||||
0x01 // bNumConfigurations Number of configurations.
|
||||
};
|
||||
|
||||
|
||||
|
@ -60,7 +60,7 @@ const uint8_t kUSBd0InterfaceDescriptor[0x1E]=
|
|||
USB_DT_INTERFACE, // bDescriptorType
|
||||
USBD_CUSTOM_CLASS0_IF0_NUM, // bInterfaceNumber
|
||||
USBD_CUSTOM_CLASS0_IF0_ALT, // bAlternateSetting
|
||||
0x03, // bNumEndpoints(we will use three endpoints)
|
||||
0x03, // bNumEndpoints(we will use 3 endpoints)
|
||||
//
|
||||
USBD_CUSTOM_CLASS0_IF0_CLASS, // bInterfaceClass
|
||||
USBD_CUSTOM_CLASS0_IF0_SUBCLASS, // bInterfaceSubClass
|
||||
|
@ -106,6 +106,7 @@ const uint8_t kUSBd0InterfaceDescriptor[0x1E]=
|
|||
0x00, // bInterval
|
||||
|
||||
/* Pysical endpoint 2 */
|
||||
|
||||
// "Endpoint 3: Bulk In (optional) – used for streaming SWO trace" Device -> PC
|
||||
0x07, // bLength
|
||||
USB_DT_ENDPOINT, // bDescriptorType
|
||||
|
@ -123,9 +124,8 @@ const uint8_t kUSBd0ConfigDescriptor[LENGTHOFCONFIGDESCRIPTOR] =
|
|||
{
|
||||
// Configuration descriptor header.
|
||||
|
||||
0x09, // bLength -> 0x09?? may be ok... 1-23
|
||||
0x03, // bDescriptorType
|
||||
// constant, set to 0x03
|
||||
0x09, // bLength
|
||||
USB_DT_CONFIGURATION, // bDescriptorType
|
||||
|
||||
USBShort((sizeof(kUSBd0InterfaceDescriptor)) + (LENGTHOFCONFIGDESCRIPTOR)),
|
||||
// wTotalLength
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
#include "usbip_server.h"
|
||||
#include "DAP_handle.h"
|
||||
#include "DAP.h"
|
||||
|
||||
#include "esp_libc.h"
|
||||
////TODO: Merge this
|
||||
#define DAP_PACKET_SIZE 512
|
||||
|
||||
|
@ -30,16 +30,18 @@ void handle_dap_data_request(usbip_stage2_header *header)
|
|||
data_in = &(data_in[sizeof(usbip_stage2_header)]);
|
||||
// Point to the beginning of the URB packet
|
||||
dap_respond = DAP_ProcessCommand((uint8_t *)data_in, (uint8_t *)data_out);
|
||||
send_stage2_submit(header, 0, 0);
|
||||
handle_dap_data_response(header);
|
||||
//send_stage2_submit(header, 0, 0);
|
||||
}
|
||||
void handle_dap_data_response(usbip_stage2_header *header)
|
||||
{
|
||||
if (dap_respond)
|
||||
{
|
||||
dap_respond = 0;
|
||||
//os_printf("*** Will respond");
|
||||
send_stage2_submit_data(header, 0, data_out, DAP_PACKET_SIZE);
|
||||
|
||||
//os_printf("*** Will respond");
|
||||
|
||||
send_stage2_submit_data(header, 0, data_out, (dap_respond & 0x0000FFFF));
|
||||
dap_respond = 0;
|
||||
//os_printf("*** RESPONDED ***");
|
||||
}
|
||||
else
|
||||
|
@ -66,18 +68,19 @@ void handle_swo_trace_response(usbip_stage2_header *header)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// SWO Data Queue Transfer
|
||||
// buf: pointer to buffer with data
|
||||
// num: number of bytes to transfer
|
||||
void SWO_QueueTransfer (uint8_t *buf, uint32_t num) {
|
||||
void SWO_QueueTransfer(uint8_t *buf, uint32_t num)
|
||||
{
|
||||
swo_data_to_send = buf;
|
||||
num_swo_data = num;
|
||||
swo_trace_respond = 1;
|
||||
}
|
||||
|
||||
// SWO Data Abort Transfer
|
||||
void SWO_AbortTransfer (void) {
|
||||
void SWO_AbortTransfer(void)
|
||||
{
|
||||
//USBD_EndpointAbort(0U, USB_ENDPOINT_IN(2U));
|
||||
////TODO: unlink might be useful ...
|
||||
}
|
|
@ -34,6 +34,7 @@
|
|||
|
||||
extern void SWO_Thread(void *argument);
|
||||
extern void usart_monitor_task(void *argument);
|
||||
extern void DAP_Setup(void);
|
||||
|
||||
/* FreeRTOS event group to signal when we are connected & ready to make a request */
|
||||
static EventGroupHandle_t wifi_event_group;
|
||||
|
@ -136,6 +137,7 @@ void app_main()
|
|||
ESP_ERROR_CHECK(nvs_flash_init());
|
||||
initialise_wifi();
|
||||
wait_for_ip();
|
||||
DAP_Setup(); // DAP Setup
|
||||
|
||||
xTaskCreate(timer_create_task, "timer_create", 512, NULL, 10, NULL);
|
||||
xTaskCreate(tcp_server_task, "tcp_server", 4096, NULL, 5, NULL);
|
||||
|
|
|
@ -65,7 +65,7 @@ void tcp_server_task(void *pvParameters)
|
|||
os_printf("Unable to create socket: errno %d\r\n", errno);
|
||||
break;
|
||||
}
|
||||
os_printf("Socket created");
|
||||
os_printf("Socket created\r\n");
|
||||
|
||||
int err = bind(listen_sock, (struct sockaddr *)&destAddr, sizeof(destAddr));
|
||||
if (err != 0)
|
||||
|
@ -73,7 +73,7 @@ void tcp_server_task(void *pvParameters)
|
|||
os_printf("Socket unable to bind: errno %d\r\n", errno);
|
||||
break;
|
||||
}
|
||||
os_printf("Socket binded");
|
||||
os_printf("Socket binded\r\n");
|
||||
|
||||
err = listen(listen_sock, 1);
|
||||
if (err != 0)
|
||||
|
@ -81,7 +81,7 @@ void tcp_server_task(void *pvParameters)
|
|||
os_printf("Error occured during listen: errno %d\r\n", errno);
|
||||
break;
|
||||
}
|
||||
os_printf("Socket listening");
|
||||
os_printf("Socket listening\r\n");
|
||||
|
||||
#ifdef CONFIG_EXAMPLE_IPV6
|
||||
struct sockaddr_in6 sourceAddr; // Large enough for both IPv4 or IPv6
|
||||
|
@ -89,13 +89,15 @@ void tcp_server_task(void *pvParameters)
|
|||
struct sockaddr_in sourceAddr;
|
||||
#endif
|
||||
uint32_t addrLen = sizeof(sourceAddr);
|
||||
while (1)
|
||||
{
|
||||
kSock = accept(listen_sock, (struct sockaddr *)&sourceAddr, &addrLen);
|
||||
if (kSock < 0)
|
||||
{
|
||||
os_printf("Unable to accept connection: errno %d\r\n", errno);
|
||||
break;
|
||||
}
|
||||
os_printf("Socket accepted");
|
||||
os_printf("Socket accepted\r\n");
|
||||
|
||||
while (1)
|
||||
{
|
||||
|
@ -129,14 +131,10 @@ void tcp_server_task(void *pvParameters)
|
|||
inet_ntoa_r(((struct sockaddr_in *)&sourceAddr)->sin_addr.s_addr, addr_str, sizeof(addr_str) - 1);
|
||||
#endif
|
||||
|
||||
rx_buffer[len] = 0; // Null-terminate whatever we received and treat like a string
|
||||
//os_printf("Received %d bytes from %s:\r\n", len, addr_str);
|
||||
// os_printf("%s", rx_buffer);
|
||||
switch (kState)
|
||||
{
|
||||
case ACCEPTING:
|
||||
kState = ATTACHING;
|
||||
break;
|
||||
|
||||
case ATTACHING:
|
||||
attach(rx_buffer, len);
|
||||
|
@ -145,26 +143,22 @@ void tcp_server_task(void *pvParameters)
|
|||
case EMULATING:
|
||||
emulate(rx_buffer, len);
|
||||
break;
|
||||
}
|
||||
|
||||
// int err = send(sock, rx_buffer, len, 0);
|
||||
// if (err < 0)
|
||||
// {
|
||||
// os_printf("Error occured during sending: errno %d\r\n", errno);
|
||||
// break;
|
||||
// }
|
||||
default:
|
||||
os_printf("unkonw kstate!\r\n");
|
||||
}
|
||||
}
|
||||
kState = ACCEPTING;
|
||||
}
|
||||
// kState = ACCEPTING;
|
||||
if (kSock != -1)
|
||||
{
|
||||
os_printf("Shutting down socket and restarting...\r\n");
|
||||
shutdown(kSock, 0);
|
||||
//shutdown(kSock, 0);
|
||||
close(kSock);
|
||||
|
||||
shutdown(listen_sock, 0);
|
||||
close(listen_sock);
|
||||
vTaskDelay(5);
|
||||
//shutdown(listen_sock, 0);
|
||||
//close(listen_sock);
|
||||
//vTaskDelay(5);
|
||||
}
|
||||
}
|
||||
}
|
||||
vTaskDelete(NULL);
|
||||
|
|
|
@ -53,7 +53,7 @@ int attach(uint8_t *buffer, uint32_t length)
|
|||
os_printf("attach Unknown command: %d\r\n", command);
|
||||
break;
|
||||
}
|
||||
return 0; ////TODO: ...
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int read_stage1_command(uint8_t *buffer, uint32_t length)
|
||||
|
@ -130,16 +130,15 @@ static void send_device_list()
|
|||
|
||||
static void send_device_info()
|
||||
{
|
||||
os_printf("Sending device info...");
|
||||
os_printf("Sending device info...\r\n");
|
||||
usbip_stage1_usb_device device;
|
||||
|
||||
strcpy(device.path, "/sys/devices/pci0000:00/0000:00:01.2/usb1/1-1");
|
||||
strcpy(device.busid, "1-1");
|
||||
|
||||
device.busnum = htonl(1);
|
||||
device.devnum = htonl(2);
|
||||
device.speed = htonl(2); // what is this???
|
||||
//// TODO: 0200H for USB2.0
|
||||
device.devnum = htonl(1);
|
||||
device.speed = htonl(3); // See usb_device_speed enum
|
||||
|
||||
device.idVendor = htons(USBD0_DEV_DESC_IDVENDOR);
|
||||
device.idProduct = htons(USBD0_DEV_DESC_IDPRODUCT);
|
||||
|
@ -211,7 +210,7 @@ static int read_stage2_command(usbip_stage2_header *header, uint32_t length)
|
|||
}
|
||||
|
||||
//client.readBytes((uint8_t *)&header, sizeof(usbip_stage2_header));
|
||||
unpack((uint32_t *)&header, sizeof(usbip_stage2_header));
|
||||
unpack((uint32_t *)header, sizeof(usbip_stage2_header));
|
||||
return header->base.command;
|
||||
}
|
||||
|
||||
|
@ -263,7 +262,7 @@ static void unpack(void *data, int size)
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* @brief USB transaction processing
|
||||
*
|
||||
*/
|
||||
static int handle_submit(usbip_stage2_header *header)
|
||||
|
@ -324,18 +323,18 @@ void send_stage2_submit(usbip_stage2_header *req_header, int32_t status, int32_t
|
|||
{
|
||||
|
||||
req_header->base.command = USBIP_STAGE2_RSP_SUBMIT;
|
||||
req_header->base.direction = !req_header->base.direction;
|
||||
req_header->base.direction = !(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.status = status;
|
||||
req_header->u.ret_submit.data_length = data_length;
|
||||
|
||||
pack(&req_header, sizeof(usbip_stage2_header));
|
||||
pack(req_header, sizeof(usbip_stage2_header));
|
||||
send(kSock, req_header, sizeof(usbip_stage2_header), 0);
|
||||
}
|
||||
|
||||
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 uint8_t *const data, int32_t data_length)
|
||||
{
|
||||
|
||||
send_stage2_submit(req_header, status, data_length);
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
#define EXAMPLE_WIFI_SSID "DAP"
|
||||
#define EXAMPLE_WIFI_PASS "12345678"
|
||||
|
||||
#define PORT 22350
|
||||
#define PORT 3240
|
||||
|
||||
#define CONFIG_EXAMPLE_IPV4 1
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue