AnsweredAssumed Answered

HID USB Data to the STM32F4 DISCOVERY

Question asked by gouskov.vadim on Mar 11, 2016
Latest reply on Mar 15, 2016 by gouskov.vadim
Dear people on the ST Forum.

I am currently working on configuring the STM32F4 DISCO board as a HID device that must send an receive data from a host (PC). I've managed to configure it as a HID mouse and altered the descriptors and reports to send 64byte packets to the PC.I get the correct data from the device, but when I try to send data to the device (YAT terminal) I get an undefinable error and the terminal closes.

Here's what I added to the USB FS project generated in CubeMx so far to try to accomplish this. :

Added an EPOUT descriptor 
and changed the wTotallength accordingly in the Conf.Desc. and checked the Descriptors and report descriptors in USBlyzer.

....
  /* 34 */
  //////////////////////EPOUT Descriptor ///////////////////////
  0x07,          /*bLength: Endpoint Descriptor size*/
  USB_DESC_TYPE_ENDPOINT, /*bDescriptorType:*/
  HID_EPOUT_ADDR,    /*bEndpointAddress: Endpoint Address (OUT)*/ // VADIM
  0x03,          /*bmAttributes: Interrupt endpoint*/
  HID_EPOUT_SIZE, /*wMaxPacketSize: 64 Byte max */
  0x00,
  0x0A,          /*bInterval: Polling Interval (10 ms)*/
} ; 

Changed the report Descriptors:
<code>
__ALIGN_BEGIN static uint8_t HID_MOUSE_ReportDesc[HID_MOUSE_REPORT_DESC_SIZE]  __ALIGN_END =
{
  0x06,   0xAB, 0xFF,               // Report Descriptor Raw Hid
  0x0A,   0x00, 0x02,
  0xA1,   0x01,
  0x75,   0x08,
  
  0x15,   0x00,
  0x26,   0xFF, 0x00,
  0x95,   0x40,
  0x09,   0x01,
  
  0x81,   0x02,
  0x95,   0x40,
  0x09,   0x02,
  
  0x91,   0x02,
  0xC0
}; </code>

Added a Data out function in the HID callback structure
<code>
static uint8_t  USBD_HID_DataOut (USBD_HandleTypeDef *pdev, uint8_t epnum);
.....
USBD_ClassTypeDef  USBD_HID = 
{
  USBD_HID_Init,
  USBD_HID_DeInit,
  USBD_HID_Setup,
  NULL, /*EP0_TxSent*/  
  NULL, /*EP0_RxReady*/
  USBD_HID_DataIn, /*DataIn*/
  USBD_HID_DataOut, /*DataOut*/ // <<<<<<
  NULL, /*SOF */
  NULL,
  NULL,      
  USBD_HID_GetCfgDesc,
  USBD_HID_GetCfgDesc, 
  USBD_HID_GetCfgDesc,
  USBD_HID_GetDeviceQualifierDesc,
}; </code>

Declared the USBD_HID_DataOut  function
but to my knowledge this function is never entered...

<code>
static uint8_t  USBD_HID_DataOut (USBD_HandleTypeDef *pdev,                    
                              uint8_t epnum)
{
     //printf("Received \r\n") ;
       USBD_LL_PrepareReceive(pdev,               //VADIM
                                             HID_EPOUT_ADDR,
                                            /* (uint8_t*)*/HID_Rx_Buffer,
                                             HID_EPOUT_SIZE
                                                               ) ;
       return USBD_OK;
} </code>

And in USBD_HID_INIT opened EPOUT
<code>
static uint8_t  USBD_HID_Init (USBD_HandleTypeDef *pdev, 
                               uint8_t cfgidx)
{
  uint8_t ret = 0;
  
  /* Open EP IN */
  USBD_LL_OpenEP(pdev,
                 HID_EPIN_ADDR,
                 USBD_EP_TYPE_INTR,
                 HID_EPIN_SIZE);  
  /* Open EP OUT */
  USBD_LL_OpenEP(pdev,                    <<<<<<<<<<<<<<<<
                         HID_EPOUT_ADDR,
                 USBD_EP_TYPE_INTR,
                 HID_EPOUT_SIZE);
  
  USBD_LL_PrepareReceive(pdev,               <<<<<<<<<<<< 
                                        HID_EPOUT_ADDR,
                                        (uint8_t*)HID_Rx_Buffer,
                                        HID_EPOUT_SIZE
                                                          ) ;
....
</code>

Does somebody have more experience with HID on the STM32F4 ? For know I can't figure this out..

I followed the approach in this thread for USB HID on the STM32F105/107

https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2Fcortex_mx_stm32%2FSTM32F105107%20HID%20USB%20device%20SET_REPORT%2C%20GET_REPORT&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&currentviews=1524

Thanks in Advance,
Vadim , Student at Thomas More - De Nayer

Outcomes