USB Generic HID Device Example Code - Why is this "send" embedded in the receive function?

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

USB Generic HID Device Example Code - Why is this "send" embedded in the receive function?

1,404 Views
nbgatgi
Contributor IV

I'm using the LPCXpresso54608 SDK for MCUXpresso.  In particular, I'm running the generic HID device with FreeRTOS example code (link to my code/setup).

The purpose of the code is to echo data sent from a PC program back to the PC.  This all works as intended, but now I'm trying to modify it for my specific application needs.

In the function "USB_DeviceHidGenericCallback", the switch/case called after receiving a USB message includes a call to "USB_DeviceHidSend" which performs the echo function ... so far so good.  After that, within the same switch/case "USB_DeviceHidRecv" which eventually calls "USB_DeviceLpc3511IpRecv" which is the device specific call for the LPCXpresso54608 development board ... again, so far so good.  But then, within "USB_DeviceLpc3511IpRecv", the only function is to call "USB_DeviceLpc3511IpSend".

usb_status_t USB_DeviceLpc3511IpRecv(usb_device_controller_handle controllerHandle,

                                     uint8_t endpointAddress,

                                     uint8_t *buffer,

                                     uint32_t length)

{

    return USB_DeviceLpc3511IpSend(controllerHandle, endpointAddress, buffer, length);

// Example code echo data???  NBG

//    return kStatus_USB_Success;

}

My initial thought was that this was simply an accidental redundant means of echoing the received data, but when it is called, no data is received by the PC.  I attempted to replace the call with a return of the enumerated value for a successful USB operation, but then the ENTIRE PROGRAM STOPPED FUNCTIONING AND I HAVE NO IDEA WHY!!!

If anyone knows what the purpose is for the send within the receive shown above, please let me know.

Thank you in advance!

2 Replies

1,075 Views
Hui_Ma
NXP TechSupport
NXP TechSupport

Hi,

I debug the project and find below code:

usb_status_t USB_DeviceLpc3511IpRecv(usb_device_controller_handle controllerHandle,
                                     uint8_t endpointAddress,
                                     uint8_t *buffer,
                                     uint32_t length)
{
    return USB_DeviceLpc3511IpSend(controllerHandle, endpointAddress, buffer, length);
}

In fact, the USB_DeviceLpc3511IpSend() function doesn't mean the USB device send data to USB host.

The data direction based on the endpoint is IN or OUT.

From the previous code, the endpoint direction is OUT, which means the USB host send data to USB slave.

The USB_DeviceLpc3511IpSend() function name does add the confusion.

While, the actual function called here to receive data from USB Host(PC).


Have a great day,
Mike

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

1,075 Views
nbgatgi
Contributor IV

Your reply didn't really answer the question.  What is the functional purpose of the SEND in this context?

0 Kudos
Reply