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

How to process OUT Vendor Request with data stage

Hello, dear experts.
I have a problem with the USB component ver 6.5 of MDK-Professional Middleware.
I'm developing vendor specific device and I use USB0 of the microcontroller LPC4337JBD144. I use USB component ver 6.5.
After sending OUT Vendor Request with data stage it's impossible to process any IN Vendor Request. It looks as if it's processed successfully in my firmware program (it continues to work), but my PC application just freezes and waits for a response of a driver untill I detach my device or reset it using debugger.
I added a file "USBD_User_Device_0.c" to my project and modified it in order to process Vendor specific Requests. I changed a callback function the next way

usbdRequestStatus USBD_Device0_Endpoint0_SetupPacketReceived (const USB_SETUP_PACKET *setup_packet, uint8_t **buf, int32_t *len)
{
  switch (setup_packet->bmRequestType.Type) {
    ...
    case USB_REQUEST_VENDOR:
      switch (setup_packet->bmRequestType.Recipient){
        case USB_REQUEST_TO_DEVICE:
          switch (setup_packet->bRequest){
            ... // some code
            case USB_VEND_REQ_LONG_COMM:   // bRequest = 4
              CommStruct.CommLength = setup_packet->wLength;
              CommStruct.RespLength = setup_packet->wIndex;
              // When I call this function, the problem appears. Without calling it everything works properly
              usbReadStat = USBD_EndpointRead(0,       USB_ENDPOINT_OUT(0), CommStruct.CommBuff, 64/*CommStruct.CommLength*/);
              // Here you can see that I tried different ways to solve the problem. I waited, aborted transition, but nothing helped me.
              //while (USBD_EndpointReadGetResult(0, 0x00) != CommStruct.CommLength);
              //USBD_EndpointAbort(0, USB_ENDPOINT_OUT(0));
              ... // some code
              break;
          }
      }
      break;
  }
}

I have to add, that OUT Vendor Requests without data stage are processed successfully even after OUT Vendor Requests with data stage.
I use the toolchain MDK-ARM Professional version 5.14.0.0 and Windows 7 64-bit.
Thank you for any help.

Parents
  • Finally I've got a solution from technical support. That's what I was advised to do:
    ----------------------------------------------------------
    The USBD_EndpointWrite and USBD_EndpointRead should not be used for Endpoint 0 communication as it is handled by the library itself.
    As it can be seen in a template for custom device handling file USBD_User_Device_SerNum.c communication on Endpoint 0 is done through parameters of this function. So in this case you should do something like below:

    *buf = global_buffer; // Where OUT data will be received
    *len = setup_packet->wLength; // Number of bytes to be received
    return usbdRequestOK; // Return status that custom handling for this request is used

    after that function USBD_Device0_Endpoint0_OutDataReceived will be called by the library when OUT data is received and you should then analyze received data in there.
    ----------------------------------------------------------
    I hope it can help someone.

Reply
  • Finally I've got a solution from technical support. That's what I was advised to do:
    ----------------------------------------------------------
    The USBD_EndpointWrite and USBD_EndpointRead should not be used for Endpoint 0 communication as it is handled by the library itself.
    As it can be seen in a template for custom device handling file USBD_User_Device_SerNum.c communication on Endpoint 0 is done through parameters of this function. So in this case you should do something like below:

    *buf = global_buffer; // Where OUT data will be received
    *len = setup_packet->wLength; // Number of bytes to be received
    return usbdRequestOK; // Return status that custom handling for this request is used

    after that function USBD_Device0_Endpoint0_OutDataReceived will be called by the library when OUT data is received and you should then analyze received data in there.
    ----------------------------------------------------------
    I hope it can help someone.

Children