This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

STM32F4 USBD keyboard problem with USB_CM3_L.lib

Hi,

I work with STM32F4LP5 chip and Keil USB device stack.

I configure USB-HID with HID_REPORT_DESCRITOR to 63 and a specific descriptor as follow :

#define KBD_REPORT_DESC_SIZE                                           63U
const uint8_t usbd_hid0_report_descriptor[KBD_REPORT_DESC_SIZE] =
{
0x05, 0x01, // Usage Page (Generic Desktop),
0x09, 0x06, // Usage (Keyboard),
0xA1, 0x01, // Collection (Application),
0x75, 0x01, // Report Size (1),
0x95, 0x08, // Report Count (8),
0x05, 0x07, // Usage Page (Key Codes),
0x19, 0xE0, // Usage Minimum (224),
0x29, 0xE7, // Usage Maximum (231),
0x15, 0x00, // Logical Minimum (0),
0x25, 0x01, // Logical Maximum (1),
0x81, 0x02, // Input (Data, Variable, Absolute),
//;Modifier byte
0x95, 0x01, // Report Count (1),
0x75, 0x08, // Report Size (8),
0x81, 0x03, // Input (Constant),
//;Reserved byte
0x95, 0x05, // Report Count (5),
0x75, 0x01, // Report Size (1),
0x05, 0x08, // Usage Page (LEDs),
0x19, 0x01, // Usage Minimum (1),
0x29, 0x05, // Usage Maximum (5),
0x91, 0x02, // Output (Data, Variable, Absolute),
//;LED report
0x95, 0x01, // Report Count (1),
0x75, 0x03, // Report Size (3),
0x91, 0x03, // Output (Constant), ;LED report?
// padding
0x95, 0x06, //................// Report Count (6),
0x75, 0x08, // Report Size (8),
0x15, 0x00, // Logical Minimum (0),
0x25, 0x68, // Logical Maximum(104),
0x05, 0x07, // Usage Page (Key Codes),
0x19, 0x00, // Usage Minimum (0),
0x29, 0x68, // Usage Maximum (104),
0x81, 0x00, // Input (Data, Array),
0xc0 // End Collection
};

In main, i do USB initialization layer :

    USBD_Initialize (0);       // USB Device 0 Initialization
    USBD_Connect    (0);       // USB Device 0 Connect  

PC HOST view and is ok to mangage keyboard USB-HID : Ok

Then the first call to USBD_HID_GetReportTrigger() function works fine and send a correct 8 bytes flow  to HOST (pc) :

USBD_HID_GetReportTrigger(0, 0, (uint8_t *)&keyBoardHIDsub, sizeof(keyBoardHIDsub) );

But STM32 won't send 8 bytes to release the key and send only one 0 byte over USB link and HOST repeat the key in loop.

The second call to USBD_HID_GetReportTrigger give 0x23 error : usbDriverBusy

Why ?

Regards,

G.Grange

Parents Reply Children
  • Thanks for samples, but i can't replace USB_CM3_L.lib by theses sources.

    I finally find the bug, You can use HID management for keyboard if you generate a correct keyboard report profil. I define 'User Provided HID Report Descriptor" as follow :

    // User Provided HID Report Descriptor
    // for standard keyboard (size of this descriptor is 63 bytes)
    // From
    www.microchip.com/.../m816038.aspx
    extern const uint8_t usbd_hid0_report_descriptor[];
    const uint8_t usbd_hid0_report_descriptor[63] = {
      HID_UsagePage(HID_USAGE_PAGE_GENERIC),       // 0x05, 0x01, // Usage Page (Generic Desktop),
      HID_Usage(HID_USAGE_GENERIC_KEYBOARD),       // 0x09, 0x06, // Usage (Keyboard),
      HID_Collection(HID_Application),             // 0xA1, 0x01, // Collection (Application),
          HID_UsagePage(HID_USAGE_PAGE_KEYBOARD),  // 0x05, 0x07, // Usage Page (Key Codes);
          HID_UsageMin(224),  //  0x19, 0xE0, // Usage Minimum (224),
          HID_UsageMax(231),  //  0x29, 0xE7, // Usage Maximum (231),
          HID_LogicalMin(0),  //  0x15, 0x00, // Logical Minimum (0),
          HID_LogicalMax(1),  //  0x25, 0x01, // Logical Maximum (1),
          HID_ReportSize(1),  //  0x75, 0x01, // Report Size (1),
          HID_ReportCount(8), //  0x95, 0x08, // Report Count (8),
                HID_Input(HID_Variable), //  0x81, 0x02, // Input (Data, Variable, Absolute), ; Modifier byte
          HID_ReportCount(1), //  0x95, 0x01, // Report Count (1),
          HID_ReportSize(8),  //  0x75, 0x08, // Report Size (8),
          HID_Input(HID_Constant),  //  0x81, 0x01, // Input (Constant), ; Reserved byte
          HID_ReportCount(5), //  0x95, 0x05, // Report Count (5),
          HID_ReportSize(1),  //  0x75, 0x01, // Report Size (1),
          HID_UsagePage(HID_USAGE_LED_DO_NOT_DISTURB),   // 0x05, 0x08, // Usage Page (Page# for LEDs),    
          HID_UsageMin(1),  //  0x19, 0x01, // Usage Minimum (1),
          HID_UsageMax(5),  //  0x29, 0x05, // Usage Maxmimum (5),
                HID_Output(2),        //  0x91, 0x02, // Output (Data, Variable, Absolute), ; LED report
          HID_ReportCount(1), //  0x95, 0x01, // Report Count (1),
          HID_ReportSize(3),  //  0x75, 0x03, // Report Size (3),
                HID_Output(HID_Constant), // 0x91, 0x01, // Output (Constant), ; LED report padding
          HID_ReportCount(6), //  0x95, 0x06, // Report Count (6),
          HID_ReportSize(8),  //  0x75, 0x08, // Report Size (8),
          HID_LogicalMin(0),  //  0x15, 0x00, // Logical Minimum (0),
          HID_LogicalMax(101),//  0x25, 0x65, // Logical Maximum (101),
          HID_UsagePage(HID_USAGE_PAGE_KEYBOARD), //  0x05, 0x07, // Usage Page (Key Codes),
                HID_UsageMin(0),   // 0x19, 0x00, // Usage Minimum (0),
                HID_UsageMax(101), // 0x29, 0x65, // Usage Maximum (101),
                HID_Input(0),  // 0x81, 0x00, // Input (Data, Array), ; Key arrays (6 bytes)
      HID_EndCollection, // End Collection
    };

    This point is close.

    Thanks for support,

    G.Grange

  • Thanks for samples, but i can't replace USB_CM3_L.lib by theses sources.

    I finally find the bug, You can use HID management for keyboard if you generate a correct keyboard report profil. I define 'User Provided HID Report Descriptor" as follow :

    // User Provided HID Report Descriptor
    // for standard keyboard (size of this descriptor is 63 bytes)
    // From
    www.microchip.com/.../m816038.aspx
    extern const uint8_t usbd_hid0_report_descriptor[];
    const uint8_t usbd_hid0_report_descriptor[63] = {
      HID_UsagePage(HID_USAGE_PAGE_GENERIC),       // 0x05, 0x01, // Usage Page (Generic Desktop),
      HID_Usage(HID_USAGE_GENERIC_KEYBOARD),       // 0x09, 0x06, // Usage (Keyboard),
      HID_Collection(HID_Application),             // 0xA1, 0x01, // Collection (Application),
          HID_UsagePage(HID_USAGE_PAGE_KEYBOARD),  // 0x05, 0x07, // Usage Page (Key Codes);
          HID_UsageMin(224),  //  0x19, 0xE0, // Usage Minimum (224),
          HID_UsageMax(231),  //  0x29, 0xE7, // Usage Maximum (231),
          HID_LogicalMin(0),  //  0x15, 0x00, // Logical Minimum (0),
          HID_LogicalMax(1),  //  0x25, 0x01, // Logical Maximum (1),
          HID_ReportSize(1),  //  0x75, 0x01, // Report Size (1),
          HID_ReportCount(8), //  0x95, 0x08, // Report Count (8),
                HID_Input(HID_Variable), //  0x81, 0x02, // Input (Data, Variable, Absolute), ; Modifier byte
          HID_ReportCount(1), //  0x95, 0x01, // Report Count (1),
          HID_ReportSize(8),  //  0x75, 0x08, // Report Size (8),
          HID_Input(HID_Constant),  //  0x81, 0x01, // Input (Constant), ; Reserved byte
          HID_ReportCount(5), //  0x95, 0x05, // Report Count (5),
          HID_ReportSize(1),  //  0x75, 0x01, // Report Size (1),
          HID_UsagePage(HID_USAGE_LED_DO_NOT_DISTURB),   // 0x05, 0x08, // Usage Page (Page# for LEDs),    
          HID_UsageMin(1),  //  0x19, 0x01, // Usage Minimum (1),
          HID_UsageMax(5),  //  0x29, 0x05, // Usage Maxmimum (5),
                HID_Output(2),        //  0x91, 0x02, // Output (Data, Variable, Absolute), ; LED report
          HID_ReportCount(1), //  0x95, 0x01, // Report Count (1),
          HID_ReportSize(3),  //  0x75, 0x03, // Report Size (3),
                HID_Output(HID_Constant), // 0x91, 0x01, // Output (Constant), ; LED report padding
          HID_ReportCount(6), //  0x95, 0x06, // Report Count (6),
          HID_ReportSize(8),  //  0x75, 0x08, // Report Size (8),
          HID_LogicalMin(0),  //  0x15, 0x00, // Logical Minimum (0),
          HID_LogicalMax(101),//  0x25, 0x65, // Logical Maximum (101),
          HID_UsagePage(HID_USAGE_PAGE_KEYBOARD), //  0x05, 0x07, // Usage Page (Key Codes),
                HID_UsageMin(0),   // 0x19, 0x00, // Usage Minimum (0),
                HID_UsageMax(101), // 0x29, 0x65, // Usage Maximum (101),
                HID_Input(0),  // 0x81, 0x00, // Input (Data, Array), ; Key arrays (6 bytes)
      HID_EndCollection, // End Collection
    };

    This point is now close.

    Thanks for support,

    G.Grange