How to use FSL stack 4.1.1 usb host cdc demo

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

How to use FSL stack 4.1.1 usb host cdc demo

1,344 Views
lin100
Contributor I

All,

I maked a project to work as a usb host base on FSL USB stack 4.1.1 USB host cdc demo,I want to use it to control a usb customer's define device. 

when it power up,connect the usb device to host,it can be enumerated.and it has 3 interface,each interface has a bulk-in and bulk-out pipe.

But when i use the host api by step according the Using API(described in USBHOSTAPIRM.pdf  page11), i found _usb_host_send_data()/ _usb_host_recv_data()

function's return is OK,the host can not receive any data from device, normally, the device will send out a response after it receive a data from host.

I don't know what i do is right or not? and i have no other method to find out whether the device can not receive data from host or the host can not receive data from device. .

does any body have a good idea?

0 Kudos
8 Replies

800 Views
carlnormansuret
Contributor V

I am trying to get Telit (HE910) CDC / acm serial ports working using MQX4.2 cdc example on TWR52259. 

Telit have sent me their driver information but I cannot seem to understand how to get it to work, I tried changing the vendor/product ID but no luck. 

/* Table of driver capabilities this application wants to use */
static USB_HOST_DRIVER_INFO DriverInfoTable[] =
{
{
// {0x00,0x00}, /* Vendor ID per USB-IF */
// {0x00,0x00}, /* Product ID per manufacturer */
{0x1B,0xC7}, /* Vendor ID per USB-IF */
{0x00,0x21}, /* Product ID per manufacturer */
USB_CLASS_COMMUNICATION, /* Class code */
USB_SUBCLASS_COM_ABSTRACT, /* Sub-Class code */
0xFF, /* Protocol */
0, /* Reserved */
usb_host_cdc_acm_event /* Application call back function */
},
{
// {0x00,0x00}, /* Vendor ID per USB-IF */
// {0x00,0x00}, /* Product ID per manufacturer */
{0x1B,0xC7}, /* Vendor ID per USB-IF */
{0x00,0x21}, /* Product ID per manufacturer */
USB_CLASS_DATA, /* Class code */
0xFF, /* Sub-Class code */
0xFF, /* Protocol */
0, /* Reserved */
usb_host_cdc_data_event /* Application call back function */
},
/* USB 1.1 hub */
{

{0x00,0x00}, /* Vendor ID per USB-IF */
{0x00,0x00}, /* Product ID per manufacturer */
USB_CLASS_HUB, /* Class code */
USB_SUBCLASS_HUB_NONE, /* Sub-Class code */
USB_PROTOCOL_HUB_ALL, /* Protocol */
0, /* Reserved */
usb_host_hub_device_event /* Application call back function */
},
{
{0x00,0x00}, /* All-zero entry terminates */
{0x00,0x00}, /* driver info list. */
0,
0,
0,
0,
NULL
}
};

Ultimately I want to be able to fopen("ttyACM0:", 0); and fopen("ttyACM1:", 0); or similar so I can start using two of the available serial ports.

0 Kudos

800 Views
isaacavila
NXP Employee
NXP Employee

Hello Carl,

Have you checked if once USB CDC device is being connected, USB callback is called with attach and other events like change configuration/set interface?

You can debug (using printfs) to validate if attachments and set configuration is done correctly.

Regards,

Isaac

0 Kudos

800 Views
carlnormansuret
Contributor V

Hi Isaac,

I turned on the MQX USB Debugging and have attached is the full debug log using correct vendor / manufacturer that Telit supplied. Turns out the bytes in the USB_HOST_DRIVER_INFO are swapped for vendor / product, debug log attached (endianness issue).

Still not working, lots of "failed" in the log. I added code to print vendor / manufaturer which is how i found the orginal issue, but its still not working because things dont match i guess.

Also, once I get it working how do I address each CDC serial port?

The example has 

char                *device_name = "tty0:";

but I thought maybe it should be this:

char                *device_name = "ttyACM0:";

But still no luck, Im sure its something simple. The main issue is I am new to USB and how it all works.

0 Kudos

800 Views
Kan_Li
NXP TechSupport
NXP TechSupport

Hi,

This stack provides class layer APIs such as _io_cdc_serial_write() and _io_cdc_serial_read() for Host CDC application, so why not use them in your application? You may refer to cdc_serial.c in the folder of "C:\Freescale\Freescale USB Stack v4.1.1\Source\Host\examples\cdc_serial" for more details.

Actually ver 4.1.1 is an old version, so if you want to have the latest one , you may refer to KSDK 1.2 which can be downloaded from Software Development Kit for Kinetis MCUs|Freescale .

Hope that helps,


Have a great day,
Kan

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

800 Views
lin100
Contributor I

Hi Kan,

Many thanks your kindly replay.

Maybe my expression is not so clear. because the usb device I want to control is not a standard CDC device, so I need to modify CDC host demo code to identify and operate it. for _io_cdc_serial_write() and _io_cdc_serial_read() ,the final call is _usb_host_send_data()/ _usb_host_recv_data().so I think i can use _usb_host_send_data()/ _usb_host_recv_data().directly to control the pipe.Is it right?

On the other hand ,I will download the latest code to make a test.

Thanks and B.R.

Kun

0 Kudos

800 Views
isaacavila
NXP Employee
NXP Employee

Hi Lin,

has your problem been resolved?

One important thing to notice is that current CDC Host Example is compatible with standard CDC devices (according to specifications), However, there are some CDC devices (such as FTDI's or SiLabs' or another vendor-specific) that are not accepted because these devices use a custom driver/protocol.

I am wondering if your customer's device uses vendor-specific driver/protocol, if os, CDC Host Example demo will not enumerate these device correctly.

There is a post that ask about CDC Host example (In MQX) does not 'work' with some CDC devices (FTDI) and maybe it could be a good idea to check it out. (USB CDC FTDI devices )

Could you please validate that enumeration process is completed correctly?

Best Regards,

Isaac

0 Kudos

800 Views
lin100
Contributor I

Hi Isaac,

Thanks for your reply.

Now my demo can read and write by using _usb_host_send_data()/ _usb_host_recv_data() api.

but sometimes the data which recerived from device may be confused.

I make the changes on the CDC host demo like below

static const USB_HOST_DRIVER_INFO DriverInfoTable[] = {

   {

      {0x00,0x00},                  /* Vendor ID per USB-IF             */

      {0x00,0x00},                  /* Product ID per manufacturer      */

      0xFF,//USB_CLASS_COMMUNICATION,      /* Class code                       */

      0x00,//USB_SUBCLASS_COM_ABSTRACT,    /* Sub-Class code                   */

      0x00,//0xFF,                         /* Protocol                         */

      0,                            /* Reserved                         */

      usb_host_cdc_acm_event        /* Application call back function   */

   },

#ifdef USBCLASS_INC_CDC

   {

      usb_class_cdc_acm_init,

      sizeof(USB_ACM_CLASS_INTF_STRUCT),

      0xFF,//USB_CLASS_COMMUNICATION,

      0x00,//USB_SUBCLASS_COM_ABSTRACT,

      0x00,//USB_PROTOCOL_COM_NOSPEC,

      0xFF, 0xFF, 0xFE

   },

and  dev_inst_ptr->state can be set to DEVSTATE_ENUM_OK

case DEVSTATE_SET_INTF:    /* Select interface done */

         dev_inst_ptr->state = DEVSTATE_ENUM_OK;

         usb_hostdev_attach_detach(dev_inst_ptr, USB_INTF_EVENT);

         break;

      default:

         dev_inst_ptr->state = DEVSTATE_ENUM_OK;

         case DEVSTATE_ENUM_OK:   /* enumeration complete */

            if ((dev_inst_ptr->control_callback != NULL))

then i use _usb_host_send_data()/ _usb_host_recv_data() to read and write the corresponding pipe,and it work.

I am busy for other things recently,i will check why sometimes the data which recerived from device are confused when i am free.

Thanks and B.R.

Kun

0 Kudos

800 Views
isaacavila
NXP Employee
NXP Employee

Hi Kun

I will be waiting for any update from you.

Best Regards,

Isaac

0 Kudos