FX3 USB3 (some USB3) and USB2 HID interface behaviour

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
FuBe_4381791
Level 4
Level 4
10 questions asked 50 sign-ins 25 replies posted

Hello Cypress!

I've run into some really strange behaviour with my HID keyboard interface, it is essentially the same as the mouse interface example, but for some reason it works perfectly when in a USB2 connection, and on some USB3, it sometimes works, and it works perfectly on other USB3 connections (such as through my USB3 hub).

The times when it does not work, is as if the key is held down for an extended period of time, sometimes as long as 9 seconds. I have no idea what could cause this difference in behavior on different hosts.

I have tried: removing the check for failure to commit or get buffer, changing the servicing interval on the SS descriptor from the HID mouse example to a larger value, and I even tried changing the thread priority to the same as the driver level (I know this is not recommended but I was curious if the FX3 was getting hung up on a driver call) and these had no effect.

Writing this I will double check if the driver handler callback is perhaps resetting the USB thread separately. If this is the issue I will make a comment here.

What confuses me the most is that this is not an issue on all USB3, but only on some....

    outBuf.buffer = 0;

    outBuf.status = 0;

    outBuf.size   = 8;

    outBuf.count  = 8;

    CyU3PDmaChannelReset (&KeyboardDMA);

    CyU3PDmaChannelSetXfer (&KeyboardDMA, 0);

CyU3PBusyWait (2000);

while (i < to_type_len && to_type != '\0'){

        status = CyU3PDmaChannelGetBuffer (&KeyboardDMA, &outBuf, 1000);

        key_out = keyboard_output(to_type);

outBuf.buffer[0] = (uint8_t)((key_out >> 😎 & 0xff);

outBuf.buffer[1]=0x00;

outBuf.buffer[2]= (uint8_t)(key_out & 0xff);

outBuf.buffer[3]=0x00;outBuf.buffer[4]=0x00;outBuf.buffer[5]=0x00;

outBuf.buffer[6]=0x00;outBuf.buffer[7]=0x00;

        status = CyU3PDmaChannelCommitBuffer (&KeyboardDMA, 8, 0);

        CyU3PBusyWait (2000);

status = CyU3PDmaChannelGetBuffer (&KeyboardDMA, &outBuf, 1000);

outBuf.buffer[0]=0x00;outBuf.buffer[1]=0x00;

outBuf.buffer[2]=0x00;outBuf.buffer[3]=0x00;

outBuf.buffer[4]=0x00;outBuf.buffer[5]=0x00;

outBuf.buffer[6]=0x00;outBuf.buffer[7]=0x00;

status = CyU3PDmaChannelCommitBuffer (&KeyboardDMA, 8, 0);

if (status != CY_U3P_SUCCESS){

CyU3PDmaChannelReset (&KeyboardDMA);

CyU3PDmaChannelSetXfer (&KeyboardDMA, 0);

}

CyU3PBusyWait (2000);

    i++;

    }

0 Likes
1 Solution

Hello Yashwant!

I managed to get it working, the 2 changes I made was adding to the LPM a check that keyboard output was not active (I do not know if this is been used):

if (glMscDriverBusy == CyFalse && keyboard_output_command ==0){

return CyTrue;

}

return CyFalse;

and modifying the interval in the descriptor:

//Endpoint Descriptor keyboard

0x07,  //Descriptor size

0x05,  //bDescriptorType: USB_ENDPOINT_DESCRIPTOR_TYPE

Keyboard_EP,  //bEndpointAddress in 0x83 Keyboard_EP

0x03,  //bmAttributes: USB_ENDPOINT_TYPE_INTERRUPT

0x08,0x00,  //wMaxPacketSize

0x04,  //bInterval

// Super Speed Endpoint Descriptor keyboard

0x06,                           // Descriptor size

0x30,    // SS Endpoint Companion Descriptor Type CY_FX_SS_EP_COMPN_DSCR_TYPE

0x00,                           // Max no. of packets in a Burst.

0x00,                           // No streaming for Interrupt Endpoints.

0x08,0x00                       // Number of bytes per interval = 2.

Thanks!

Fujimi

View solution in original post

0 Likes
3 Replies
YashwantK_46
Moderator
Moderator
Moderator
100 solutions authored 50 solutions authored 50 likes received

Hello FuBe_4381791​,

"The times when it does not work, is as if the key is held down for an extended period of time, sometimes as long as 9 seconds. I have no idea what could cause this difference in behavior on different hosts."

=> Can you please let me know what exactly is the issue or error you are facing?

Also, please let me know the additional questions:
1.) Are you using a custom board or is it the FX3 SuperSpeed Explorer Kit?
2.) How is the "button press" action handled in the firmware?

3.) Please let me know which SDK version are you using. Also, confirm the Build Variable (Project settings > C/C++ Build >Build variable). The Build variable should be 1_3_4 when using the latest SDK 1.3.4

4.) Which OS and host controllers have been diagnosed to be having the issue when testing?

Regards,

Yashwant

0 Likes
lock attach
Attachments are accessible only for community members.

Hello Yashwant!

I've attached 3 videos to show the difference in behavior between the different interfaces.

To answer your questions directly:

1.) Are you using a custom board or is it the FX3 SuperSpeed Explorer Kit?

Custom board

2.) How is the "button press" action handled in the firmware?

There is a separate GPIO thread that listens to button presses from volatile bool, when the GPIO press is detected, it sets a flag for the keyboard to type when it can. This way it avoids a "denouncing" or "double pressing" effect. The GPIO interrupt sets the volatile bool.

3.) Please let me know which SDK version are you using. Also, confirm the Build Variable (Project settings > C/C++ Build >Build variable). The Build variable should be 1_3_4 when using the latest SDK 1.3.4

Yes FX3SDKVERSION is using 1.3.4 and is used for "Paths and Symbols"

4.) Which OS and host controllers have been diagnosed to be having the issue when testing?

So far just Windows 10

I don't see any issues with the below... The SS descriptor is essentially the same as the HID mouse. I am still trying a few small changes to the driver callback incase the USB3 interface is sending a reset signal. I may change the method used for sending the entire keyboard output in a single instance to staggering it out.

SS descriptor section (there are 2 other interfaces before this):

// Interface 3 keyboard

0x09,  //Descriptor size

0x04,  //Interface Descriptor type

0x02,  //Interface number

0x00,  //Alternate setting number

0x01,  //Number of end points

0x03,  //Interface class : USB_DEVICE_CLASS_HUMAN_INTERFACE

0x01,  //Interface sub class : HID_SUBCLASS_NONE ??? 0 or 1?

0x01,  //Interface protocol code : HID_KEYBOARD

0x00,  //Interface descriptor string index

//HID Descriptor keyboard

0x09,  //Descriptor size

0x21,  //Endpoint Descriptor Type

0x10,0x11,  //bcdHID : 1.11

0x00,  //bCountryCode

0x01,  //bNumDescriptors

0x22,  //bDescriptorType: HID_REPORT_DESCRIPTOR_TYPE

0x3F,0x00,  //wDescriptorLength

//Endpoint Descriptor keyboard

0x07,  //Descriptor size

0x05,  //bDescriptorType: USB_ENDPOINT_DESCRIPTOR_TYPE

Keyboard_EP,  //bEndpointAddress in 0x83 Keyboard_EP

0x03,  //bmAttributes: USB_ENDPOINT_TYPE_INTERRUPT

0x08,0x00,  //wMaxPacketSize

0x05,  //bInterval

// Super Speed Endpoint Descriptor keyboard

0x06,                           // Descriptor size

0x30,    // SS Endpoint Companion Descriptor Type CY_FX_SS_EP_COMPN_DSCR_TYPE

0x00,                           // Max no. of packets in a Burst.

0x00,                           // No streaming for Interrupt Endpoints.

0x08,0x00                       // Number of bytes per interval = 2.

};

Keyboard descriptor:

const uint8_t CyFxUSBReportDscr_Keyboard[] __attribute__ ((aligned (32))) =

{

    0x05, 0x01,//     ; Usage Page (Generic Desktop)

0x09, 0x06,//     ; Usage (Keyboard)

0xA1, 0x01,//     ; Collection (Application)

0x05, 0x07,//     ;       Usage Page (Key codes)

0x19, 0xE0,// ; Usage minimum (234)

0x29, 0xE7,// ; Usage maximum (231)

0x15, 0x00,// ; Logical minimum (0)

0x25, 0x01,// ; Logical maximum (1)

0x75, 0x01,// ; Report size (1)

0x95, 0x08,// ; Report count (8)

0x81, 0x02,// ; Input (data, variable, absolute)

0x95, 0x01,// ; Report count (1)

0x75, 0x08,// ; Report size (8)

0x81, 0x01,// ; Input (constant)

0x95, 0x05,// ; Report count (5)

0x75, 0x01,// ; Report size (1)

0x05, 0x08,// ; Usage Page (LED)

0x19, 0x01,// ; Usage minimum (1)

0x29, 0x05,// ; Usage maximum (5)

0xB1, 0x02,// ; Feature (data, variable, absolute)

0x95, 0x01,// ; Report count (1)

0x75, 0x03,// ; Report size (3)

0xB1, 0x01,// ; Feature (constant)

0x95, 0x06,// ; Report count (3)

0x75, 0x08,// ; Report size (8)

0x15, 0x00,// ; Logical minimum (0)

0x25, 0x65,// ; Logical maximum (101)

0x05, 0x07,// ; Usage page (key codes)

0x19, 0x00,// ; Usage minimum (0)

0x29, 0x65,// ; Usage maximum (101)

0x81, 0x00,// ; Input (data, array)

0xC0

};

0 Likes

Hello Yashwant!

I managed to get it working, the 2 changes I made was adding to the LPM a check that keyboard output was not active (I do not know if this is been used):

if (glMscDriverBusy == CyFalse && keyboard_output_command ==0){

return CyTrue;

}

return CyFalse;

and modifying the interval in the descriptor:

//Endpoint Descriptor keyboard

0x07,  //Descriptor size

0x05,  //bDescriptorType: USB_ENDPOINT_DESCRIPTOR_TYPE

Keyboard_EP,  //bEndpointAddress in 0x83 Keyboard_EP

0x03,  //bmAttributes: USB_ENDPOINT_TYPE_INTERRUPT

0x08,0x00,  //wMaxPacketSize

0x04,  //bInterval

// Super Speed Endpoint Descriptor keyboard

0x06,                           // Descriptor size

0x30,    // SS Endpoint Companion Descriptor Type CY_FX_SS_EP_COMPN_DSCR_TYPE

0x00,                           // Max no. of packets in a Burst.

0x00,                           // No streaming for Interrupt Endpoints.

0x08,0x00                       // Number of bytes per interval = 2.

Thanks!

Fujimi

0 Likes