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 will test with a physical machine tomorrow. |
I will do a quick reviw from the AI comment again and do rebasing tomorrow. |
Ah yes. Sorry for missing this. |
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 Sponsored-by: Framework Laptop. Inc
|
I just rebase and clean up the commit. All AI's feedback is fixed. |
|
Preparing to test with a physical machine, an Chuwi mini PC with Intel J4125 CPU. |
|
Test log. Edit: this test is not using the latest push today but previous version. I will test that later. Interestingly it works every other time. Looks like there may be a data toggle related issues. Supposedly EZ-USB FX2LP can handle data toggle bit automatically. |
|
The above is not the issue of this PR though. libusb backend has the same issue. So does PR #728. Edit: this test is not using the latest push today but previous version. I will test that later. |
|
Using the latest git push of this PR #730. As expected, no changing of the test results. |
|
Now I will continue the 128bytes FX2HID mod firmware testing. Unfortunately this PR does not work. PR #728 also does not seems to work either. Strange. Interestingly hidapi git libusb backend (same as PR#730 libusb backend works a bit better and returns 64 bytes of data. But there is an offset of 64 bytes. |
|
Unfortunately I am not so sure how to force it to Full Speed mode using the physical machine. I already applied the changes to /boot/loader.conf and reboot the machine. |
|
The following bootloader.conf does not work either even after the reboot. |
This looks like a firmware bug, right? |
Not really in this particular case. More like a FreeBSD USB bug to me since other Operating Systems have no issues. Also EZ-USB FX2LP is supposed to handle data toggle correctly from HW side. BTW, this original FW comes from Jan Axelson, no modification from my side. If possible, please get the cheap EZ-FX2LP board from online store and try yourself. |
|
For anyone interested in High Speed USB development and testing, EZ-USB FX2LP is highly recommended. The board is pretty cheap to get from 3rd party vendors (cheap clone of CY3689 EZ-USB FX2LP Discovery Kit) For anyone interested in Super Speed USB development and testing, EZ-USB FX3 is highly recommended. The board is not that cheap but still manageable. It used to be at around US$50 but now it is at US$90.15. |
|
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. |

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