AnsweredAssumed Answered

Issues with custom class driver for a usb serial device in MQX

Question asked by Shabeer Badarudheen on Jan 6, 2017

Hi,

   We need to interface K60  Tower board with a usb serial device which is having a custom class usb interface. The device descriptor which got when we connect with a linux machine given below. We need to write a mqx driver for this device. we are using

MQX 4.0 for our development.

 

Device Descriptor:
   bLength 18
   bDescriptorType 1
   bcdUSB 2.00
   bDeviceClass 0 (Defined at Interface level)
   bDeviceSubClass 0
   bDeviceProtocol 0
   bMaxPacketSize0 64
   idVendor 0xxxx
   idProduct 0xxxx
   bcdDevice 6
   iManufacturer x 
   iProduct x
   iSerial x

DEF
   bNumConfigurations 1
   Configuration Descriptor:
      bLength 9
      bDescriptorType 2
      wTotalLength 32
      bNumInterfaces 1
      bConfigurationValue 1
      iConfiguration 0
      bmAttributes 0xe0
      Self Powered
      Remote Wakeup
      MaxPower 500mA
Interface Descriptor:
      bLength 9
      bDescriptorType 4
      bInterfaceNumber 2
      bAlternateSetting 0
      bNumEndpoints 2
      bInterfaceClass 255 Vendor Specific Class
      bInterfaceSubClass 0
      bInterfaceProtocol 0
      iInterface 0
Endpoint Descriptor:
      bLength 7
      bDescriptorType 5
      bEndpointAddress 0x81 EP 1 IN
      bmAttributes 2
      Transfer Type Bulk
      Synch Type None
      Usage Type Data
      wMaxPacketSize 0x0200 1x 512 bytes
      bInterval 0
Endpoint Descriptor:
      bLength 7
      bDescriptorType 5
      bEndpointAddress 0x01 EP 1 OUT
      bmAttributes 2
      Transfer Type Bulk
      Synch Type None
      Usage Type Data
      wMaxPacketSize 0x0200 1x 512 bytes
      bInterval 0
Device Qualifier (for other device speed):
      bLength 10
      bDescriptorType 6
      bcdUSB 2.00
      bDeviceClass 0 (Defined at Interface level)
      bDeviceSubClass 0
      bDeviceProtocol 0
      bMaxPacketSize0 64
      bNumConfigurations 1
Device Status: 0x0000

 

For writing this we have followed the document the "Freescale MQX™ RTOS USB Host User’s Guide" (Section 4.2). The steps we have done is given below.

1) We took the hidkeyboard driver code a reference and modified the driver info table as given below.


static USB_HOST_DRIVER_INFO DriverInfoTable[] = {
{
   {0x00, 0x00}, /* Vendor ID per USB-IF */
   {0x00, 0x00}, /* Product ID per manufacturer */
   0xFF,/* Class code */
   0,  /* Sub-Class code */
   0, /* Protocol */
   0, /* Reserved */
   usb_host_hid_keyboard_event /* Application call back function */
},

 

2) _usb_host_driver_install(USBCFG_DEFAULT_HOST_CONTROLLER)

3)  _usb_host_init(USBCFG_DEFAULT_HOST_CONTROLLER, &host_handle)

4) _usb_host_driver_info_register(host_handle, DriverInfoTable)

5) After usb attached, select inetrface by _usb_hostdev_select_interface()

6) After usb device interfaced , create pipe handle for rcv and send pipes

_usb_hostdev_find_pipe_handle(hid_device.DEV_HANDLE, hid_device.INTF_HANDLE, USB_BULK_PIPE, USB_RECV);

_usb_hostdev_find_pipe_handle(hid_device.DEV_HANDLE, hid_device.INTF_HANDLE, USB_BULK_PIPE, USB_SEND);

7) Allocate the buffer by

_usb_hostdev_get_buffer(hid_device.DEV_HANDLE, pipe->MAX_PACKET_SIZE, (pointer *) &in_buffer);

8) Register the call backs

usb_hostdev_tr_init(&tr1, usb_host_hid_recv_callback, NULL);
usb_hostdev_tr_init(&tr, usb_host_hid_send_callback, NULL);

9) initialize the tx buffer and tx length and send the data.

tr.G.TX_BUFFER = (uchar *) data_buffer_tx;
tr.G.TX_LENGTH = pipe_tr->MAX_PACKET_SIZE;
status = _usb_host_send_data(host_handle, pipe_tr, &tr);

10) After a time delay, say 10 ms, receive the data by

tr1.G.RX_BUFFER = (uchar *) in_buffer;
tr1.G.RX_LENGTH = pipe->MAX_PACKET_SIZE;
status1 = _usb_host_recv_data(host_handle, pipe, &tr1);

 

By doing this, all the steps are successful but the status of the  _usb_host_send_data() and _usb_host_recv_data() is "USB_STATUS_TRANSFER_QUEUED".

and the status in the call back functions usb_host_hid_send_callback() and usb_host_hid_recv_callback() is "USBERR_TR_FAILED" . When we step in to the code, we note that the code is failed by NACK from device (KHCI_ATOM_TR_NAK) in _usb_khci_atom_tr() function.

 

Is there any thing extra thing we need to do for a vendor specific class driver? Any idea why the NACK is coming? Please help

Outcomes