Emulate USB Keyboard with MCBSTM32Exl

Hi,

I use the board MCBSTM32Exl (http://www.keil.com/arm/mcbstm32exl/) and i wanna that my Board emulate a USB HID Keyboard (When i use the push-button User, the char 'Q' is send to my PC Host). For this, i studied the STMicroelectronics' library "USB full-speed device library" (www.st.com/.../um0424.zip) and adapted interruptions/GPIOs to use this Flibrary with my Board. Also, my PC recognize the device and i successed send data (I watched with a sniffer).

But, it's not like a keyboard, i tried to change the descriptor but it does'nt work (for exemple, my PC don't recognize the device)...

Have you any idea to help me ?

Regards,
ealary.

Parents
  • 1) Run Custom_HID project on uVision IDE, select "STM3210E-EVAL" at the target pulldown on the tool bar.
    ST's STM3210E-EVAL board is closer to MCBSTM32Exl
    - STM32F103ZG
    - Both boards mount 8MHz crystal
    - PB15 pin connects to "USB Disconnect" circuitry

    2) Replace report descriptor to a keyboard one.
    You may take it from keybrd.hid example of HID Descriptor Tool

    HID Descriptor Tool on USB.org
    www.usb.org/.../dt2_4.zip

    \STM32_USB-FS-Device_Lib_V3.3.0\Project\Custom_HID\src\usb_desc.h
    
    #define CUSTOMHID_SIZ_REPORT_DESC               63
    
    \STM32_USB-FS-Device_Lib_V3.3.0\Project\Custom_HID\src\usb_desc.c
    
    const uint8_t CustomHID_ReportDescriptor[CUSTOMHID_SIZ_REPORT_DESC] =
    {
      // drag in from keybrd.hid example
        0x05, 0x01,                    // USAGE_PAGE (Generic Desktop)
        0x09, 0x06,                    // USAGE (Keyboard)
        0xa1, 0x01,                    // COLLECTION (Application)
        0x05, 0x07,                    //   USAGE_PAGE (Keyboard)
        0x19, 0xe0,                    //   USAGE_MINIMUM (Keyboard LeftControl)
        0x29, 0xe7,                    //   USAGE_MAXIMUM (Keyboard Right GUI)
        0x15, 0x00,                    //   LOGICAL_MINIMUM (0)
        0x25, 0x01,                    //   LOGICAL_MAXIMUM (1)
        0x75, 0x01,                    //   REPORT_SIZE (1)
        0x95, 0x08,                    //   REPORT_COUNT (8)
        0x81, 0x02,                    //   INPUT (Data,Var,Abs)
        0x95, 0x01,                    //   REPORT_COUNT (1)
        0x75, 0x08,                    //   REPORT_SIZE (8)
        0x81, 0x03,                    //   INPUT (Cnst,Var,Abs)
        0x95, 0x05,                    //   REPORT_COUNT (5)
        0x75, 0x01,                    //   REPORT_SIZE (1)
        0x05, 0x08,                    //   USAGE_PAGE (LEDs)
        0x19, 0x01,                    //   USAGE_MINIMUM (Num Lock)
        0x29, 0x05,                    //   USAGE_MAXIMUM (Kana)
        0x91, 0x02,                    //   OUTPUT (Data,Var,Abs)
        0x95, 0x01,                    //   REPORT_COUNT (1)
        0x75, 0x03,                    //   REPORT_SIZE (3)
        0x91, 0x03,                    //   OUTPUT (Cnst,Var,Abs)
        0x95, 0x06,                    //   REPORT_COUNT (6)
        0x75, 0x08,                    //   REPORT_SIZE (8)
        0x15, 0x00,                    //   LOGICAL_MINIMUM (0)
        0x25, 0x65,                    //   LOGICAL_MAXIMUM (101)
        0x05, 0x07,                    //   USAGE_PAGE (Keyboard)
        0x19, 0x00,                    //   USAGE_MINIMUM (Reserved (no event indicated))
        0x29, 0x65,                    //   USAGE_MAXIMUM (Keyboard Application)
        0x81, 0x00,                    //   INPUT (Data,Ary,Abs)
        0xc0                           // END_COLLECTION
    };
    

    3) Put 8-bytes input report of keyboard over the interrupt IN endpoint, when a key makes and when the key breaks.

    I explained on the contents of this input report in this topic on SiLabs forum,
    USB HID KEYBOARD
    www.cygnal.org/.../001381.html

    On the ST's example, the report is sent to host using USB_SIL_Write().
    You'll see a typical code in EXTI9_5_IRQHandler() (\STM32_USB-FS-Device_Lib_V3.3.0\Project\Custom_HID\src\stm32f10x_it.c)

    In this file, DMA1_Channel1_IRQHandler() and EXTI15_10_IRQHandler() also put input reports using USB_SIL_Write(). You have to disable these IRQs, so that any spurious report doesn't come out.

    4) Optionally, implement Set_Report( Output ) process.
    Host puts output reports for keyboard LED over Set_Report( Output ) request.
    In this post to ST forum, I showed Set_Report( Feature ) implementation.

    my.st.com/.../Flat.aspx

    In CustomHID_Data_Setup() routine, copy the lines on case SET_REPORT/case HID_FEATURE into case SET_REPORT/case HID_OUTPUT

    4) Optionally, remove interrupt OUT endpoint from the config descriptor set
    Also delete routines relates to the interrupt OUT endpoint
    The interrupt OUT endpoint is not used on keyboard implementation.

    Tsuneo

Reply
  • 1) Run Custom_HID project on uVision IDE, select "STM3210E-EVAL" at the target pulldown on the tool bar.
    ST's STM3210E-EVAL board is closer to MCBSTM32Exl
    - STM32F103ZG
    - Both boards mount 8MHz crystal
    - PB15 pin connects to "USB Disconnect" circuitry

    2) Replace report descriptor to a keyboard one.
    You may take it from keybrd.hid example of HID Descriptor Tool

    HID Descriptor Tool on USB.org
    www.usb.org/.../dt2_4.zip

    \STM32_USB-FS-Device_Lib_V3.3.0\Project\Custom_HID\src\usb_desc.h
    
    #define CUSTOMHID_SIZ_REPORT_DESC               63
    
    \STM32_USB-FS-Device_Lib_V3.3.0\Project\Custom_HID\src\usb_desc.c
    
    const uint8_t CustomHID_ReportDescriptor[CUSTOMHID_SIZ_REPORT_DESC] =
    {
      // drag in from keybrd.hid example
        0x05, 0x01,                    // USAGE_PAGE (Generic Desktop)
        0x09, 0x06,                    // USAGE (Keyboard)
        0xa1, 0x01,                    // COLLECTION (Application)
        0x05, 0x07,                    //   USAGE_PAGE (Keyboard)
        0x19, 0xe0,                    //   USAGE_MINIMUM (Keyboard LeftControl)
        0x29, 0xe7,                    //   USAGE_MAXIMUM (Keyboard Right GUI)
        0x15, 0x00,                    //   LOGICAL_MINIMUM (0)
        0x25, 0x01,                    //   LOGICAL_MAXIMUM (1)
        0x75, 0x01,                    //   REPORT_SIZE (1)
        0x95, 0x08,                    //   REPORT_COUNT (8)
        0x81, 0x02,                    //   INPUT (Data,Var,Abs)
        0x95, 0x01,                    //   REPORT_COUNT (1)
        0x75, 0x08,                    //   REPORT_SIZE (8)
        0x81, 0x03,                    //   INPUT (Cnst,Var,Abs)
        0x95, 0x05,                    //   REPORT_COUNT (5)
        0x75, 0x01,                    //   REPORT_SIZE (1)
        0x05, 0x08,                    //   USAGE_PAGE (LEDs)
        0x19, 0x01,                    //   USAGE_MINIMUM (Num Lock)
        0x29, 0x05,                    //   USAGE_MAXIMUM (Kana)
        0x91, 0x02,                    //   OUTPUT (Data,Var,Abs)
        0x95, 0x01,                    //   REPORT_COUNT (1)
        0x75, 0x03,                    //   REPORT_SIZE (3)
        0x91, 0x03,                    //   OUTPUT (Cnst,Var,Abs)
        0x95, 0x06,                    //   REPORT_COUNT (6)
        0x75, 0x08,                    //   REPORT_SIZE (8)
        0x15, 0x00,                    //   LOGICAL_MINIMUM (0)
        0x25, 0x65,                    //   LOGICAL_MAXIMUM (101)
        0x05, 0x07,                    //   USAGE_PAGE (Keyboard)
        0x19, 0x00,                    //   USAGE_MINIMUM (Reserved (no event indicated))
        0x29, 0x65,                    //   USAGE_MAXIMUM (Keyboard Application)
        0x81, 0x00,                    //   INPUT (Data,Ary,Abs)
        0xc0                           // END_COLLECTION
    };
    

    3) Put 8-bytes input report of keyboard over the interrupt IN endpoint, when a key makes and when the key breaks.

    I explained on the contents of this input report in this topic on SiLabs forum,
    USB HID KEYBOARD
    www.cygnal.org/.../001381.html

    On the ST's example, the report is sent to host using USB_SIL_Write().
    You'll see a typical code in EXTI9_5_IRQHandler() (\STM32_USB-FS-Device_Lib_V3.3.0\Project\Custom_HID\src\stm32f10x_it.c)

    In this file, DMA1_Channel1_IRQHandler() and EXTI15_10_IRQHandler() also put input reports using USB_SIL_Write(). You have to disable these IRQs, so that any spurious report doesn't come out.

    4) Optionally, implement Set_Report( Output ) process.
    Host puts output reports for keyboard LED over Set_Report( Output ) request.
    In this post to ST forum, I showed Set_Report( Feature ) implementation.

    my.st.com/.../Flat.aspx

    In CustomHID_Data_Setup() routine, copy the lines on case SET_REPORT/case HID_FEATURE into case SET_REPORT/case HID_OUTPUT

    4) Optionally, remove interrupt OUT endpoint from the config descriptor set
    Also delete routines relates to the interrupt OUT endpoint
    The interrupt OUT endpoint is not used on keyboard implementation.

    Tsuneo

Children
More questions in this forum