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;
} }
Please help...
Dear Tran,
I hope you have implemented whatever I suggested previously.
Just implement below logic.
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.
And set HID machine state to HID_SEND_DATA whenever you want to transmit data.
Krunal
Set HID_Machine.state = HID_SEND_DATA; in main.c ? I want to my host send data when I push a button. I set in main.c and It give a error "use of undeclared identifier 'HID_Machine'" but If I define
#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #if defined ( __ICCARM__ ) /*!< IAR Compiler */ #pragma data_alignment=4 #endif #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ __ALIGN_BEGIN HID_Machine_TypeDef HID_Machine __ALIGN_END ;
It give a error "HID_Machine mutiply defined (by usbh_hid_core.o and main.o)" p/s : I included usbh_hid_core.h in main.c Thank you.
Hi Krunal, Thank you for helping me. I can transfer and recieve data from my custom HID Device now. Khoa.
You are welcome and congratulation!!
Hi Khor, Now I used STM32F4 HID Host custom device,the logic is when I pressed button ,HOST send data to HID decive ,can you tell me the send logic in USBH_HID_Handle?
Thanks!