0

I have created a gadget HID device on embedded linux. -It's a high-speed device

  • and has two endpoint In and Out,
  • both endpoints are bulk endpoints
  • and have 512 Bytes report length each.

I have installed winusb driver and associated it to my device under Win10. The device is recognized correctly. I tried libusb "xusb" example to test it, and it's correctly recognized.

enter image description here

On Windows I'm using a code like this (simplified)

unsigned char* data[1024];
    memset(data, 0, 1024);
    int al = 0;
    int n = 0;
    data[0] = 'H';
    data[1] = 'E';
    data[2] = 'L';
    data[3] = 'L';
    data[4] = 'O';
    data[5] = 0x00;
    int utm = 512-1;

    display_buffer_hex(data, utm);
    printf("\n");
    libusb_bulk_transfer(handle, 0x01, data, utm, &al, 0);
    printf("\nWritten data %d\n", al);

This code simply put the word "HELLO" in the buffer and send the whole buffer (512 bytes) to the linux gadget (please, forgot the 512-1 for now ... it's another story)

On Linux side I'm using some code like this one (simplified):

const char *filename = "/dev/hidg0";
char buf[512];
int cmd_len;

while(1)
{
    cmd_len = read(fd, buf, 512 - 1);
    printf("recv len : %d\n", cmd_len);
          
    for (i = 0; i < cmd_len; i++)
    {
    printf(" %02x", buf[i]);
    }     
    printf("\n");
}

this code simply opens the gadget and read a packet of 512 bytes and print it to stdout.

In theory I should have the word "HELLO" printed to display (0x48 0x45 0x4C 0x4C Ox4F).

instead of 
0x48 0x45 0x4C 0x4C Ox4F

I'm getting seven 0x00 between each two bytes 
0x48 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x45 0x00 0x00 0x00 0x00 0x00 0x00 0x00 
0x4C 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x4C 0x00 0x00 0x00 0x00 0x00 0x00 0x00 
Ox4F 0x00 0x00 0x00 0x00 0x00 0x00 0x00
 

What I'm having is that on Linux side, when I dump the buffer to stdout, I can see that I receive effectively those chars, but they are spaced by 7 of 0x00 chars (I mean, each char from HELLO is printed followed by 7 chars 0x00 and then the next char ...). enter image description here

I really tracked all my code, up to calling the synchronous function from Libusb, I can see the buffer is correct. What's adding those padding chars? I'm not doing anything special. Can it be GadgetFS bug? or libUSB bug setting needed? Thx

Progman
  • 16,827
  • 6
  • 33
  • 48

0 Answers0