cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F105 USB Host HID application

? ?
Associate
Posted on August 04, 2017 at 10:42

     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);

 ..

}.

2 REPLIES 2
Steven Pearce
Associate II
Posted on March 21, 2018 at 15:09

I see I am the first to reply, and I have a similar requirement to code.

Did your solution work?

How was 

HID_Handle->state set to HID_TRANSFER_DATA?

Steve

Posted on May 21, 2018 at 23:16

Using the existing states that were not implemented, I have this solution for the USBH_Process function:

 case HID_SEND_DATA:
 USBH_InterruptSendData(phost, HID_Handle->pData, HID_Handle->length, HID_Handle->OutPipe);
 HID_Handle->state = HID_BUSY;
 HID_Handle->timer = phost->Timer;
 HID_Handle->DataReady = 0;
 break;
 case HID_BUSY:
 if(USBH_LL_GetURBState(phost, HID_Handle->OutPipe) == USBH_URB_DONE)
 {
 if(fifo_size(&HID_Handle->fifo))
 {
 memset(HID_Handle->pData, 0, HID_Handle->length);
 fifo_write(&HID_Handle->fifo, HID_Handle->pData, HID_Handle->length);
 USBH_InterruptSendData(phost,
 HID_Handle->pData,
 HID_Handle->length,
 HID_Handle->OutPipe);
 }
 else
 {
 HID_Handle->state = HID_SYNC;
 }
 #if (USBH_USE_OS == 1)
 osMessagePut ( phost->os_event, USBH_URB_EVENT, 0);
 #endif
 }
 else if(USBH_LL_GetURBState(phost, HID_Handle->OutPipe) == USBH_URB_STALL) /* OUT end point Stalled */
 {
 /* Issue Clear Feature on interrupt OUT end point */
 if(USBH_ClrFeature(phost, HID_Handle->OutEp) == USBH_OK)
 {
 /* Change state to issue next IN token */
 HID_Handle->state = HID_GET_DATA;
 }
 }
 break;
�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

Allows for sending more than the single 64 byte frame.