AnsweredAssumed Answered

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

Question asked by Risto Mustonen on Oct 18, 2018
Latest reply on Oct 25, 2018 by Hui_Ma

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

Outcomes