feat: URB packet processing & DAP command push
This commit is contained in:
		
							parent
							
								
									957cc01656
								
							
						
					
					
						commit
						529e0a375f
					
				|  | @ -100,7 +100,7 @@ This information includes: | |||
| /// This configuration settings is used to optimize the communication performance with the
 | ||||
| /// debugger and depends on the USB peripheral. For devices with limited RAM or USB buffer the
 | ||||
| /// setting can be reduced (valid range is 1 .. 255).
 | ||||
| #define DAP_PACKET_COUNT 8U ///< Specifies number of packets buffered.
 | ||||
| #define DAP_PACKET_COUNT 1U ///< Specifies number of packets buffered.
 | ||||
| 
 | ||||
| /// Indicate that UART Serial Wire Output (SWO) trace is available.
 | ||||
| /// This information is returned by the command \ref DAP_Info as part of <b>Capabilities</b>.
 | ||||
|  | @ -109,7 +109,7 @@ This information includes: | |||
| /// Maximum SWO UART Baudrate.
 | ||||
| #define SWO_UART_MAX_BAUDRATE 50000000U ///< SWO UART Maximum Baudrate in Hz.
 | ||||
| // <<<<<<<<<<<<<<<<<<<<<<<<<<<<< 5MHz
 | ||||
| // TODO: uncertain value
 | ||||
| //// TODO: uncertain value
 | ||||
| 
 | ||||
| /// Indicate that Manchester Serial Wire Output (SWO) trace is available.
 | ||||
| /// This information is returned by the command \ref DAP_Info as part of <b>Capabilities</b>.
 | ||||
|  | @ -144,7 +144,7 @@ This information includes: | |||
|  */ | ||||
| __STATIC_INLINE uint8_t DAP_GetVendorString(char *str) | ||||
| { | ||||
|   //TODO: fill this
 | ||||
|   ////TODO: fill this
 | ||||
|   // In fact, Keil can get the corresponding information through USB
 | ||||
|   // without filling in this information.
 | ||||
|   (void)str; | ||||
|  | @ -296,7 +296,7 @@ __STATIC_INLINE void PORT_OFF(void) | |||
|  */ | ||||
| __STATIC_FORCEINLINE uint32_t PIN_SWCLK_TCK_IN(void) | ||||
| { | ||||
|   // TODO : can we set to 0?
 | ||||
|   ////TODO: can we set to 0?
 | ||||
|   return ((GPIO.in >> PIN_SWCLK) & 0x1); | ||||
| } | ||||
| 
 | ||||
|  | @ -478,7 +478,7 @@ __STATIC_FORCEINLINE uint32_t PIN_nTRST_IN(void) | |||
|  */ | ||||
| __STATIC_FORCEINLINE void PIN_nTRST_OUT(uint32_t bit) | ||||
| { | ||||
|   //TODO : What does this mean? ? ?
 | ||||
|   ////TODO: What does this mean? ? ?
 | ||||
|   if ((bit & 1U) == 1) | ||||
|   { | ||||
|     //set bit
 | ||||
|  | @ -512,7 +512,7 @@ __STATIC_FORCEINLINE uint32_t PIN_nRESET_IN(void) | |||
|  */ | ||||
| __STATIC_FORCEINLINE void PIN_nRESET_OUT(uint32_t bit) | ||||
| { | ||||
|   //TODO : What does this mean? ? ?
 | ||||
|   ////TODO: What does this mean? ? ?
 | ||||
|   if ((bit & 1U) == 1) | ||||
|   { | ||||
|     //set bit
 | ||||
|  |  | |||
|  | @ -1,6 +1,6 @@ | |||
| /**
 | ||||
|  * @file USB_handle.c | ||||
|  * @brief Handle all Standard Device Requests | ||||
|  * @brief Handle all Standard Device Requests on endpoint 0 | ||||
|  * @version 0.1 | ||||
|  * @date 2020-01-23 | ||||
|  *  | ||||
|  | @ -17,34 +17,38 @@ | |||
| #include "usbip_server.h" | ||||
| #include "usb_defs.h" | ||||
| 
 | ||||
| 
 | ||||
| // handle functions
 | ||||
| static void handleGetDescriptor(struct usbip_stage2_header *header); | ||||
| static void handleGetDescriptor(usbip_stage2_header *header); | ||||
| 
 | ||||
| ////TODO: fill this
 | ||||
| int handleUSBControlRequest(struct usbip_stage2_header *header) | ||||
| int handleUSBControlRequest(usbip_stage2_header *header) | ||||
| { | ||||
|     // Table 9-3. Standard Device Requests
 | ||||
| 
 | ||||
|     switch (header->u.cmd_submit.request.bmRequestType) | ||||
|     { | ||||
|     case 0x00: | ||||
|     case 0x00: // ignore..
 | ||||
|         switch (header->u.cmd_submit.request.bRequest) | ||||
|         { | ||||
|         case USB_REQ_CLEAR_FEATURE: | ||||
|             /* code */ | ||||
|             os_printf("* CLEAR FEATURE\r\n"); | ||||
|             send_stage2_submit_data(header, 0, 0, 0); | ||||
|             break; | ||||
|         case USB_REQ_SET_FEATURE: | ||||
|             /* code */ | ||||
|             os_printf("* SET FEATURE\r\n"); | ||||
|             send_stage2_submit_data(header, 0, 0, 0); | ||||
|             break; | ||||
|         case USB_REQ_SET_ADDRESS: | ||||
|             /* code */ | ||||
|             os_printf("* SET ADDRESS\r\n"); | ||||
|             send_stage2_submit_data(header, 0, 0, 0); | ||||
|             break; | ||||
|         case USB_REQ_SET_DESCRIPTOR: | ||||
|             /* code */ | ||||
|             os_printf("* SET DESCRIPTOR\r\n"); | ||||
|             send_stage2_submit_data(header, 0, 0, 0); | ||||
|             break; | ||||
|         case USB_REQ_SET_CONFIGURATION: | ||||
|             /* code */ | ||||
|             os_printf("* SET CONFIGURATION\r\n"); | ||||
|             send_stage2_submit_data(header, 0, 0, 0); | ||||
|             break; | ||||
|         default: | ||||
|             os_printf("USB unknown request, bmRequestType:%d,bRequest:%d\r\n", | ||||
|  | @ -52,17 +56,20 @@ int handleUSBControlRequest(struct usbip_stage2_header *header) | |||
|             break; | ||||
|         } | ||||
|         break; | ||||
|     case 0x01: | ||||
|     case 0x01: // ignore...
 | ||||
|         switch (header->u.cmd_submit.request.bRequest) | ||||
|         { | ||||
|         case USB_REQ_CLEAR_FEATURE: | ||||
|             /* code */ | ||||
|             os_printf("* CLEAR FEATURE\r\n"); | ||||
|             send_stage2_submit_data(header, 0, 0, 0); | ||||
|             break; | ||||
|         case USB_REQ_SET_FEATURE: | ||||
|             /* code */ | ||||
|             os_printf("* SET FEATURE\r\n"); | ||||
|             send_stage2_submit_data(header, 0, 0, 0); | ||||
|             break; | ||||
|         case USB_REQ_SET_INTERFACE: | ||||
|             /* code */ | ||||
|             os_printf("* SET INTERFACE\r\n"); | ||||
|             send_stage2_submit_data(header, 0, 0, 0); | ||||
|             break; | ||||
| 
 | ||||
|         default: | ||||
|  | @ -71,14 +78,16 @@ int handleUSBControlRequest(struct usbip_stage2_header *header) | |||
|             break; | ||||
|         } | ||||
|         break; | ||||
|     case 0x02: | ||||
|     case 0x02: // ignore..
 | ||||
|         switch (header->u.cmd_submit.request.bRequest) | ||||
|         { | ||||
|         case USB_REQ_CLEAR_FEATURE: | ||||
|             /* code */ | ||||
|             os_printf("* CLEAR FEATURE\r\n"); | ||||
|             send_stage2_submit_data(header, 0, 0, 0); | ||||
|             break; | ||||
|         case USB_REQ_SET_FEATURE: | ||||
|             /* code */ | ||||
|             os_printf("* SET INTERFACE\r\n"); | ||||
|             send_stage2_submit_data(header, 0, 0, 0); | ||||
|             break; | ||||
| 
 | ||||
|         default: | ||||
|  | @ -88,17 +97,19 @@ int handleUSBControlRequest(struct usbip_stage2_header *header) | |||
|         } | ||||
|         break; | ||||
| 
 | ||||
|     case 0x80: | ||||
|     case 0x80: // *IMPORTANT*
 | ||||
|         switch (header->u.cmd_submit.request.bRequest) | ||||
|         { | ||||
|         case USB_REQ_GET_CONFIGURATION: | ||||
|             handleGetDescriptor(header); | ||||
|             os_printf("* GET CONIFGTRATION\r\n"); | ||||
|             send_stage2_submit_data(header, 0, 0, 0); | ||||
|             break; | ||||
|         case USB_REQ_GET_DESCRIPTOR: | ||||
|             /* code */ | ||||
|             handleGetDescriptor(header); ////TODO: device_qualifier
 | ||||
|             break; | ||||
|         case USB_REQ_GET_STATUS: | ||||
|             /* code */ | ||||
|             os_printf("* GET STATUS\r\n"); | ||||
|             send_stage2_submit_data(header, 0, 0, 0); | ||||
|             break; | ||||
|         default: | ||||
|             os_printf("USB unknown request, bmRequestType:%d,bRequest:%d\r\n", | ||||
|  | @ -106,17 +117,20 @@ int handleUSBControlRequest(struct usbip_stage2_header *header) | |||
|             break; | ||||
|         } | ||||
|         break; | ||||
|     case 0x81: | ||||
|     case 0x81: // ignore...
 | ||||
|         switch (header->u.cmd_submit.request.bRequest) | ||||
|         { | ||||
|         case USB_REQ_GET_INTERFACE: | ||||
|             /* code */ | ||||
|             os_printf("* GET INTERFACE\r\n"); | ||||
|             send_stage2_submit_data(header, 0, 0, 0); | ||||
|             break; | ||||
|         case USB_REQ_SET_SYNCH_FRAME: | ||||
|             /* code */ | ||||
|             os_printf("* SET SYNCH FRAME\r\n"); | ||||
|             send_stage2_submit_data(header, 0, 0, 0); | ||||
|             break; | ||||
|         case USB_REQ_GET_STATUS: | ||||
|             /* code */ | ||||
|             os_printf("* GET STATUS\r\n"); | ||||
|             send_stage2_submit_data(header, 0, 0, 0); | ||||
|             break; | ||||
| 
 | ||||
|         default: | ||||
|  | @ -126,11 +140,12 @@ int handleUSBControlRequest(struct usbip_stage2_header *header) | |||
|         } | ||||
|         break; | ||||
| 
 | ||||
|     case 0x82: | ||||
|     case 0x82: // ignore...
 | ||||
|         switch (header->u.cmd_submit.request.bRequest) | ||||
|         { | ||||
|         case USB_REQ_GET_STATUS: | ||||
|             /* code */ | ||||
|             os_printf("* GET STATUS\r\n"); | ||||
|             send_stage2_submit_data(header, 0, 0, 0); | ||||
|             break; | ||||
| 
 | ||||
|         default: | ||||
|  | @ -139,7 +154,6 @@ int handleUSBControlRequest(struct usbip_stage2_header *header) | |||
|             break; | ||||
|         } | ||||
|         break; | ||||
|         /////////
 | ||||
| 
 | ||||
|     default: | ||||
|         os_printf("USB unknown request, bmRequestType:%d,bRequest:%d\r\n", | ||||
|  | @ -148,8 +162,8 @@ int handleUSBControlRequest(struct usbip_stage2_header *header) | |||
|     } | ||||
| } | ||||
| 
 | ||||
| ////TODO: fill this
 | ||||
| static void handleGetDescriptor(struct usbip_stage2_header *header) | ||||
| ////TODO: BOS descriptor
 | ||||
| static void handleGetDescriptor(usbip_stage2_header *header) | ||||
| { | ||||
|     // 9.4.3 Get Descriptor
 | ||||
|     switch (header->u.cmd_submit.request.wValue.u8hi) | ||||
|  | @ -168,7 +182,6 @@ static void handleGetDescriptor(struct usbip_stage2_header *header) | |||
| 
 | ||||
|             send_stage2_submit(header, 0, header->u.cmd_submit.data_length); | ||||
|             send(kSock, kUSBd0ConfigDescriptor, sizeof(kUSBd0ConfigDescriptor), 0); | ||||
| 
 | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|  | @ -177,18 +190,19 @@ static void handleGetDescriptor(struct usbip_stage2_header *header) | |||
|             send_stage2_submit(header, 0, header->u.cmd_submit.data_length); | ||||
|             send(kSock, kUSBd0ConfigDescriptor, sizeof(kUSBd0ConfigDescriptor), 0); | ||||
|             send(kSock, kUSBd0InterfaceDescriptor, sizeof(kUSBd0InterfaceDescriptor), 0); | ||||
| 
 | ||||
|         } | ||||
|         break; | ||||
| 
 | ||||
|     case USB_DT_STRING: | ||||
|         os_printf("* GET 0x03 STRING DESCRIPTOR\r\n"); | ||||
| 
 | ||||
|         if (header->u.cmd_submit.request.wValue.u8lo == 0) { | ||||
|         if (header->u.cmd_submit.request.wValue.u8lo == 0) | ||||
|         { | ||||
|             os_printf("** REQUESTED list of supported languages\r\n"); | ||||
|             send_stage2_submit_data(header, 0, kLangDescriptor, sizeof(kLangDescriptor)); | ||||
|         } | ||||
|         else{ | ||||
|         else | ||||
|         { | ||||
|             os_printf("***Unsupported operation***\r\n"); | ||||
|         } | ||||
|         break; | ||||
|  | @ -227,7 +241,6 @@ static void handleGetDescriptor(struct usbip_stage2_header *header) | |||
|         send_stage2_submit(header, 0, 0); | ||||
|         break; | ||||
| 
 | ||||
| 
 | ||||
|     default: | ||||
|         os_printf("USB unknown Get Descriptor requested:%d", header->u.cmd_submit.request.wValue.u8lo); | ||||
|         break; | ||||
|  |  | |||
|  | @ -26,7 +26,8 @@ const uint8_t kUSBd0DeviceDescriptor[0x12] = | |||
| { | ||||
|     0x12,             // bLength
 | ||||
|     USB_DT_DEVICE, // bDescriptorType (constant)
 | ||||
|     USBShort(0x0200), // bcdUSB (2.00)
 | ||||
|     USBShort(0x0210), // bcdUSB 
 | ||||
|     ////TODO: Is it also available elsewhere?
 | ||||
| 
 | ||||
|     // We need to use a device other than the USB-IF standard, set to 0x00
 | ||||
|     0x00, // bDeviceClass
 | ||||
|  |  | |||
|  | @ -197,13 +197,13 @@ typedef struct | |||
|  */ | ||||
| typedef struct | ||||
| { | ||||
|     struct usbip_stage2_header_basic base; | ||||
|     usbip_stage2_header_basic base; | ||||
| 
 | ||||
|     union { | ||||
|         struct usbip_stage2_header_cmd_submit cmd_submit; | ||||
|         struct usbip_stage2_header_ret_submit ret_submit; | ||||
|         struct usbip_stage2_header_cmd_unlink cmd_unlink; | ||||
|         struct usbip_stage2_header_ret_unlink ret_unlink; | ||||
|         usbip_stage2_header_cmd_submit cmd_submit; | ||||
|         usbip_stage2_header_ret_submit ret_submit; | ||||
|         usbip_stage2_header_cmd_unlink cmd_unlink; | ||||
|         usbip_stage2_header_ret_unlink ret_unlink; | ||||
|     } u; | ||||
| } __attribute__((packed)) usbip_stage2_header; | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,4 +1,4 @@ | |||
| set(COMPONENT_SRCS "main.c timer.c tcp_server.c usbip_server.c") | ||||
| set(COMPONENT_SRCS "main.c timer.c tcp_server.c usbip_server.c DAP_handle.c") | ||||
| set(COMPONENT_ADD_INCLUDEDIRS ". $ENV{IDF_PATH}/components/esp8266/include/esp8266/ ../components/USBIP") | ||||
| 
 | ||||
| register_component() | ||||
|  |  | |||
|  | @ -0,0 +1,45 @@ | |||
| /**
 | ||||
|  * @file DAP_handle.c | ||||
|  * @brief Handle DAP packets and transaction push | ||||
|  * @version 0.1 | ||||
|  * @date 2020-01-25 | ||||
|  *  | ||||
|  * @copyright Copyright (c) 2020 | ||||
|  *  | ||||
|  */ | ||||
| 
 | ||||
| #include <stdint.h> | ||||
| #include "usbip_server.h" | ||||
| #include "DAP_handle.h" | ||||
| #include "DAP.h" | ||||
| 
 | ||||
| ////TODO: Merge this
 | ||||
| #define DAP_PACKET_SIZE 512   | ||||
| 
 | ||||
| 
 | ||||
| uint8_t data_out[DAP_PACKET_SIZE]; | ||||
| int respond = 0; | ||||
| 
 | ||||
| 
 | ||||
| void handle_dap_data_request(usbip_stage2_header *header) | ||||
| { | ||||
|     uint8_t * data_in = (uint8_t *)header; | ||||
|     data_in = &(data_in[sizeof(usbip_stage2_header)]); | ||||
|     // Point to the beginning of the URB packet
 | ||||
|     respond = DAP_ProcessCommand((uint8_t *)data_in, (uint8_t *)data_out); | ||||
|     send_stage2_submit(header, 0, 0); | ||||
| 
 | ||||
| } | ||||
| void handle_dap_data_response(usbip_stage2_header *header) | ||||
| { | ||||
|     if (respond) { | ||||
|             respond = 0; | ||||
|             //os_printf("*** Will respond");
 | ||||
|             send_stage2_submit_data(header, 0, data_out, DAP_PACKET_SIZE); | ||||
|          | ||||
|             //os_printf("*** RESPONDED ***");
 | ||||
|         } else { | ||||
|             //os_printf("*** Will NOT respond");
 | ||||
|             send_stage2_submit(header, 0, 0); | ||||
|         } | ||||
| } | ||||
|  | @ -0,0 +1,8 @@ | |||
| #ifndef __DAP_HANDLE_H__ | ||||
| #define __DAP_HANDLE_H__ | ||||
| 
 | ||||
| #include "usbip_defs.h" | ||||
| 
 | ||||
| void handle_dap_data_request(usbip_stage2_header *header); | ||||
| void handle_dap_data_response(usbip_stage2_header *header); | ||||
| #endif | ||||
|  | @ -121,7 +121,6 @@ static void send_device_list() | |||
| 
 | ||||
| static void send_device_info() | ||||
| { | ||||
|     //// TODO:fill this
 | ||||
|     os_printf("Sending device info..."); | ||||
|     usbip_stage1_usb_device device; | ||||
| 
 | ||||
|  | @ -172,7 +171,7 @@ static void send_interface_info() | |||
| int emulate(uint8_t *buffer, uint32_t length) | ||||
| { | ||||
|     // usbip_stage2_header header;
 | ||||
|     int command = read_stage2_command((usbip_stage2_header *)buffer); ////TODO: fill this
 | ||||
|     int command = read_stage2_command((usbip_stage2_header *)buffer, length); ////TODO: fill this
 | ||||
|     if (command < 0) | ||||
|     { | ||||
|         return -1; | ||||
|  | @ -272,13 +271,13 @@ static int handle_submit(usbip_stage2_header *header) | |||
|     case 0x01: | ||||
|         if (header->base.direction == 0) | ||||
|         { | ||||
|             // Serial.println("EP 01 DATA FROM HOST");
 | ||||
|             handle_data_request(header); | ||||
|             // os_printf("EP 01 DATA FROM HOST");
 | ||||
|             handle_dap_data_request(header); | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             // Serial.println("EP 01 DATA TO HOST");
 | ||||
|             handle_data_response(header); | ||||
|             // os_printf("EP 01 DATA TO HOST");
 | ||||
|             handle_dap_data_response(header); | ||||
|         } | ||||
|         break; | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue