在嵌入式系统中编程USB以发送一些数据到主机进行打印
我的任务是为我们的嵌入式软件编写 USB 驱动程序,以将原始数据发送到主机。这将用于向主机发送一些日志数据。我们使用 iMX31 litekit 进行开发。
从我读过的关于USB的文档来看,我的理解是嵌入式设备将仅处于设备模式。它也只会与主机通信。
那么有人可以指导我吗?欢迎任何文章、参考或代码。
I have been tasked with writing a USB driver for our embedded software to send raw data to Host. This will be used to send some logging data to host. We are using iMX31 litekit for development.
From the documents that I have read on USB, my understanding is that the embedded device will be in device mode only. Also it will only be communicating with host machine.
So can any one guide me here? Any article, reference or code is welcome.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
需要考虑的一些事项:
这是相机或数据记录器等高带宽设备,还是低带宽设备?
对于低带宽,我强烈考虑让您的设备充当 USB HID 类。这是支持键盘、鼠标、操纵杆、游戏手柄等的设备类。将数据发送到几乎任何应用程序都相对容易,并且通常不需要您在主机端编写自定义设备驱动程序。仅后一个功能通常就值得将数据稍微扭曲成 HID 类假定的形状。所有支持 USB 的桌面操作系统都可以使用 HID 设备,因此您可以相当轻松地获得广泛的兼容性。
对于高带宽,如果您的设备符合完善的设备类别之一(可以使用线路主机端的库存设备驱动程序),您仍然会得到更好的服务。一种常用的方法是使用大容量存储类,并模拟磁盘驱动器包含一个文件。然后,您的设备就像磁盘一样安装在主机上,并且您可以通过读取和写入一个(或几个)文件来进行通信。
我希望对于任何实现 HID 和大容量存储之一或两者的严肃 USB 设备芯片组来说,都会有相当多的示例代码。
如果您确实必须进入完全自定义的设备领域,那么您将需要为每个主机平台构建设备驱动程序。如果开源 libusb 库的许可证与您的项目兼容,它可能会有所帮助。在较新版本的 Windows 中,还可以使用 用户模式驱动程序框架,具有许多与 libusb 相同的优点,但不能从 Windows 平台移植。
我开发的最后一个自定义设备基于 Cypress 设备,我们能够提供他们的驱动程序和关联的 DLL,以使我们的应用程序代码更易于构建。我不知道是否有适用于您的设备的同等产品。
要获得真正好的概述,我推荐 USB 常见问题解答,以及 Jan 的书的最新版本, USB 完整。
Some things to consider:
Is this a high bandwidth device like a camera or data recorder, or a low bandwidth device?
For low bandwidth, I would strongly consider making your device act as a USB HID class. This is the device class that supports keyboards, mice, joysticks, gamepads, and the like. It is relatively easy to send data to nearly any application, and it generally doesn't require that you write a custom device driver on the host side. That latter feature alone is often worth the cost of lightly contorting your data into the shape assumed by the HID class. All the desktop operating systems that do USB can use HID devices, so you get broad compatibility fairly easily.
For high bandwidth, you would still be better served if your device fits one of the well established device classes, where a stock device driver on the host end of the wire can be used. One approach that often works is to use the Mass Storage class, and emulate a disk drive containing one file. Then, your device simply mounts on the host as if it were a disk, and you communicate by reading and writing to one (or a few) file.
I would expect there to be a fair amount of sample code out there for any serious USB device chipset that implements either or both of HID and Mass Storage.
If you really must wander into fully custom device territory, then you will need to be building device drivers for each host platform. The open source libusb library can be of some help, if its license is compatible with your project. There are also ways in newer versions of Windows to develop USB drivers that run in user mode using the User Mode Driver Framework that have many of the same advantages of libusb, but are not portable off the Windows platform.
The last custom device I worked on was based on a Cypress device, and we were able to ship their driver and an associated DLL to make our application code easier to build. I don't know off the cuff if there is any equivalent available for your device.
For a really good overview, I recommend the USB FAQ, and the latest edition of Jan's book, USB Complete.