USB HID 协议问题

发布于 2024-08-30 23:22:17 字数 617 浏览 4 评论 0原文

我正在使用通用 HID 接口在 PIC 18F2550 上实现 USB。我已将 HID 配置文件配置设置为输入和输出均具有单个 64 字节消息。

现在基本上已经可以工作了。设备在 Windows 上注册正常。我可以在 PC 上的程序中找到它,并且可以向它发送和接收数据。但问题是这样的 - 从 PC 到 PIC 的消息被截断为 EP0 端点缓冲区的大小。

在我进一步调试之前,我想尝试澄清我对 USB 协议的理解,并检查我是否正确。

假设EP0输入缓冲区为8字节。据我了解,PC端会发送一个8字节的控制包。其中包含要跟随的数据的长度(以字节为单位)。然后它将发送一系列 8 字节数据包,PIC 端必须确认每个数据包。

据我了解,PC端通过查看设备描述符中的最大数据包大小字段知道每个数据包有多大,并将相应地将消息划分为多个数据包。

在我花更多时间研究代码之前,有人能确认这基本上是正确的吗?如果 EP0 缓冲区大小是 8 个字节,那么 PC 应该因为我上面提到的配置字段而知道这一点并发送多个数据包?

如果我在 PIC 上设置接收缓冲区 64 字节,那么我会得到 64 字节的消息,这足以满足我的需要,但我不喜欢不理解为什么它不能与小缓冲区一起工作,有一天我会无论如何,可能都需要它们。

欢迎任何建议或信息。

I'm implementing USB on a PIC 18F2550 using a generic HID interface. I've set up the HID profile configuation to have a single 64 byte message for both inputs and outputs.

Now it's basically working. The device registers OK with windows. I can find it in my program on the PC and can send and receive data to it. The problem is this though - messages from the PC to the PIC are truncated to the size of the EP0 endpoint buffer.

Before I go debugging too much further I want to try to clarify my understanding of the USB protocols here and check I got it right.

Assume that the EP0 input buffer is 8 bytes. It's my understanding that the PC end will send a control packet which is 8 bytes. In there is the length in bytes of the data to follow. And then it will send a sequence of 8 byte data packets and the PIC end has to acknowledge each one.

It's my understanding that the PC end knows how big each packet may be by looking in the maximum packet size field in the device descriptor and will divide up the message accordingly into multiple data packets.

Before I go looking for more hours at the code, can anyone confirm that this is basically correct? That if the EP0 buffer size is 8 bytes then the PC should know this because of the configuration field I mentioned above and send multiple data packets?

If I make my receive buffer on the PIC 64 bytes then I get 64 bytes of the message which is sufficient for my needs, but I don't like not understanding why it doesn't work with small buffers, and one day I'll probably need them anyway.

Any advice or information would be welcome.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

瘫痪情歌 2024-09-06 23:22:17

有一个称为端点描述符的东西,除其他外,它定义了 wMaxPacketSize - 主机控制器接口驱动程序使用它来将大型 USB 传输细分为较小的数据包。

这与 EP0 缓冲区大小完全不同 - 然而,EP0 缓冲区大小始终需要大于 wMaxPacketSize。我的猜测是(如果您使用 Microchip USB 堆栈,请尝试发布您的 usb_config.h 和 usb_descriptors.c),您要么尝试使用 8 字节长的 EP0 和 64 字节长的 wMaxPacketSize,这会截断传输。

另请注意,在 USB 1.1 低速中,wMaxPacketSize 不能超过 8,在 USB 1.1 全速中,wMaxPacketSize 不能超过 64。

0x07,/*sizeof(USB_EP_DSC)*/
USB_DESCRIPTOR_ENDPOINT,    //Endpoint Descriptor
HID_EP | _EP_IN,            //EndpointAddress
_INTERRUPT,                       //Attributes
DESC_CONFIG_WORD(9),        //size
0x01,                        //Interval

/* Endpoint Descriptor */
0x07,/*sizeof(USB_EP_DSC)*/
USB_DESCRIPTOR_ENDPOINT,    //Endpoint Descriptor
HID_EP | _EP_OUT,            //EndpointAddress
_INTERRUPT,                       //Attributes
DESC_CONFIG_WORD(9),        //size
0x01                        //Interval

There is something called Endpoint Descriptor, which, among other things, defines the wMaxPacketSize - which is what the Host Controller Interface drivers use to subdivide a large USB transfer into smaller packets.

This is entirely different from the EP0 buffer size - which however, is always required to be larger than the wMaxPacketSize. My guess is (try posting your usb_config.h and usb_descriptors.c, if you use Microchip USB stack), that you're either trying to use 8-byte long EP0 with 64-byte long wMaxPacketSize, which is truncating the transfer.

Also, be aware that in USB 1.1 Low Speed, the wMaxPacketSize cannot exceed 8, and in USB 1.1 Full Speed it cannot exceed 64.

0x07,/*sizeof(USB_EP_DSC)*/
USB_DESCRIPTOR_ENDPOINT,    //Endpoint Descriptor
HID_EP | _EP_IN,            //EndpointAddress
_INTERRUPT,                       //Attributes
DESC_CONFIG_WORD(9),        //size
0x01,                        //Interval

/* Endpoint Descriptor */
0x07,/*sizeof(USB_EP_DSC)*/
USB_DESCRIPTOR_ENDPOINT,    //Endpoint Descriptor
HID_EP | _EP_OUT,            //EndpointAddress
_INTERRUPT,                       //Attributes
DESC_CONFIG_WORD(9),        //size
0x01                        //Interval
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文