Source: USB That Thing 3-using port 2 as the transfer of custom HID
The USB custom HID example uses port 1 as the communication, so now I use port 2 as the communication end, how to modify it? As shown below:
First modify: USB_DESC.C in the const U8 CUSTOMHID_CONFIGDESCRIPTOR[CUSTOMHID_SIZ_CONFIG_DESC] This character array contents: The following red for the modified part, Not listed without modification:
Usb_endpoint_descriptor_type,/*bDescriptorType:*/ 0x82, /*bendpointaddress:endpoint Address (in)*/ 0x03,/*Bmattributes:interrupt Endpoint*/ 0x02,/*wmaxpacketsize:2 Bytes Max*/ 0x00, 0x20,/*binterval:polling Interval (ms)*/ /* the*/ /*********out endpoint******/ 0x07,/*blength:endpoint Descriptor Size*/Usb_endpoint_descriptor_type,/*bDescriptorType:*/ /*Endpoint Descriptor Type*/ 0x02, /*bendpointaddress:*/ /*Endpoint Address (out)*/ 0x03,/*Bmattributes:interrupt Endpoint*/ 0x02,/*wmaxpacketsize:2 Bytes Max*/ 0x00, 0x20,/*binterval:polling Interval (ms)*/ /* A*/
Second, modify the Usb_conf.h file as follows:
/*-------------------------------------------------------------*/
#define EP_NUM (3)//This is very important. I've changed it for a long time. This is the number of endpoints supported by the specified device, since the endpoint 2 is used so I use 3, of course >=3
/*-------------------------------------------------------------*/
/*--------------Buffer Description Table-----------------*/
/*-------------------------------------------------------------*/
/* Buffer Table base Address */
/* Buffer Table base Address */
#define BTABLE_ADDRESS (0x00)
maximum number of bytes #define Epxbyte 0x2//Endpoint Transfer
/* EP0 */
/* RX/TX Buffer Base Address */
#define ENDP0_RXADDR (0x18)
#define ENDP0_TXADDR (0x58)
/* EP1 */
/* TX Buffer Base Address */
#define ENDP1_TXADDR (0x100)
#define ENDP1_RXADDR (0x104)
/* EP2 */
#define ENDP2_TXADDR endp1_rxaddr + epxbyte //define receive and send addresses for endpoint 2
#define ENDP2_RXADDR endp2_txaddr + epxbyte
Finally, modify the usb_prop.c as follows:
void Customhid_reset (void) This function adds a reset to port 2 as follows:
Seteptype (ENDP2, ep_interrupt);
Seteptxaddr (ENDP2, endp2_txaddr);
Seteprxaddr (ENDP2, endp2_rxaddr);
Seteptxcount (ENDP2, epxbyte);
Seteprxcount (ENDP2, epxbyte);
Seteprxstatus (ENDP2, ep_rx_valid);
Seteptxstatus (ENDP2, Ep_tx_nak);
The whole is done.
Ps:usb hid example in Keil inside the installation directory examples directory has this example, is based on the example of STM32!
USB that thing 3-use port 2 as custom HID transmission (RPM)