AnsweredAssumed Answered

STM32F105 USB Host HID application

Question asked by 林 工 on Aug 4, 2017
Latest reply on May 21, 2018 by Richard Lowe

     hi everyone

       “We are trying to develop a USB Host HID application where using the controller STM32F1, and the USB stack library available on the ST website, we are trying to send data/command to an USB HID device.

      But in the library we downloaded from ST site, the host HID application has examples for mouse and keyboard application only.In case of Mouse and keyboard, Host receives but does not transmit back anything while in our application we need to also transmit data.

      How to use USBH_HID_SetReport, USBH_InterruptSendData, USBH_LL_GetURBState.

   

Is it right?

 

static void HID_ProcessTransmission(USBH_HandleTypeDef *phost)
{
  HID_HandleTypeDef *HID_Handle =  (HID_HandleTypeDef*) phost->pActiveClass->pData;
  USBH_URBStateTypeDef URB_Status = USBH_URB_IDLE;
 
  switch(HID_Handle->data_tx_state)
  {
 
  case HID_SEND_DATA:

 

      USBH_InterruptSendData (...);

 

    HID_Handle->data_tx_state = HID_SEND_DATA_WAIT;
    
    break;
    
  case HID_SEND_DATA_WAIT:
    
    URB_Status = USBH_LL_GetURBState(phost, HID_Handle->DataItf.OutPipe);
    
    /*Check the status done for transmission*/
    if(URB_Status == USBH_URB_DONE )
    {         

 

        HID_Handle->data_tx_state = HID_IDLE;           
    }
    break;
  default:
    break;
  }
}

 

 

 

static USBH_StatusTypeDef USBH_HID_Process(USBH_HandleTypeDef *phost)
{
  USBH_StatusTypeDef status = USBH_OK;
  HID_HandleTypeDef *HID_Handle =  (HID_HandleTypeDef *) phost->pActiveClass->pData;
 
  switch (HID_Handle->state)
  {
  case HID_INIT:
    HID_Handle->Init(phost);
  case HID_IDLE:
    if (USBH_HID_SetReport (phost, // H2D, CLASS REQ
                            0x02, // Type 1 in, 2 out, 3 feature, ff res
                            0,    // Id
                            _buf,
                            sizeof(_buf)) == USBH_OK)
{
 // HID_Handle->state = HID_SYNC;
}

 ...

  case HID_TRANSFER_DATA:

    HID_ProcessTransmission(phost);
   HID_ProcessReception(phost);

 ..

}.

Attachments

Outcomes