How to USB CDC VCOM set line coding ?

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

How to USB CDC VCOM set line coding ?

Jump to solution
2,330 Views
NicolasP
Contributor IV

Hi,

I've started a new project using USB CDC VCOM.

I've imported a SDK example to get a starting example.

In need to manage line coding parameters (baudrate, parity, nb bits...).

Here is the code of the class callback managing line coding in the SDK example :

        case kUSB_DeviceCdcEventGetLineCoding:
            *(acmReqParam->buffer) = vcomInstance->lineCoding;
            *(acmReqParam->length) = LINE_CODING_SIZE;
            error = kStatus_USB_Success;
            break;

        case kUSB_DeviceCdcEventSetLineCoding:
        {
            if (1 == acmReqParam->isSetup)
            {
                *(acmReqParam->buffer) = vcomInstance->lineCoding;
            }
            else
            {
                *(acmReqParam->length) = 0;
            }
        }
            error = kStatus_USB_Success;
            break;

The code in kUSB_DeviceCdcEventGetLineCoding is ok.

We provide a buffer address containing line coding data. These data will be sent to the host.

The code in kUSB_DeviceCdcEventSetLineCoding is problematic.

From what I understand : We, again, provide a buffer address. This buffer address wil be used to receive data from the host when the callback is exited. We don't have data yet so we can't do the real work.

How can the application be aware that data from the host have been received ?

Best regards,

Nicolas

Labels (1)
Tags (2)
0 Kudos
1 Solution
1,549 Views
NicolasP
Contributor IV

I finaly got it.

The callback is called a first time to get a buffer address for packet RX.

The callback is called again once the packet has been received.

The following statement allows to know which call phase it is.

if (1 == acmReqParam->isSetup)‍‍‍

So here is a more understandable piece of code :

        case kUSB_DeviceCdcEventSetLineCoding:
        {
            if (1 == acmReqParam->isSetup)
            {
                // Get buffer address for packet RX
                *(acmReqParam->buffer) = vcomInstance->lineCoding;
            }
            else
            {
                // Do real work with RX data
                // Rx data are at *(acmReqParam->buffer) address

                *(acmReqParam->length) = 0;  // Do nothing when exiting callback
            }
        }
            error = kStatus_USB_Success;
            break;‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

View solution in original post

0 Kudos
1 Reply
1,550 Views
NicolasP
Contributor IV

I finaly got it.

The callback is called a first time to get a buffer address for packet RX.

The callback is called again once the packet has been received.

The following statement allows to know which call phase it is.

if (1 == acmReqParam->isSetup)‍‍‍

So here is a more understandable piece of code :

        case kUSB_DeviceCdcEventSetLineCoding:
        {
            if (1 == acmReqParam->isSetup)
            {
                // Get buffer address for packet RX
                *(acmReqParam->buffer) = vcomInstance->lineCoding;
            }
            else
            {
                // Do real work with RX data
                // Rx data are at *(acmReqParam->buffer) address

                *(acmReqParam->length) = 0;  // Do nothing when exiting callback
            }
        }
            error = kStatus_USB_Success;
            break;‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

0 Kudos