Adding Handshaking to KSDK 2.0 USB CDC Stack

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

Adding Handshaking to KSDK 2.0 USB CDC Stack

1,563 Views
myke_predko
Senior Contributor III


I'm working on an app with the K22F which will communicate with a number of PC applications.  One application requires the use of the (virtual) RS-232 hardware handshaking pins (DTR, DSR, CTS, RTS, DCD & RI).  This doesn't seem to be part of the CDC Stack provided as part of KSDK 2.0 (according to the CDC specification, there should be a "SET_CONTROL_LINE_STATE" request). 

 

Has anybody accessed the virtual handshaking lines in the KSDK 2.0 USB CDC Stack? 

 

Thanx,

 

myke

Labels (1)
Tags (3)
0 Kudos
8 Replies

879 Views
benatar
Contributor I

Hi Iva,

Thanks for your reply. I was experiencing the same issue.

One question - i am using the FREERTOS example of dev_cdc_vcom_freertos on K22 board.

Do i need to include the usb_host_cdc.c file in my project ?

Where should i invoke the mentioned function from?

Thanks,

Ben

0 Kudos

879 Views
ivadorazinova
NXP Employee
NXP Employee

Hi Myke.

The "SET_CONTROL_LINE_STATE" request is handled in application layer, which is located in virtual_com.c.

You can refer to the snippet of code as below

case kUSB_DeviceCdcEventSetControlLineState:

        {

            s_usbCdcAcmInfo.dteStatus = acmReqParam->setupValue;

            /* activate/deactivate Tx carrier */

            if (acmInfo->dteStatus & USB_DEVICE_CDC_CONTROL_SIG_BITMAP_CARRIER_ACTIVATION)

            {

                acmInfo->uartState |= USB_DEVICE_CDC_UART_STATE_TX_CARRIER;

            }

            else

            {

                acmInfo->uartState &= (uint16_t)~USB_DEVICE_CDC_UART_STATE_TX_CARRIER;

            }

            /* activate carrier and DTE */

    ...

In case of any issue, please let me know.

Best Regards,

Iva

0 Kudos

879 Views
myke_predko
Senior Contributor III

HI Iva,

Could you please show me how to:

  1. Enable and set the RTS and CTS virtual handshaking lines?
  2. Setup an Event Monitor for the DTR line? 

In case you haven't guessed, the host software I'm looking for is trying to communicate with an Arduino, so I need to simulate the interface. 

Thanx,

myke

0 Kudos

879 Views
ivadorazinova
NXP Employee
NXP Employee

Hi Myke,

please give me short time I have been gathering information for you.

I will answer you as soon as possible.

Thank you.

Best Regards.
Iva

0 Kudos

879 Views
myke_predko
Senior Contributor III

Thanx Iva! 

Let me know if there's anything I can do to help.

myke

0 Kudos

879 Views
ivadorazinova
NXP Employee
NXP Employee

Hello Myke.

Based on Reference Manual USB Stack Host, there are two macros for this

• #define USB_HOST_CDC_CONTROL_LINE_STATE_DTR 0x01U

CDC class-specific request (SET_CONTROL_LINE_STATE) bitmap.

• #define USB_HOST_CDC_CONTROL_LINE_STATE_RTS 0x02U

CDC class-specific request (SET_CONTROL_LINE_STATE) bitmap.

to set the virtual handshaking signals, call USB_HostCdcSetAcmCtrlState() (see bellow) which is snippet from usb_host_cdc.c

usb_status_t USB_HostCdcSetAcmCtrlState(

    usb_host_class_handle classHandle, uint8_t dtr, uint8_t rts, transfer_callback_t callbackFn, void *callbackParam)

{

    uint16_t lineState = 0;

    usb_host_cdc_instance_struct_t *cdcInstance = (usb_host_cdc_instance_struct_t *)classHandle;

    lineState = dtr ? USB_HOST_CDC_CONTROL_LINE_STATE_DTR : 0;

    lineState |= rts ? USB_HOST_CDC_CONTROL_LINE_STATE_RTS : 0;

    return USB_HostCdcControl(

        cdcInstance, USB_REQUEST_TYPE_DIR_OUT | USB_REQUEST_TYPE_TYPE_CLASS | USB_REQUEST_TYPE_RECIPIENT_INTERFACE,

        USB_HOST_CDC_SET_CONTROL_LINE_STATE, USB_SHORT_GET_LOW(lineState), USB_SHORT_GET_HIGH(lineState), 0, NULL,

        callbackFn, callbackParam);

}

To read the virtual handshaking signals, you can check the state->bmstate in USB_HostCdcInterruptPipeCallback() in usb_host_cdc.c.

void USB_HostCdcInterruptPipeCallback(void *param, usb_host_transfer_t *transfer, usb_status_t status)

{

    usb_host_cdc_instance_struct_t *cdcInstance = (usb_host_cdc_instance_struct_t *)param;

    USB_HostFreeTransfer(cdcInstance->hostHandle, transfer);

    if (cdcInstance->interruptCallbackFn != NULL)

    {

        cdcInstance->interruptCallbackFn(cdcInstance->interruptCallbackParam, transfer->transferBuffer,

                                         transfer->transferSofar, status);

    }

}

This callback serves for an interrupt pipe so that it would be invoked periodically. As long as the device side had sent the handshaking signals through the interrupt pipe, the host side should read the incoming signals.

I hope this helps.

In case of any question, please let me know.

Best Regards,

Iva

0 Kudos

879 Views
phantomgz
Contributor III

Hi Iva.

I'm work in a USB device CDC, how can I get those state like in host?

thx.

Cai.

0 Kudos

879 Views
myke_predko
Senior Contributor III

Hi Iva,

Thank you for the pointer - now, how do I

a) set the virtual handshaking signals

b) read the virtual handshaking signals coming in?

Thanx again,

myke

0 Kudos