-
Notifications
You must be signed in to change notification settings - Fork 440
Add hidraw backend for FreeBSD #730
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No more comments
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. |
Ooops. FreeBSD hidraw API is outdated. It misses HIDIOCSOUTPUT and HIDIOCGINPUT ioctls. |
Hmm, what about FreeBSD 15.0-Current? Does it have the two IOCTLs you mentioned? @aokblast is indeed using FreeBSD 15.0-Current for testing. |
Not yet. I made a patch with both ioctls(). It is only compile tested. I'll commit after one has tested it. |
The IOCTLs have been added to FreeBSD on 27-April-2025.
|
Can I do it seperately? I think it needs some version check code to enable it. BTW, thought I don't buy the chip you have, I found 1 stm32f103 in my bedroom yesterday. Then I try to reproduce your environment. I have the following questions: Is the wMaxPacket under 64bytes with multiple transport of blocks or wMaxPacket > 64? Is your condition as following?
If so, I can reproduce it throught stm32f103 as I set the Input Descriptor to 1023 bytes. Or
|
Also, they have been merged to 14-STABLE today. |
Yes. That can be another follow-up PR.
Yes, STM32 MCU is a good one to use.
No matter the wMaxPacket number, but rather the HID report length (Input report or Output report in my test, not so sure about Feature report). BTW, my device is a high speed USB device (Cypress EZ-USB FX2LP). But it does not matter.
HID report length greater than 64 bytes will cause issus to this PR. The current libusb backend also got the issue. I am using hidapitester to carry out the test so it is not that easy to differentiate the two cases you mentioned. In any case, it is good that you can at least reproduce the issue (first case). You can also try to change 1023 to something like 80, 128 or 512 to see if the issue still exist. Then you can try to debug the issue to see if it is related to FreeBSD hidraw implementation or your PR. |
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
Oops, I thought you are using FULL speed device (64byte packets) with hid descriptor larger than 64byte. That is why I ask you what is the value of wMaxPakcet. Because I though you are using an device unable to configure from stm32cubemx(If you type you want to configure packet size higher than 64, you needs to be the HIGH speed device) So you are using the HIGH speed? If so, I needs extra hardware to test it. HIGH speed needs MCU have clock higher than 120Mhz. It is impossible for stm32f103. I am trying to find an available stm32f405 to test it. In the current modification, I support HIDIOC family ioctl for all and use ifdef to provide backward support, you can test it with the new 14-STABLE or 15-CURRENT but I thought they will have the same result. Besides, I make hidtest compiles hidtest_hidraw and hidtest_libusb. |
My FW is based on this one, with Cypress EZ-USB FX2LP. USB Descriptors
Full source codes and binaries: |
Using FreeBSD 15 Current snapshot 1-May-2025. So we can see that the hidraw backend does not work from this PR. But at least it does not have regression on the libusb backend since the problem is the same as current hidapi git in terms of libusb backend.
|
Now I am clean of the fault, it is the same as what you see. No timeout, immediately exit.
|
Ok, I see. I should take some time to get a device able to afford USB HIGH speed |
Are you saying that you no longer have issuses with your own full speed STM32 MCU implementation if the HID Input/Output report length are larger than 64 Bytes? Or you still have the issue? If possible, please post the USB descriptors of your device and the test results. Thanks. |
More about the test device.
|
Forcing the device to run in Full Speed mode and now this PR works.
|
@aokblast @wulf7 |
Yes, hid full speed with larger than 64 byte report works. Code and result:
usbconfig -d0.3 dump_all_desc:
Report Descriptor: |
If you can, please get the FX2LP break-out board from Taobao/AliExpress/Amazon/etc. It is pretty cheap. FW binary and source codes are here. It is a quick minor modification of Jan Axelson's FX2HID example from here. There may be a bit of challenge if you want to rebuild the source code as it may require a full version of Keil C51 compiler. I happen to have access to a pretty old version of Keil C51 compiler at work. I am not so sure about the efforts to port the code to use the free sdcc toolchain. It may be possible because of the nice sdcc based libraries. Jan's HID page has some other FW as well, for example, for Microchip USB PIC18. I was able to use that as a base for my other HIDAPI testing but I have not figured out how to increase the HID report size above 64 bytes with that FW. I have the PIC18F87J50 USB PIM (free tool from Microchip many years ago). More testing device discussions: |
Update with the main git branch to trigger another CI run. |
Since you two are the FreeBSD power user I know of, please help to check if you can give this PR a try. You need to use FreeBSD 14 Stable or 15 Current. Thanks. This has something to do with avrdude as well. For example, if it works, it is a potential workaround for Issue #274. FreeBSD HIDAPI is now based on libusb, so it is affected by the Issue #274. |
@mcuee builds okay, could you please provide test steps, its a long thread and I am quite short on time sorry :-P |
Great. Test steps: make sure you use the hidraw driver.
I have mentioned my test device in the comments above. |
I just ordered one. Let's seen when it arrives. |
I am in Canada right now. I get the USB3320 and try to setup the experiment environment with my stm32h750. I will test with it later after my experiment environment is setup with other patches you have mentioned. |
@aokblast I tend to believe my modification FW may not be totally correct (interrupt transfer for the IN/OUT endpoint may be correct; Control Transfer to the IN/OUT endpoint may need to be checked). I am not a progammer myself and my main contributions for the Open Source projects (eg: libusb, libusb-win32, libusbK, avrdude, pyusb, libusbdotnet, libftdi and OpenOCD) are mainly on the testing and technical side. STM32 is a popular ARM Cortex MCU family and STM32H750 is a powerful one, very good for libusb and hidapi related testing. If you need Super Speed USB testing device (probably not needed for hidapi but more for libusb project), I will highly recomemend EZ-USB FX3 board, CYUSB3KIT-003 EZ-USB™ FX3 SuperSpeed explorer kit, at US$$45.93 plus shipment. Example test FW used in libusbK project, based on Cypress (now part of Infineon) FW examples. |
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