Add hidraw backend for FreeBSD#730
Conversation
|
Currently, some stuff like the Report Descriptor parser and error registry routine are copied from Linux and I think they are platform independent. Can we create a common directory or hidraw directory in code then put them inside? Have tested by the hidtest program. |
49a7a62 to
6e7a25a
Compare
|
Thanks for @Youw your review:). Then, What is your opinion about this?
|
I thinjk that is a good idea, but I don't think it really is nesessary to do so in scope of this PR. |
|
Nice. This will address the following issue. |
|
Oops. I forget we have udev-devd stuff. Maybe we should use udev also? |
I lost context here. What for? Seem like you have all the functionality implemented already. Aren't you? |
Yes, all functionality is fully implemented. I am just thinking if we should use libudev make hidapi more portable. |
|
First test under FreeBSD 14.1 Release, under a physical machine (Chuwi mini PC, Intel J4125 CPU, 8GB RAM, 256GB SSD) There are a few compiler warnings. |
|
Fix it:). Forget to fix the warning. |
|
Somehow hidtest-hidraw will seg fault with the Microchip Simple HID example. |
Thanks. The compiler warnings are gone. The Segfault issue is still there though. |
|
I am stilll using VirtualBox VM under Windows 11 for this test, but I have switched the VM back to the default USB configuration (OHCI + EHCI). Then I use my trusted modified Generic PIC USB HID example (modified from the Lakeview Research Generic HID example to add Input/Output/Feature report IDs). It is a Full Speed USB device. It was mentioned in the following discussion. FW source code and old libusb test codes are here. The device works well under Windows. It also works fine with this PR under FreeBSD VM. |
Just buy a EZ-USB FX2LP. I spend two days on configuring stm32h750 + usb3320 and it fails. I think there are some design flaws on stm32h750 as some pin output doesn't follow the ulpi standard. |
Hi, I received the EXUSB FX2 last week. I spent the weekend setting up the toolchain, since the SDK is very outdated and Infineon no longer maintains or provides the download link. I’ve fixed the firmware now. The issue turned out to be quite simple: you forgot to arm EP1OUT the first time. To fix it, add: EP1OUTBC = anynumber; at the end of TD_Init(). |
|
@mcuee I also did some experiments. FX2 is packet-based, which means if you set MPS = 64 and the report size = 128, it will not work correctly when the device wants to send a short packet (< 64 bytes). The reason is the following: xHCI assumes there will be 2 packets (128 / 64), so it sends the following sequence to the device: IN token with size = 64 This completes a full cycle for receiving a 128-byte report from the device. However, if the device sends a short packet, the sequence becomes: IN token with size = 64 As a result, the receive operation eventually hangs and fails. |
|
Thanks a lot for the updates. Let me digest and check again.
You are absolute right here. I have seen strange issues previously with random data for the initial run. I am not the author of the origina FX2HID code. The original auther is Jan Axelson (author of the book "USB Complete").
I am not so sure about this one. Different OS may be different as well. Let me check. |
|
I have some modified EZ-USB FX2HID firmware as well. I am not a programmer myself, please check as well. Thanks. Modified version of the fx2hid firmware mods (with bug fixes in Common files from Cypress |
|
Infineon/Cypress CY3689 and CY3684 download links (you need to register). The clones are mostly copy of CY3689.
|
BTW, EZ-USB FX2LP is a High Speed USB device, do you mean to say EHCI and not xHCI?
Another thing, I have tested different firmwares. So you may get confused here.
I will carry out tests under FreeBSD over the weekend. |
USB standard is a little bit confusing. You actually attached a USB 2.0 device to xHCI. But since the xHCI controller is a xHCI controller + eHCI controller internally, so...
I found a bug in the FreeBSD xHCI implementation that cause the data only receive bi-transfer in <= 64 byte case. Please also apply this patch while you are testing. https://reviews.freebsd.org/D57146. Send 64 bytes (report size is 128) can not be resolved as the problem I have explain previously. There is a flag in libusb call LIBUSB_TRANSFER_ADD_ZERO_PACKET that can solve this problem. |
|
@mcuee 3 bytes also work in both 64 and 128 bytes report. 2 bytes won't work as it is a hard limit in FreeBSD hidraw interface. If you need a ISO image to test, I can build one for you with my patch. |
Ok, will build one later. I just merge my patch upstream and need times to build world and kernel. |
Hi, I just send a link to your email. Please take a look. |
Great, now this PR works perfectly under your FreeBSD 16.0 Current build (tested with VirtualBox VM first). |
|
PR #728 also works fine and hidapi git has the issue with #274.
|
Indeed 2 bytes will not work with FreeBSD hidraw backend. libusb backend works fine (git or PR #728) I will carry out more testing later today and tomorrow. |
Thanks! Hope we can merge this patch ASAP:). |
|
Going back to the Generic HID PIC FW example (Full Speed USB device), there are no issues. |
|
Going to the original Generic PIC FW (unmodified, from Jan Axelson, Full Speed USB device) with two bytes reoort, it also works. |
|
Please re-review as well. Thanks. |

FreeBSD support hidraw in Kernel from 13.0.
By using libusb only, we can only see the HID device from usb. To address this, we implement hidraw backend for FreeBSD.
Just like Linux use libudev to handle usb specified HID stuff (like Manufacture), we use libusb to handle it.
Sponsored-by: FreeBSD Foundation