Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
9 years, 2 months ago.
USBHID minimal cookbook example not working as expected
Hello, recently i tried the USBHID example found here: https://developer.mbed.org/cookbook/USBHID-bindings-.
I tried it with pywinusb and pyusb as the computer side program. What i can do is receive messages send from my NUCLEO-F429ZI, but the device itself does not receive any data correct. The if(hid.read(&recv_report)) in line 31 evaluates to true so something is received and the code enters the if path.
But then recv_report.length is always zero and there is no data in the report except zeros.
pyusb tells me, that it successfully sended 8 bytes. I am on Windows 10. Does anybody find a bug in my example or is this a mbed bug?
Thanks in advance, moro
slightly modified example from the cookbook
#include "mbed.h"
#include "USBHID.h"
//We declare a USBHID device. Input out output reports have a length of 8 bytes
USBHID hid(8, 8);
//This report will contain data to be sent
HID_REPORT send_report;
HID_REPORT recv_report;
Serial pc(USBTX, USBRX);
Timer debugTimer;
int main(void) {
send_report.length = 8;
debugTimer.start();
while (1) {
//Fill the report
for (int i = 0; i < send_report.length; i++) {
send_report.data[i] = rand() & 0xff;
}
//Send the report
hid.send(&send_report);
//try to read a msg
if(hid.read(&recv_report)) {
pc.printf("received at %d, length of report %d: ", debugTimer.read_us(), recv_report.length);
for(int i = 0; i < 8; i++) {
pc.printf("%d ", recv_report.data[i]);
}
pc.printf("\r\n");
}
wait(1.0);
}
}