stm32 USB增加端点总结(端点用法)
在原有的端点1和端点2基础上增加一个双向端点3.
由于EP3端点缓冲区只有512-32-64*7=32字节大小,所以发送长度不能大于32,否则多余的数据会丢失
1. 修改u***_desc.c
1)将端点数目改为6
/************** Descriptor of Custom HID interface ****************/
/* 09 */
0x09, /* bLength: Interface Descriptor size */
USB_INTERFACE_DESCRIPTOR_TYPE,/* bDescriptorType: Interface descriptor type */
0x00, /* bInterfaceNumber: Number of Interface */
0x00, /* bAlternateSetting: Alternate setting */
0x06, /* bNumEndpoints */
0xDC, /* bInterfaceClass: Class code = 0DCH */
0xA0, /* bInterfaceSubClass : Subclass code = 0A0H */
0xB0, /* nInterfaceProtocol : Protocol code = 0B0H */
0, /* iInterface: Index of string descriptor */
2)增加端点描述符
0x07, /* endpoint descriptor length = 07H */
USB_ENDPOINT_DESCRIPTOR_TYPE, /* endpoint descriptor type = 05H */
0x83, /* endpoint 2 IN */
0x02, /* bulk transfer = 02H */
0x40,0x00, /* endpoint max packet size = 0040H */
0x0A, /* the value is invalid when bulk transfer */
0x07, /* endpoint descriptor length = 07H */
USB_ENDPOINT_DESCRIPTOR_TYPE, /* endpoint descriptor type = 05H */
0x03, /* endpoint 2 OUT */
0x02, /* bulk transfer = 02H */
0x40,0x00, /* endpoint max packet size = 0040H */
0x0A, /* the value is invalid when bulk transfer */
2. 修改u***_prop.c
1)在void CustomHID_Reset(void)中初始化端点3
/* Initialize Endpoint 3 */
SetEPType(ENDP3, EP_BULK);
SetEPRxAddr(ENDP3, ENDP3_RXADDR);
SetEPTxAddr(ENDP3, ENDP3_TXADDR);
SetEPRxCount(ENDP3, EP_SIZE);
SetEPRxStatus(ENDP3, EP_RX_VALID);
SetEPTxStatus(ENDP3, EP_TX_NAK);
3. 修改u***_conf.h
1)将端点书改为4
#define EP_NUM (4)
2)修改端点缓冲地址
/* buffer table base address */
#define BTABLE_ADDRESS (0x00)
/* EP0 */
/* rx/tx buffer base address */
#define ENDP0_RXADDR (0x20) //4*8=0x20,参照有道笔记“STM32 USB端点修改”
#define ENDP0_TXADDR (0x60)
/* EP1 */
/* tx buffer base address */
//地址为32位对其,位4的倍数,不能超过 bMaxPacketSize
//EP1
#define ENDP1_RXADDR (0xa0) //每个缓冲区大小64
#define ENDP1_TXADDR (0xa0+64)
EP2
#define ENDP2_RXADDR (0xa0+64+64)
#define ENDP2_TXADDR (0xa0+64+64+64)
EP3
#define ENDP3_RXADDR (0xa0+64+64+64+64)
#define ENDP3_TXADDR (0xa0+64+64+64+64+64)
3)注释回调函数
//#define EP3_IN_Callback NOP_Process
//#define EP3_OUT_Callback NOP_Process
4. 修改u***_endp.c
1)在void EP3_OUT_Callback(void)中实现u***接收数据处理
2)void EP3_IN_Callback(void)可不用实现
5. 修改u***io.c
1)封装上层接收与发送接口
stm32 USB增加端点总结(端点用法)
在原有的端点1和端点2基础上增加一个双向端点3.
由于EP3端点缓冲区只有512-32-64*7=32字节大小,所以发送长度不能大于32,否则多余的数据会丢失
1. 修改u***_desc.c
1)将端点数目改为6
/************** Descriptor of Custom HID interface ****************/
/* 09 */
0x09, /* bLength: Interface Descriptor size */
USB_INTERFACE_DESCRIPTOR_TYPE,/* bDescriptorType: Interface descriptor type */
0x00, /* bInterfaceNumber: Number of Interface */
0x00, /* bAlternateSetting: Alternate setting */
0x06, /* bNumEndpoints */
0xDC, /* bInterfaceClass: Class code = 0DCH */
0xA0, /* bInterfaceSubClass : Subclass code = 0A0H */
0xB0, /* nInterfaceProtocol : Protocol code = 0B0H */
0, /* iInterface: Index of string descriptor */
2)增加端点描述符
0x07, /* endpoint descriptor length = 07H */
USB_ENDPOINT_DESCRIPTOR_TYPE, /* endpoint descriptor type = 05H */
0x83, /* endpoint 2 IN */
0x02, /* bulk transfer = 02H */
0x40,0x00, /* endpoint max packet size = 0040H */
0x0A, /* the value is invalid when bulk transfer */
0x07, /* endpoint descriptor length = 07H */
USB_ENDPOINT_DESCRIPTOR_TYPE, /* endpoint descriptor type = 05H */
0x03, /* endpoint 2 OUT */
0x02, /* bulk transfer = 02H */
0x40,0x00, /* endpoint max packet size = 0040H */
0x0A, /* the value is invalid when bulk transfer */
2. 修改u***_prop.c
1)在void CustomHID_Reset(void)中初始化端点3
/* Initialize Endpoint 3 */
SetEPType(ENDP3, EP_BULK);
SetEPRxAddr(ENDP3, ENDP3_RXADDR);
SetEPTxAddr(ENDP3, ENDP3_TXADDR);
SetEPRxCount(ENDP3, EP_SIZE);
SetEPRxStatus(ENDP3, EP_RX_VALID);
SetEPTxStatus(ENDP3, EP_TX_NAK);
3. 修改u***_conf.h
1)将端点书改为4
#define EP_NUM (4)
2)修改端点缓冲地址
/* buffer table base address */
#define BTABLE_ADDRESS (0x00)
/* EP0 */
/* rx/tx buffer base address */
#define ENDP0_RXADDR (0x20) //4*8=0x20,参照有道笔记“STM32 USB端点修改”
#define ENDP0_TXADDR (0x60)
/* EP1 */
/* tx buffer base address */
//地址为32位对其,位4的倍数,不能超过 bMaxPacketSize
//EP1
#define ENDP1_RXADDR (0xa0) //每个缓冲区大小64
#define ENDP1_TXADDR (0xa0+64)
EP2
#define ENDP2_RXADDR (0xa0+64+64)
#define ENDP2_TXADDR (0xa0+64+64+64)
EP3
#define ENDP3_RXADDR (0xa0+64+64+64+64)
#define ENDP3_TXADDR (0xa0+64+64+64+64+64)
3)注释回调函数
//#define EP3_IN_Callback NOP_Process
//#define EP3_OUT_Callback NOP_Process
4. 修改u***_endp.c
1)在void EP3_OUT_Callback(void)中实现u***接收数据处理
2)void EP3_IN_Callback(void)可不用实现
5. 修改u***io.c
1)封装上层接收与发送接口
1
举报