cancel
Showing results for 
Search instead for 
Did you mean: 

The questions about stm32f1 Usb-hid.The libs from TM32 USB-FS-Device Lib V4.1.0' Custom HID#Insert get report in RESULT CustomHID_Data_Setup/usb_prop.c

JachChen423
Associate II

The original CustomHID_Data_Setup function :

RESULT CustomHID_Data_Setup(uint8_t RequestNo) 

{

 uint8_t *(*CopyRoutine)(uint16_t);

  

 if (pInformation->USBwIndex != 0) 

  return USB_UNSUPPORT;  

 CopyRoutine = NULL;  

  

 if ((RequestNo == GET_DESCRIPTOR)  

   && (Type_Recipient == (STANDARD_REQUEST | INTERFACE_RECIPIENT))

    )     // (( ==0x06 ))&&(0x01=(0x00|0x01))

 {

   

  if (pInformation->USBwValue1 == REPORT_DESCRIPTOR)

  {

   CopyRoutine = CustomHID_GetReportDescriptor;

  }

  else if (pInformation->USBwValue1 == HID_DESCRIPTOR_TYPE)

  {

   CopyRoutine = CustomHID_GetHIDDescriptor;

  }

   

 } /* End of GET_DESCRIPTOR */

  

 /*** GET_PROTOCOL, GET_REPORT, SET_REPORT ***/

 else if ( (Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT)) )

 {    

  switch( RequestNo )

  {

  case GET_PROTOCOL:

   CopyRoutine = CustomHID_GetProtocolValue;

   break;

  case SET_REPORT:

   CopyRoutine = CustomHID_SetReport_Feature;

   Request = SET_REPORT;

   break;

  default:

   break;

  }

 }

  

 if (CopyRoutine == NULL)

 {

  return USB_UNSUPPORT;

 }

  

 pInformation->Ctrl_Info.CopyData = CopyRoutine;

 pInformation->Ctrl_Info.Usb_wOffset = 0;

 (*CopyRoutine)(0);

 return USB_SUCCESS;

}

If I don't change the original code:

The result of usb communication is this:c00000004 stall pid.I guess because original code not have handle "get report".My request in host by feature.

So I changed the code.

The new core:

RESULT CustomHID_Data_Setup(uint8_t RequestNo) 

{

 uint8_t *(*CopyRoutine)(uint16_t);

  

 if (pInformation->USBwIndex != 0) 

  return USB_UNSUPPORT;  

  

 CopyRoutine = NULL;  

  

 if ((RequestNo == GET_DESCRIPTOR)  

   && (Type_Recipient == (STANDARD_REQUEST | INTERFACE_RECIPIENT))

    )     

 {

   

  if (pInformation->USBwValue1 == REPORT_DESCRIPTOR)

  {

   CopyRoutine = CustomHID_GetReportDescriptor;

  }

  else if (pInformation->USBwValue1 == HID_DESCRIPTOR_TYPE)

  {

   CopyRoutine = CustomHID_GetHIDDescriptor;

  }

   

 } /* End of GET_DESCRIPTOR */

  

 /*** GET_PROTOCOL, GET_REPORT, SET_REPORT ***/

 else if ( (Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT)) )

 {   

  switch( RequestNo )

  {

  case GET_REPORT:     //new insert

   CopyRoutine = CustomHID_GetReport_Feature; //new insert

   Request = GET_REPORT; //new insert

  case GET_PROTOCOL:

   CopyRoutine = CustomHID_GetProtocolValue;

   break;

  case SET_REPORT:

   CopyRoutine = CustomHID_SetReport_Feature;

   Request = SET_REPORT;

   break;

  default:

   break;

  }

 }

 if (CopyRoutine == NULL)

 {

  return USB_UNSUPPORT;

 }

  

 pInformation->Ctrl_Info.CopyData = CopyRoutine;

 pInformation->Ctrl_Info.Usb_wOffset = 0;

 (*CopyRoutine)(0);

 return USB_SUCCESS;

}

add to new function:

uint8_t *CustomHID_GetReport_Feature(uint16_t Length)

{

 

return (uint8_t *)(&report[0]);

 

}

uint32_t report[]={0x01,0x01,0x02,0x03,0x04,0x03,0x02,0x64,0x64,0x00,0x00,0x00,0x00,0x04};

But the device only responded with a data 0.

0693W00000aHo8XQAS.pngI don`t know why?

1 ACCEPTED SOLUTION

Accepted Solutions
JachChen423
Associate II

Now is OK.

uint8_t *CustomHID_GetReport_Feature(uint16_t Length)

{

if (Length == 0)

 {

  pInformation->Ctrl_Info.Usb_wLength = Size ; //The size is your data length.

  return NULL;

 }

 else

 {

  return (uint8_t *)(&report[0]);

 }

}

I don't know why.Because I think it had return.But it's ok.!!!???

View solution in original post

4 REPLIES 4
JachChen423
Associate II

I forgot to add break, but stall pid=c0000004 appeared again.

gbm
Lead III

uint32_t report[]?

The report is a sequence of bytes, not 32-bit words.

Thank you for your answer. Unfortunately, I still can't.

JachChen423
Associate II

Now is OK.

uint8_t *CustomHID_GetReport_Feature(uint16_t Length)

{

if (Length == 0)

 {

  pInformation->Ctrl_Info.Usb_wLength = Size ; //The size is your data length.

  return NULL;

 }

 else

 {

  return (uint8_t *)(&report[0]);

 }

}

I don't know why.Because I think it had return.But it's ok.!!!???