usbFunctionWrite incorrect length, need help
Posted: Mon Aug 11, 2014 4:10 am
Hi,
I'm trying V-USB on an ATmega328p board, using INT0 on D- (for USB suspend detection).
My project is modified from hid-data example, but I changed HID report size to 18 bytes. I wanted to test USB reliability so in the firmware side I simply copy the SET_REPORT 18 bytes buffer to a static buffer and return them for each GET_REPORT request. Because there are 18 bytes, I suppose the complete transmission should be split into 3 packets and each has 8-8-2 number of bytes.
The PC side is modified from hid-data commandline application on Windows 7/MingW, I generate 18 random bytes and send to the device, then get them back for comparison. The test is put in a while loop and I count how many iterations can be made without error.
The result appears to be not very solid. I will have an error on every 700-3000 loops randomly. When the error occurs, I can observe the length passed to usbFunctionWrite is not 8 or 2, but 6 (mostly) of the time or 7 (occasionally). This causes mismatch on the amount of data and host will think USB transaction to either stalled or cancelled.
I wonder if there are anything I can do to improve it.
TIA
I'm trying V-USB on an ATmega328p board, using INT0 on D- (for USB suspend detection).
My project is modified from hid-data example, but I changed HID report size to 18 bytes. I wanted to test USB reliability so in the firmware side I simply copy the SET_REPORT 18 bytes buffer to a static buffer and return them for each GET_REPORT request. Because there are 18 bytes, I suppose the complete transmission should be split into 3 packets and each has 8-8-2 number of bytes.
The PC side is modified from hid-data commandline application on Windows 7/MingW, I generate 18 random bytes and send to the device, then get them back for comparison. The test is put in a while loop and I count how many iterations can be made without error.
The result appears to be not very solid. I will have an error on every 700-3000 loops randomly. When the error occurs, I can observe the length passed to usbFunctionWrite is not 8 or 2, but 6 (mostly) of the time or 7 (occasionally). This causes mismatch on the amount of data and host will think USB transaction to either stalled or cancelled.
I wonder if there are anything I can do to improve it.
TIA