FX3 Non-UVC 图像采集+虚拟串口复合设备(新手入门手册)

[复制链接]
6420|11
手机看帖
扫描二维码
随时随地手机跟帖
zengweitotty|  楼主 | 2015-11-5 16:10 | 显示全部楼层 |阅读模式
新手入门的系列文档【原创】
如果自己的板子没有预留UART口进行调试,可以通过本帖方法配置为虚拟串口复合设备通过API  CyU3PDebugPrint 打印调试信息。具体内容如下:
NON-UVC Virtual COM 复合设备,进行调试信息打印。
确认使用的VirtualCOM驱动版本如下:
New Bitmap Image.bmp
在3.0下添加如下配置描述符。
更改如下ssconfigurationdescriptor
#ifndefCDC_DEBUG
    0x1F, 0x00,                         /* Length of this descriptor and all sub descriptors */
    0x01,                                /* Number of interfaces */
#else
   0x73,0x00,
   0x03,                                /* Number of interfaces */
#endif

在配置描述符最后添加如下信息。
#ifdef CDC_DEBUG
              ,
              /* Interfaceassociation descriptor */
              0x08,                           /* Descriptor size*/
              CY_FX_INTF_ASSN_DSCR_TYPE,      /* Interface association descr type*/
              0x01,                           /* first interface*/
              0x02,                           /* InterfaceCount */
              0x02,                           /* CDC */
              0x02,                           /* abstract controlmodel */
              0x01,                           /* AT commands*/
              0x00,                           /* String descindex for interface */
              /* CommunicationInterface descriptor */
              0x09,                           /* Descriptor size*/
              CY_U3P_USB_INTRFC_DESCR,        /* Interface Descriptor type */
              0x01,                           /* Interface number*/
              0x00,                           /* Alternatesetting number */
              0x01,                           /* Number of endpoints*/
              0x02,                           /* Interface class: Communication Interface */
              0x02,                           /* Interface subclass */
              0x01,                           /* Interface protocol code */
              0x00,                           /* Interfacedescriptor string index */
              /* CDCClass-specific Descriptors */
              /* Headerfunctional Descriptor */
              0x05,                           /* Descriptorslength(5) */
              0x24,                           /* Descriptor type: CS_Interface */
              0x00,                           /*DescriptorSubType : Header Functional Descriptor */
              0x10,0x01,                      /* bcdCDC : CDCRelease Number */
              /* Abstract ControlManagement Functional Descriptor */
              0x04,                           /* DescriptorsLength (4) */
              0x24,                           /* bDescriptorType:CS_INTERFACE */
              0x02,                           /*bDescriptorSubType: Abstract Control Model Functional Descriptor */
              0x02,                           /* bmCapabilities:Supports the request combination of Set_Line_Coding,
                                                    Set_Control_Line_State, Get_Line_Coding and the notificationSerial_State */
              /* Union FunctionalDescriptor */
              0x05,                           /* DescriptorsLength (5) */
              0x24,                           /* bDescriptorType:CS_INTERFACE */
              0x06,                           /*bDescriptorSubType: Union Functional Descriptor */
              0x01,                           /* bMasterInterface*/
              0x02,                           /* bSlaveInterface*/
              /* Call ManagementFunctional Descriptor */
              0x05,                           /*  Descriptors Length (5) */
              0x24,                           /* bDescriptorType: CS_INTERFACE */
              0x01,                           /*  bDescriptorSubType: Call ManagementFunctional Descriptor */
              0x00,                           /*  bmCapabilities: Device sends/receives callmanagement information
                                                      only over theCommunication Class Interface. */
              0x01,                           /*  Interface Number of Data Class interface */
              /* EndpointDescriptor(Interrupt) */
              0x07,                           /* Descriptor size*/
              CY_U3P_USB_ENDPNT_DESCR,        /* Endpoint descriptor type */
              CY_FX_EP_INTERRUPT_UART,        /* Endpoint address and description*/
              CY_U3P_USB_EP_INTR,             /* Interrupt endpoint type */
              0x40,0x00,                      /* Max packet size= 64 bytes */
              0x02,                           /* Servicinginterval for data transfers */
              /* Super Speed EndpointCompanion Descriptor */
              0x06,                               /* Descriptor size*/
              CY_U3P_SS_EP_COMPN_DESCR,           /* SS Endpoint Companion DescriptorType */
              0x00,                               /* Max no. ofpackets in a Burst: 1 */
              0x00,                               /* Attribute: N.A.*/
              0x40,                               /* Bytes perinterval: 1024 */
              0x00,
              /* Data InterfaceDescriptor */
              0x09,                           /* Descriptor size*/
              CY_U3P_USB_INTRFC_DESCR,        /* Interface Descriptor type */
              0x02,                           /* Interface number*/
              0x00,                           /* Alternatesetting number */
              0x02,                           /* Number of endpoints*/
              0x0A,                           /* Interface class:Data interface */
              0x00,                           /* Interface subclass */
              0x00,                           /* Interface protocol code */
              0x00,                           /* Interfacedescriptor string index */
              /* EndpointDescriptor(BULK-PRODUCER) */
              0x07,                           /* Descriptor size*/
              CY_U3P_USB_ENDPNT_DESCR,        /* Endpoint descriptor type */
              CY_FX_EP_PRODUCER_UART,                           /* Endpointaddress and description */
              CY_U3P_USB_EP_BULK,             /* BULK endpoint type */
              0x00,0x04,                      /* Max packet size= 512 bytes */
              0x00,                           /* Servicing interval for data transfers */
              /* Super Speed EndpointCompanion Descriptor */
              0x06,                               /* Descriptor size*/
              CY_U3P_SS_EP_COMPN_DESCR,           /* SS Endpoint Companion DescriptorType */
              0x0F,                               /* Max number ofpackets per burst: 12 */
              0x00,                               /* Attribute:Streams not defined */
              0x00,                               /* No meaning forbulk */
              0x00,
              /* EndpointDescriptor(BULK- CONSUMER) */
              0x07,                           /* Descriptor size*/
              CY_U3P_USB_ENDPNT_DESCR,        /* Endpoint descriptor type */
              CY_FX_EP_CONSUMER_UART,                           /* Endpointaddress and description */
              CY_U3P_USB_EP_BULK,             /* Bulk endpoint type */
              0x00,0x04,                      /* Max packet size= 512 bytes */
              0x00,                           /* Servicinginterval for data transfers */
              /* Super Speed EndpointCompanion Descriptor */
              0x06,                               /* Descriptor size*/
              CY_U3P_SS_EP_COMPN_DESCR,           /* SS Endpoint Companion DescriptorType */
              0x0F,                               /* Max number ofpackets per burst: 12 */
              0x00,                               /* Attribute:Streams not defined */
              0x00,                               /* No meaning forbulk */
              0x00
#endif


zengweitotty|  楼主 | 2015-11-5 16:11 | 显示全部楼层
在USB setup callback下添加virtual COM 处理代码。



打开串口如下,驱动将会发送如下USB 标准请求

bRType = 0x21, bRequest = 0x22, wValue = 0x0, wIndex = 0x1, wLength= 0x0

关闭串口,驱动将会发送如下USB 标准请求

bRType = 0x21, bRequest = 0x22, wValue = 0x0, wIndex = 0x1, wLength= 0x0

bRType = 0xA1, bRequest = 0x21, wValue = 0x0, wIndex = 0x1, wLength= 0x7



可以根据自己驱动产生的请求进行修改。



#ifdef CDC_DEBUG

       uint16_t readCount = 0;

       CyU3PUartConfig_t uartConfig;



       uint8_t config_data[7];

       if (CY_U3P_GET_LSB(wIndex) == CX3_UART_STREAM_INTERFACE || CY_U3P_GET_LSB(wIndex) == CX3_UART_CONTROL_INTERFACE){

              if(bRequest == SET_LINE_CODING)

              {

                     isHandled = CyTrue;

                     status = CyU3PUsbGetEP0Data(0x07, config_data, &readCount);

                     if (status != CY_U3P_SUCCESS)

                     {

                           CyCx3UvcAppErrorHandler(status);

                     }

                     if (readCount != 0x07)

                     {

                           CyCx3UvcAppErrorHandler(CY_U3P_ERROR_BAD_SIZE);

                     }

                     else

                     {

                           CyU3PMemSet ((uint8_t *)&uartConfig, 0, sizeof (uartConfig));

                           uartConfig.baudRate = (CyU3PUartBaudrate_t)(config_data[0] | (config_data[1]<<8)|(config_data[2]<<16)|(config_data[3]<<24));

                           if (config_data[4] == 0)

                           {

                                  uartConfig.stopBit = CY_U3P_UART_ONE_STOP_BIT;

                           }

                           else if (config_data[4] == 2)

                           {

                                  uartConfig.stopBit = CY_U3P_UART_TWO_STOP_BIT;

                           }

                           else

                           {

                                  /* Give invalid value. */

                                  uartConfig.stopBit = (CyU3PUartStopBit_t)0;

                           }

                           if (config_data[5] == 1)

                           {

                                  uartConfig.parity = CY_U3P_UART_ODD_PARITY;

                           }

                           else if (config_data[5] == 2)

                           {

                                  uartConfig.parity = CY_U3P_UART_EVEN_PARITY;

                           }

                           else

                           {

                                  /* 0 = no parity; any other value - invalid parity. */

                                  uartConfig.parity = CY_U3P_UART_NO_PARITY;

                           }



                           uartConfig.txEnable = CyTrue;

                           uartConfig.rxEnable = CyTrue;

                           uartConfig.flowCtrl = CyFalse;

                           uartConfig.isDma = CyTrue;



                           /* Set the uart configuration */

                           // status = CyU3PUartSetConfig (&uartConfig, NULL);

                           if (status == CY_U3P_SUCCESS)

                           {

                                  CyU3PMemCopy ((uint8_t *)&glUartConfig, (uint8_t *)&uartConfig,

                                                sizeof (CyU3PUartConfig_t));

                           }

                     }

              }

              /* get_line_coding */

              else if (bRequest == GET_LINE_CODING )

              {

                     isHandled = CyTrue;

                     /* get current uart config */

                     config_data[0] = glUartConfig.baudRate&(0x000000FF);

                     config_data[1] = ((glUartConfig.baudRate&(0x0000FF00))>> 8);

                     config_data[2] = ((glUartConfig.baudRate&(0x00FF0000))>>16);

                     config_data[3] = ((glUartConfig.baudRate&(0xFF000000))>>24);

                     if (glUartConfig.stopBit == CY_U3P_UART_ONE_STOP_BIT)

                     {

                           config_data[4] = 0;

                     }

                     else /* CY_U3P_UART_TWO_STOP_BIT */

                     {

                           config_data[4] = 2;

                     }



                     if (glUartConfig.parity == CY_U3P_UART_EVEN_PARITY)

                     {

                           config_data[5] = 2;

                     }

                     else if (glUartConfig.parity == CY_U3P_UART_ODD_PARITY)

                     {

                           config_data[5] = 1;

                     }

                     else

                     {

                           config_data[5] = 0;

                     }

                     config_data[6] =  0x08;

                     status = CyU3PUsbSendEP0Data( 0x07, config_data);

                     if (status != CY_U3P_SUCCESS)

                     {

                           CyCx3UvcAppErrorHandler(status);

                     }

                     if(bRType == 0xa1 && UartFlag == CyTrue){

//                         CyU3PDebugPrint(4,"Open Console\n\r");

                           UartFlag = CyFalse;

                           CyU3PDebugSetTraceLevel(8);

                     }

              }

              /* SET_CONTROL_LINE_STATE */

              else if (bRequest == SET_CONTROL_LINE_STATE)

              {

                     if (CY_U3P_GET_LSB(wIndex) == CX3_UART_CONTROL_INTERFACE && ((wValue & 0x03) == 0x01)){

                           CyU3PUsbAckSetup ();

                           UartFlag = CyTrue;

                     }else if(CY_U3P_GET_LSB(wIndex) == CX3_UART_CONTROL_INTERFACE && ((wValue & 0x03) == 0x00)){

                           CyU3PUsbAckSetup ();

                           if(UartFlag == CyTrue){

                           }else{

//                                CyU3PDebugPrint(4,"Close Console\n\r");

                                  CyU3PDebugSetTraceLevel(1);



                           }

                           /*further use*/

//                   }else if(CY_U3P_GET_LSB(wIndex) == CX3_UART_STREAM_INTERFACE && ((wValue & 0x01) == 0x01) ){

//                         CyU3PDebugSetTraceLevel(8);

//                         CyU3PUsbAckSetup ();

//                   }else if(CY_U3P_GET_LSB(wIndex) == CX3_UART_STREAM_INTERFACE && ((wValue & 0x00) == 0x00) ){

//                         CyU3PUsbAckSetup ();

                     }else{

                           CyU3PUsbStall (0, CyTrue, CyFalse);

                     }

                     isHandled = CyTrue;

              }

       }

#endif

使用如下代码初始化相应的DMA channel,并且将打印级别设置为最低。

#ifdef CDC_DEBUG

       UartFlag = CyFalse;

       switch(CyU3PUsbGetSpeed())

       {

       case CY_U3P_FULL_SPEED:

              endPointConfig.pcktSize = CX3_EP_BULK_FULL_SPEED_PKT_SIZE;

              endPointConfig.burstLen = CX3_EP_BULK_FULL_SPEED_BURST_LEN;

              break;



       case CY_U3P_HIGH_SPEED:

              endPointConfig.pcktSize = CX3_EP_BULK_HIGH_SPEED_PKT_SIZE;

              endPointConfig.burstLen = CX3_EP_BULK_HIGH_SPEED_BURST_LEN;

              break;



       case CY_U3P_SUPER_SPEED:

       default:

              endPointConfig.pcktSize = CX3_EP_BULK_VIDEO_PKT_SIZE;

              endPointConfig.burstLen = CX3_EP_BULK_SUPER_SPEED_BURST_LEN;

       }

       CyU3PMemSet ((uint8_t *)&endPointConfig, 0, sizeof (endPointConfig));

       endPointConfig.enable = CyTrue;

       endPointConfig.epType = CY_U3P_USB_EP_BULK;

       endPointConfig.isoPkts = 0;

       endPointConfig.streams = 0;

       /* Producer endpoint configuration */

       status = CyU3PSetEpConfig(CY_FX_EP_PRODUCER_UART , &endPointConfig);

       if (status != CY_U3P_SUCCESS)

       {

              CyCx3UvcAppErrorHandler (status);

       }

       /* Consumer endpoint configuration */

       status = CyU3PSetEpConfig(CY_FX_EP_CONSUMER_UART, &endPointConfig);

       if (status != CY_U3P_SUCCESS)

       {

              CyCx3UvcAppErrorHandler (status);

       }

       endPointConfig.epType = CY_U3P_USB_EP_INTR;

       endPointConfig.pcktSize = 64;

       endPointConfig.isoPkts = 0;

       status = CyU3PSetEpConfig(CY_FX_EP_INTERRUPT_UART, &endPointConfig);

       if (status != CY_U3P_SUCCESS)

       {

              CyCx3UvcAppErrorHandler (status);

       }

       status = CyU3PUsbFlushEp(CY_FX_EP_CONSUMER_UART);

       if(status != CY_U3P_SUCCESS) {

              CyCx3UvcAppErrorHandler(status);

       }

       status = CyU3PDebugInit (CY_FX_EP_CONSUMER2_SOCKET,1);

       if (status != CY_U3P_SUCCESS)

       {

              CyCx3UvcAppErrorHandler(status);

       }

       CyU3PDebugPreamble(CyFalse);

#endif

使用特权

评论回复
zengweitotty|  楼主 | 2015-11-5 16:13 | 显示全部楼层
附上源代码,有问题可以一起讨论。

使用特权

评论回复
zengweitotty|  楼主 | 2015-11-5 16:14 | 显示全部楼层
CX3Temp_MT9M114_NonUVC.zip (986.68 KB)

使用特权

评论回复
zuikongxudetong| | 2017-4-20 10:25 | 显示全部楼层
您好!请问帖子开头提到的使用的VirtualCOM驱动版本CypressUsbConsoleWindowsDriver在何处获取?

使用特权

评论回复
yldyb| | 2018-5-4 16:08 | 显示全部楼层
你好,我刷了你的img,但并没有出现uart,请问是什么原因呢?

使用特权

评论回复
digger123| | 2018-7-27 11:07 | 显示全部楼层
这是FX3的?怎么代码里面是CX3的?

使用特权

评论回复
dingy| | 2018-7-28 09:37 | 显示全部楼层
不错,支持下

使用特权

评论回复
lvyunhua| | 2020-4-16 10:37 | 显示全部楼层
我想请教下FX3的uart调试口是哪两个引脚呢?

使用特权

评论回复
layneQQ| | 2020-6-15 16:24 | 显示全部楼层
不错,可以学习一下!!!

使用特权

评论回复
dingxuandi| | 2020-10-10 17:54 | 显示全部楼层
lvyunhua 发表于 2020-4-16 10:37
我想请教下FX3的uart调试口是哪两个引脚呢?

GPIO55和GPIO56

使用特权

评论回复
lvyunhua| | 2020-10-12 11:08 | 显示全部楼层
GPIO55和GPIO56

谢谢 ,你们一般是用UART口查看调试信息 吗,FX3固件里状态机生成的.h文件是怎么得到了,关于FX3芯片内部资源以及寄存器应用 ,有没有文档可以详细了解下吗?

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

26

主题

61

帖子

19

粉丝