How to USB CDC VCOM set line coding ?

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

How to USB CDC VCOM set line coding ?

ソリューションへジャンプ
3,417件の閲覧回数
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,636件の閲覧回数
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,637件の閲覧回数
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 件の賞賛
返信