How to USB CDC VCOM set line coding ?

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

How to USB CDC VCOM set line coding ?

跳至解决方案
3,415 次查看
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

标签 (1)
标记 (2)
0 项奖励
回复
1 解答
2,634 次查看
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 项奖励
回复
1 回复
2,635 次查看
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 项奖励
回复