How to get the USB host CDC example working with FTDI adapter.

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

How to get the USB host CDC example working with FTDI adapter.

2,827 Views
ristomustonen
Contributor II

Hello!

I have tried to use "SDK_2.3.1_MK21FN1M0Axxx12" package USB example "usb_host_cdc" with "FTDI 232" adapter with custom board. Device is powered ON and detected OK when plugged in the USB connector:

Terminal printout:
===================
host init done
This example requires that the CDC device uses Hardware flow
if the device does't support it, please set USB_HOST_UART_SUPPORT_HW_FLOW to zero and rebuild this project
Type strings, then the string
will be echoed back from the device
device cdc attached:
pid=0x6001 vid=0x403 address=1
cdc device attached

After connection, USB_HostCdcDataSend() function works. UART terminal data is sent through USB and RS232 line and looped back from Rx-Tx wired loopback connector. Test data is then echoed back to UART terminal correctly. But the data baudrate at RS232 line (checked with oscilloscope) is exactly the USB speed 1.5 MHz. To be able to communicate with another device at RS232 bus the speed must be 115200 bit/s.

So the "outPipe" communication works but at USB speed.
"USB_HostSend(cdcInstance->hostHandle, cdcInstance->outPipe, transfer)"

I tried to figure out how to change the RS232 line baudrate and I have tested to set it with function USB_HostCdcSetAcmLineCoding(), which I wrote according the similar Get - function USB_HostCdcGetAcmLineCoding().
====================
g_LineCode.dwDTERate = 115200;
g_LineCode.bDataBits = 8;
g_LineCode.bParityType = 0;
g_LineCode.bCharFormat = 1;
USB_HostCdcSetAcmLineCoding(cdcInstance->classHandle, &g_LineCode, USB_HostCdcControlCallback, (void *)cdcInstance);
. . .
usb_status_t USB_HostCdcSetAcmLineCoding(usb_host_class_handle classHandle,
usb_host_cdc_line_coding_struct_t *uartLineCoding,
transfer_callback_t callbackFn,
void *callbackParam)
{
return USB_HostCdcControl(classHandle, USB_REQUEST_TYPE_DIR_OUT | USB_REQUEST_TYPE_TYPE_CLASS | USB_REQUEST_TYPE_RECIPIENT_INTERFACE,
USB_HOST_CDC_SET_LINE_CODING, 0, 0, 7, (uint8_t *)uartLineCoding, callbackFn, callbackParam);
}
. . .
USB_HostSendSetup(cdcInstance->hostHandle, cdcInstance->controlPipe, transfer)
===================

But the transfer is fails every time.
"data transfer error = 10" (kStatus_USB_TransferStall)

And similarly all other "controlPipe" operations are failed.

I get the same result with both Bare Metal and FreeRTOS code.

I wonder if I'm trying to do right thing to change baudrate of line and why data transfer is stalled every time with "controlPipe". Does anyone have this kind of problems with CDC type device. I'll be grateful if I'll get some help and solution with this issue.

Best Regards,

Risto

0 Kudos
3 Replies

2,089 Views
Hui_Ma
NXP TechSupport
NXP TechSupport

Hi Risto,

During CDC device enumeration, the USB host will send some request command, such as: GET_LINE_CODING request to get CDC device current serial parameter configuration, such as  baud rate, stop bit, parity type and data bits.

For the USB CDC host and USB CDC device using bulk transfer to transfer data, which actual USB data transfer speed doesn't followed the serial baud rate setting, which try to emulate the serial communication. The FTDI 232 device can transfer received USB data to real UART port with correct baud rate.

So, customer doesn't need to modify USB Host CDC setting.


Have a great day,
Mike

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

0 Kudos

2,089 Views
ristomustonen
Contributor II

Hi Mike,

Thank's for your answer.

Yes I can see that host is sending the GET_LINE_CODING request to device, but it fails every time with kStatus_USB_TransferStall error. Also I do not understand how FTDI 232 device can set its UART baudrate without host setting it. Device does not know what baudrate is desired.

BR,

Risto

0 Kudos

2,089 Views
Hui_Ma
NXP TechSupport
NXP TechSupport

Hi Risto,

 

I try to test FTDI232 USB to Serial tool, while I test below three types without success.

The TWR-K21F120MA serial terminal shows "device not supported."

pastedImage_1.png

So I test with FRDM-K64 board with USB CDC device routine, which can pass the test.

I could find below USB CDC device line coding at <virtual_com.c>

pastedImage_2.png

The macro definition located at <virtual_com.h> file

pastedImage_3.png

I checked the USB CDC Host driver at <usb_host_cdc.c> file, there without provide API function to SET_LINE_CODING. That's why customer can't change USB CDC device baud rate.

 pastedImage_4.png

Thank you for the attention.

 
Have a great day,
Mike

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

0 Kudos