HID device SetReport gets zero bytes when host sends 65 bytes

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

HID device SetReport gets zero bytes when host sends 65 bytes

1,250 Views
ssudhir
Contributor II

Hi,

We have a small HID host program written in Python.  At the host end, we can get Feature report from the device.  However, when the host sends a feature report using setReport, at our device SetReport gets executed (we hit a  breakpoint in our SetReport handler) but length it receives  is ‘0’. AT the host side, we are sending 65 buffer including Report ID.

static ErrorCode_t HID_SetReport(USBD_HANDLE_T hHid, USB_SETUP_PACKET *pSetup, uint8_t * *pBuffer, uint16_t length)

{

         uint8_t j =0;

         uint16_t i = 0;

         uint8_t buf[10];

                /* we will reuse standard EP0Buf */

                if (length == 0) {

                                return LPC_OK;

                }

Since length is zero , it return LPC_OK

Any ideas?

Thanks

0 Kudos
10 Replies

1,136 Views
FelipeGarcia
NXP Employee
NXP Employee

Hello,

 

Could you please let me know the specific MCU and example code you are working on?

 

Best regards,

Felipe

0 Kudos

1,136 Views
ssudhir
Contributor II

In this thread it is mentioned that GetReport and SetReport are coded just

for single byte.. It is also mentioned that we need to change but doesn't

specify what needs to be changed. Any idea what needs to be done?

https://community.nxp.com/thread/425616

Here is our SetReport we took from the sample code

static ErrorCode_t HID_SetReport(USBD_HANDLE_T hHid, USB_SETUP_PACKET

*pSetup, uint8_t * *pBuffer, uint16_t length)

{

//bns testing buffer

uint8_t j =0;

uint16_t i = 0;

uint8_t buf[10];

/* we will reuse standard EP0Buf */

if (length == 0) {

return LPC_OK;

}

uint8_t ReportID = pSetup->wValue.WB.L;

/* ReportID = SetupPacket.wValue.WB.L; */

switch (pSetup->wValue.WB.H) {

case HID_REPORT_INPUT:

return ERR_USBD_STALL; /* Not Supported */

case HID_REPORT_OUTPUT:

//bns 3/8/2018 commenting the below line because using

separate buffer for input, output and feature reports

//*loopback_report = **pBuffer;

//bns 3/82018 - save the set report buffer for time being

and think of how to set this report , however this works for one bytes

//if our report is more than one byte need to copy this

*output_report = **pBuffer;

//need the length too

out_feature_length = length;

break;

case HID_REPORT_FEATURE:

switch (ReportID)

{

case 0:

//bns just fo testing so wrapping the copy

for (i = 0; i< length; i++)

{

buf[j++] = *pBuffer[i];

if (j%10 == 0)

j =0;

}

break;

case 3:

//bns just fo testing so wrapping the copy

for (i = 0; i< length; i++)

{

buf[j++] = *pBuffer[i];

if (j%10 == 0)

j =0;

}

break;

case 4:

//bns just fo testogn so wrapping the copy

for (i = 0; i< length; i++)

{

buf[j++] = *pBuffer[i];

if (j%10 == 0)

j =0;

}

break;

}

//return ERR_USBD_STALL;

break;

}

return LPC_OK;

}

Thanks

Shobha

0 Kudos

1,136 Views
FelipeGarcia
NXP Employee
NXP Employee

Hello,

 

HID Generic example supports 1 byte report.

 

To change the report length I recommend you to read the following community post.

https://community.nxp.com/thread/422249

 

Best regards,

Felipe

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos

1,136 Views
ssudhir
Contributor II

Ok after further debugging this is what it looks.

When host sends HID_Request_Set_Report – SetReport call back function gets

called twice. First time we need to give the buffer address where we want

the data to be coped – at that time length is zero since nothing has been

copied. Then it gets called the second time after the data gets copied to

the destination buffer and this time length indicates the number of bytes

received (or copied). Now the question is should this buffer we pass be in

USB RAM area assigned to USB ROM stack or it can be in different Ram region

?

Regards

0 Kudos

1,136 Views
FelipeGarcia
NXP Employee
NXP Employee

Hello,

 

USB ROM stack are is a memory location from where the stack can allocate data and buffers. I recommend you to allocate your buffer in that section.

 

Regards,

Felipe

0 Kudos

1,136 Views
ssudhir
Contributor II

According to your documentation, In SetReport --length Amount of data

copied to destination buffer. Since we are not seeing the data host sends

and Length is zero is it fair to assume that data has not been copied to

the destination buffer despite pSetup..wLength indicating so.? And also

how to fix it?

Thanks

0 Kudos

1,136 Views
ssudhir
Contributor II

HID_SetReport(USBD_HANDLE_T hHid, USB_SETUP_PACKET *pSetup, uint8_t *

*pBuffer, uint16_t length)

We assumed that the length indicates the number of bytes received and it

was zero, It looks like length doesn't indicate number of bytes received.

When we checked pSetup..wLength that shows that 65 bytes. So

pSetup..wLength is the one indicates how many bytes we received? We are

guessing **pBuffer points to the buffer pointer, however that buffer

doesn't contain the data we are sending.. How can we access the data ?

Where does the stack store the data ?

Thanks

0 Kudos

1,136 Views
ssudhir
Contributor II

HID_SetReport - function does the length parameter indicate the number of

bytes received?

Thanks

0 Kudos

1,136 Views
ssudhir
Contributor II

Thanks for the response.

However, we have done all those things and able to get 64 bytes output

report and able to send input and feature report. When the Host wants to

fetch feature or input report, our GetReport gets invoked and we can send

64 bytes. When the host sends output report our EP handler gets invoked.

When the host sends feature report, our SetReport gets invoked and there we

see 0 bytes despite of host sending 65 bytes ( I guess first byte is the

report ID so is the zero length).

The below link suggests that apart from changing the packet size, EPBuffer

size,, defining MAX report size etc. we need to do something else to

receive more than a byte in SetReport. What is that we need to do?

Thanks

0 Kudos

1,136 Views
ssudhir
Contributor II

We are working on LPC4357 controller and generic HID

0 Kudos