Skip to content
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

RawHID.write not working on a Leonardo clone #91

Closed
jh1-git opened this issue Nov 2, 2016 · 13 comments
Closed

RawHID.write not working on a Leonardo clone #91

jh1-git opened this issue Nov 2, 2016 · 13 comments

Comments

@jh1-git
Copy link

jh1-git commented Nov 2, 2016

Using the /examples/RawHID/RawHID/RawHID.ino sketch on a Leonardo clone board with a LED and Button attached. Using the test program in /extras/rawhid/ to communicate with it.
I am able to send data from the PC to the board - the USB LED and LED flash.
When I press the button the LED flashes but the USB LED doesn't flash and nothing is received by the PC. I have also used Wireshark to sniff the USB traffic and it show there is no communication when I press the Button.

@NicoHood
Copy link
Owner

NicoHood commented Nov 5, 2016

Arduino IDE 1.6.9 was reported to work and creashed with 1.6.10.

@jh1-git
Copy link
Author

jh1-git commented Nov 6, 2016

Looks like this change in the arduino IDE between versions 1.6.9 and 1.6.10 makes a RawHID.write of 64 bytes stop working.
arduino/Arduino#4864
Since 64 bytes is the max size that can be sent in a packet on the 32u4 (USB_EP_SIZE), and apparently some USB transfers, if they are exactly a multiple of the max packet size, require that a zero length packet be sent after the last full packet, instead of figuring out when they need to send a zero length packet, they decided with this patch to just not allow sending a packet = USB_EP_SIZE. But since that is the size packets RawHID is configured to use, it causes RawHID.write to fail.

@jh1-git
Copy link
Author

jh1-git commented Nov 6, 2016

As a workaround you can either revert the arduino IDE change referenced above.
In arduino\hardware\arduino\avr\cores\arduino\USBCore.cpp line 260 change
return USB_EP_SIZE - 1 - FifoByteCount();
to
return USB_EP_SIZE - FifoByteCount();
though this may leave you with the issue they were trying to fix in CDC and other modes,
or you can change \libraries\HID\src\SingleReport\RawHID.h in line 50 from
#define RAWHID_TX_SIZE RAWHID_SIZE
to
#define RAWHID_TX_SIZE 63
or some other value under 64, and then, when you call RawHID.write, send this smaller packet size.

@NicoHood
Copy link
Owner

It also broke the gamepad. Vote the bug here: arduino/Arduino#5732

@mnhpias
Copy link

mnhpias commented Mar 10, 2017

I'm unable to work RawHID.write ,
I changed \libraries\HID\src\SingleReport\RawHID.h in line 50 from #define RAWHID_TX_SIZE RAWHID_SIZE to #define RAWHID_TX_SIZE 63 , then I sent 50 bytes long uint8_t throgh RawHID.write , but pc didn't receive anything . pls help me to make RawHID.write working .

@jbutzine
Copy link

jbutzine commented Apr 6, 2017

Has a solution been identified for this problem? Please update this thread if that is the case.

RawHID.write does not work. No data is sent to the PC.

@NicoHood
Copy link
Owner

NicoHood commented Apr 6, 2017

@jbutzine Which IDE version do you use? It should be fixed in 1.8.2 but I never tested it. And I have no time in the near future

@jbutzine
Copy link

jbutzine commented Apr 6, 2017

I'm using 1.8.2

@jbutzine
Copy link

jbutzine commented Apr 6, 2017

Ok. It works. I have to back out a few changes I tweaked to determine what change made it work. I'll update this thread.

@jbutzine
Copy link

jbutzine commented Apr 6, 2017

The call to RawHID.write needs to be : RawHID.write(buffer, (sizeof(buffer)-1));
Perhaps this is only when the buffer size is 64.
Now that the code will actually send data, any thoughts on how I can still send 64 bytes instead of 63?

@NicoHood
Copy link
Owner

NicoHood commented Apr 6, 2017

Then the bug is still inside the code or arduino core. Someone needs to look at it and fix it. I dont have time nor equipment now.

@jbutzine
Copy link

My apologies; it does appear that this bug was fixed with the 1.8.2 release of Arduino. My build was still using the old USBCore.cpp. When doing the Arduino update the install updated the USBCore.cpp located here: C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino\USBCore.cpp

Instead of the one here: C:\Users\xxxxxxxx\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.17\cores\arduino\USBCore.cpp

When I manually updated the file in the AppData directory, then the 64 byte transactions worked. Sorry for the boondoggle.

@IgorIemeluyanofflyanov
Copy link

Thank to authors ! I change c:\Users\Documents\Arduino\libraries\HID-Project\src\SingleReport\RawHID.h to
#define RAWHID_TX_SIZE 64 and all work fine! Arduino 1.8.13 + HoodLoader2.0.5+ Arduino UNO (at16u2)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants