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 HID Host custom device

Hello,

I am interested to make USB HID HOST which can communicate with custom hid device instead of mice or keyboard.

For that I have to send data to that custom hid device.
I have used below fuction for dataout
USBH_InterruptSendData (pdev, (unsigned char *)&HID_Machine.buff, HID_Machine.length, HID_Machine.hc_num_out);

I am only doing out transaction form Host(STM32) to device. Everything is perfect and working fine up to 14th frame but 15th frame get corrupted, I have analyzer showing "child has an error". So I am unable to understand the cause of issue, is it memory overflow at host?

If I continue data transmission with new data then host is sending old data packet onwards

I used dual core example for ST and modified USBH_HID_Handle() as below (Only two cases are shown here)


case HID_SEND_DATA:

while(USB_OTG_IsEvenFrame(pdev) == FALSE);

USBH_InterruptSendData (pdev, (unsigned char *)&HID_Machine.buff, HID_Machine.length, HID_Machine.hc_num_out);

HID_Machine.state = HID_BUSY;

HID_Machine.timer = HCD_GetCurrentFrame(pdev);

break;

case HID_BUSY:

if(( HCD_GetCurrentFrame(pdev) - HID_Machine.timer) >= HID_Machine.poll)

{ HID_Machine.state = HID_SEND_DATA; //Retry++; //1 }

else if(HCD_GetURB_State(pdev , HID_Machine.hc_num_out) == URB_DONE) //last transaction was successful or not(USB request Block)

{ HID_Machine.state = HID_GET_DATA;

BD_Data_Sent_Flag=1;

}

else if(HCD_GetURB_State(pdev, HID_Machine.hc_num_out) == URB_STALL )

{

if( (USBH_ClrFeature(pdev, pphost, HID_Machine.ep_addr, HID_Machine.hc_num_out)) == USBH_OK)

{

HID_Machine.state = HID_SEND_DATA;

} }

break;


Please help...

Parents
  • Hello Khoa Tran,

    I have already posted main part for data transmission in my first message. You have to add this portion in between HID_SYNC and HID_GET_DATA in

    static USBH_Status USBH_HID_Handle(USB_OTG_CORE_HANDLE *pdev , void *phost)

    Copy your data into the (that you want to transmit to the device)
    HID_Machine.buff and provide length of data in HID_Machine.length.

    for your question, HID_CUSTOM_cb giving error

    use this
    HID_cb_TypeDef HID_CUSTOM_cb=
    { Device_Init, Device_Decode,
    };

    static void Device_Init ( void)
    { // Add your code here
    }

    static void Device_Decode(uint8_t *data)
    { // Add your code here
    }

    Krunal

Reply
  • Hello Khoa Tran,

    I have already posted main part for data transmission in my first message. You have to add this portion in between HID_SYNC and HID_GET_DATA in

    static USBH_Status USBH_HID_Handle(USB_OTG_CORE_HANDLE *pdev , void *phost)

    Copy your data into the (that you want to transmit to the device)
    HID_Machine.buff and provide length of data in HID_Machine.length.

    for your question, HID_CUSTOM_cb giving error

    use this
    HID_cb_TypeDef HID_CUSTOM_cb=
    { Device_Init, Device_Decode,
    };

    static void Device_Init ( void)
    { // Add your code here
    }

    static void Device_Decode(uint8_t *data)
    { // Add your code here
    }

    Krunal

Children