Cypress EZ-USB CX3 适配输出imx586相机
SDK版本: ezusbfx3sdk_1.3.5_Windows_x32-x64.exe
640*480 raw10 30HZ 配置
Image Sensor Configuration
配置参数如上:
THS-Prepare :默认值 (LP - > HS) 如果不确定具体的值,先设定默认值
THS-Zero : 默认值 (LP -> HS) 如果不确定具体的值,先设定默认值
上面两个可能作为判断从LP->HS的参考依据。 没有按照实际设置,测试没发现问题。
CSI Clock : 因为CSI是DDR采样,所以时钟设置为450MHZ,那么单通道允许的最大速度900Mbps,这个设置根据sensor手册进行设置。
H-Active: 640
H-Blanking: 默认,没做修改
V-Active: 480
V-Blanking: 默认,没做修改
Frame Rate: 30
Parallel data: 16-Bit 对应CY_U3P_MIPIOUT_DW_16, /* MIPI out parallel width packing */
表示MIPI Block的输出位宽。
YUV2: 为什么设置YUV2,而没有设置为RAW10呢? 因为RAW10在CSI总线上实际传输是按如下格式:
上述也是按照一个字节一个字节传输的,并不是一个像素(10位)一个像素(10位)传输的,所以可以按照CY_U3P_MIPIOUT_DW_16 16位打包。可以原封不动的传输值并行口
最后将数据传输到GPIF 2接口。
CX3 Receiver Configuration
左侧部分在上面已经说明了,说说右侧部分(虽然右侧部分暂时什么也没动)
REFCLK: 硬件电路决定,与实际的保持一致。
其他始终的关系图如下:
PLL Clock: 是e MIPI CSI-2 block的主时钟,范围62.5 MHz and 1 GHz.其他内部时钟都是基于这个得来的。
PLL_CLK = REFCLK * [(PLL_FBD + 1) / (PLL_PRD + 1) ] / (2^ PLL_FRS)
CSI RX LP -> HS Clock : 这个时钟用于检测LP->HS的转换,也就是一帧图像传输的开始。最大时钟为125MHZ
Output Parallel Clock (PCLK): 这个时钟是定义GPIF并口的最大时钟为100MHZ,最大带宽是24位,决定了最大传输数据为2.4G。
Image Sensor Reference Clock (MCLK): 这个是给外部sensor供应时钟。如24Mhz,只建议测试使用。
Fifo Delay time = ((Fifo Delay * 4/Number of Lanes) + 10)/(CSI_Clock/4)
其他的都默认即可。
Sensor配置部分:
涉及到文件1 cyu3imagesensor.c文件:
- 打开debug
- 设置sensor 设备地址
- 配置SENSOR_BaseConfigurationSettings寄存器数组。
- 配置imx586_YUY2_Resolution1ConfigurationSettings 分辨率数组。
详细配置以文件形式给出。
涉及到文件2 cycx3_uvcdscr.c文件:
使用的是usb2.0,下面修改usb2.0的desc:
出现的问题:
-
调试raw8时出现了,比如我设置像素为600*400,结果收到的数据是:
比240000像素多了两行的数据。
从上面看embedded data刚好是两行,所有查看寄存器设置为0,解决了多两行的问题。 -
在多两行的问题解决后,raw10还有问题,如raw10的数据量大小不对,这时如开始所设置一样,使用YUV2作为数据传输格式,CSI总线上的数据是字节传输不是像素传输。
sudo lsusb -v
Bus 001 Device 012: ID 04b4:00c3 Cypress Semiconductor Corp. CX3-UVC
Device Descriptor:bLength 18bDescriptorType 1bcdUSB 2.10bDeviceClass 239 Miscellaneous DevicebDeviceSubClass 2 bDeviceProtocol 1 Interface AssociationbMaxPacketSize0 64idVendor 0x04b4 Cypress Semiconductor Corp.idProduct 0x00c3 bcdDevice 0.00iManufacturer 1 CypressiProduct 2 CX3-UVCiSerial 0 bNumConfigurations 1Configuration Descriptor:bLength 9bDescriptorType 2wTotalLength 0x00d4bNumInterfaces 2bConfigurationValue 1iConfiguration 4 USB-2.1bmAttributes 0xc0Self PoweredMaxPower 100mAInterface Association:bLength 8bDescriptorType 11bFirstInterface 0bInterfaceCount 2bFunctionClass 14 VideobFunctionSubClass 3 Video Interface CollectionbFunctionProtocol 0 iFunction 0 Interface Descriptor:bLength 9bDescriptorType 4bInterfaceNumber 0bAlternateSetting 0bNumEndpoints 1bInterfaceClass 14 VideobInterfaceSubClass 1 Video ControlbInterfaceProtocol 0 iInterface 0 VideoControl Interface Descriptor:bLength 13bDescriptorType 36bDescriptorSubtype 1 (HEADER)bcdUVC 1.10wTotalLength 0x0051dwClockFrequency 48.000000MHzbInCollection 1baInterfaceNr( 0) 1VideoControl Interface Descriptor:bLength 18bDescriptorType 36bDescriptorSubtype 2 (INPUT_TERMINAL)bTerminalID 1wTerminalType 0x0201 Camera SensorbAssocTerminal 0iTerminal 0 wObjectiveFocalLengthMin 0wObjectiveFocalLengthMax 0wOcularFocalLength 0bControlSize 3bmControls 0x00000000VideoControl Interface Descriptor:bLength 13bDescriptorType 36bDescriptorSubtype 5 (PROCESSING_UNIT)bUnitID 2bSourceID 1wMaxMultiplier 16384bControlSize 3bmControls 0x00000000iProcessing 0 bmVideoStandards 0x00VideoControl Interface Descriptor:bLength 28bDescriptorType 36bDescriptorSubtype 6 (EXTENSION_UNIT)bUnitID 3guidExtensionCode {ffffffff-ffff-ffff-ffff-ffffffffffff}bNumControl 0bNrPins 1baSourceID( 0) 2bControlSize 3bmControls( 0) 0x00bmControls( 1) 0x00bmControls( 2) 0x00iExtension 0 VideoControl Interface Descriptor:bLength 9bDescriptorType 36bDescriptorSubtype 3 (OUTPUT_TERMINAL)bTerminalID 4wTerminalType 0x0101 USB StreamingbAssocTerminal 0bSourceID 3iTerminal 0 Endpoint Descriptor:bLength 7bDescriptorType 5bEndpointAddress 0x82 EP 2 INbmAttributes 3Transfer Type InterruptSynch Type NoneUsage Type DatawMaxPacketSize 0x0040 1x 64 bytesbInterval 1Interface Descriptor:bLength 9bDescriptorType 4bInterfaceNumber 1bAlternateSetting 0bNumEndpoints 1bInterfaceClass 14 VideobInterfaceSubClass 2 Video StreamingbInterfaceProtocol 0 iInterface 0 VideoStreaming Interface Descriptor:bLength 14bDescriptorType 36bDescriptorSubtype 1 (INPUT_HEADER)bNumFormats 1wTotalLength 0x004dbEndPointAddress 131bmInfo 0bTerminalLink 4bStillCaptureMethod 0bTriggerSupport 0bTriggerUsage 0bControlSize 1bmaControls( 0) 0VideoStreaming Interface Descriptor:bLength 27bDescriptorType 36bDescriptorSubtype 4 (FORMAT_UNCOMPRESSED)bFormatIndex 1bNumFrameDescriptors 1guidFormat {32595559-0000-0010-8000-00aa00389b71}bBitsPerPixel 16bDefaultFrameIndex 1bAspectRatioX 0bAspectRatioY 0bmInterlaceFlags 0x00Interlaced stream or variable: NoFields per frame: 2 fieldsField 1 first: NoField pattern: Field 1 onlybCopyProtect 0VideoStreaming Interface Descriptor:bLength 30bDescriptorType 36bDescriptorSubtype 5 (FRAME_UNCOMPRESSED)bFrameIndex 1bmCapabilities 0x00Still image unsupportedwWidth 320wHeight 480dwMinBitRate 73728000dwMaxBitRate 73728000dwMaxVideoFrameBufferSize 307200dwDefaultFrameInterval 333333bFrameIntervalType 1dwFrameInterval( 0) 333333VideoStreaming Interface Descriptor:bLength 6bDescriptorType 36bDescriptorSubtype 13 (COLORFORMAT)bColorPrimaries 0 (Unspecified)bTransferCharacteristics 0 (Unspecified)bMatrixCoefficients 0 (Unspecified)Endpoint Descriptor:bLength 7bDescriptorType 5bEndpointAddress 0x83 EP 3 INbmAttributes 2Transfer Type BulkSynch Type NoneUsage Type DatawMaxPacketSize 0x0200 1x 512 bytesbInterval 0
Binary Object Store Descriptor:bLength 5bDescriptorType 15wTotalLength 0x0016bNumDeviceCaps 2USB 2.0 Extension Device Capability:bLength 7bDescriptorType 16bDevCapabilityType 2bmAttributes 0x00000002HIRD Link Power Management (LPM) SupportedSuperSpeed USB Device Capability:bLength 10bDescriptorType 16bDevCapabilityType 3bmAttributes 0x00wSpeedsSupported 0x000eDevice can operate at Full Speed (12Mbps)Device can operate at High Speed (480Mbps)Device can operate at SuperSpeed (5Gbps)bFunctionalitySupport 3Lowest fully-functional device speed is SuperSpeed (5Gbps)bU1DevExitLat 0 micro secondsbU2DevExitLat 0 micro seconds
can't get debug descriptor: Resource temporarily unavailable
Device Status: 0x0001Self Powered
上面的信息对应的结构体:
- iProduct 2 CX3-UVC
const uint8_t CyCx3USBProductDscr[] =
{0x10, /* Descriptor Size */CY_U3P_USB_STRING_DESCR, /* Device descriptor type */'C', 0x00, /* Product Descriptor String */'X', 0x00,'3', 0x00,'-', 0x00,'U', 0x00,'V', 0x00,'C', 0x00
};
- iConfiguration 4 USB-2.1
const uint8_t CyCx3USBConfigHSDscr[] =
{0x10, /* Descriptor Size */CY_U3P_USB_STRING_DESCR, /* Device descriptor type */'U', 0x00, /* High-Speed Configuration Descriptor */'S', 0x00,'B', 0x00,'-', 0x00,'2', 0x00,'.', 0x00,'1', 0x00
};
/* Standard High Speed Configuration Descriptor */
const uint8_t CyCx3USBHSConfigDscr[] =
{/* Configuration descriptor */0x09, /* Descriptor size */CY_U3P_USB_CONFIG_DESCR, /* Configuration descriptor type */HS_TOTAL_SIZE_CONFIG_DSCR_L,HS_TOTAL_SIZE_CONFIG_DSCR_H, /* Length of this descriptor and all sub descriptors */0x02, /* Number of interfaces */0x01, /* Configuration number */0x04, /* Configuration string index */0xC0, /* Config characteristics - self powered */0x32, /* Max power consumption of device (in 2mA unit) : 100mA *//* Interface Association Descriptor */0x08, /* Descriptor Size */CX3_INTRFC_ASSN_DESCR, /* Interface Association Descriptor Type */0x00, /* Interface number of the VideoControl interface that is associated with this function*/0x02, /* Number of contiguous Video interfaces that are associated with this function */0x0E, /* Video Interface Class Code: CC_VIDEO */0x03, /* Subclass code: SC_VIDEO_INTERFACE_COLLECTION*/0x00, /* Protocol: PC_PROTOCOL_UNDEFINED*/0x00, /* String Descriptor index for interface *//* Standard Video Control Interface Descriptor (Interface 0, Alternate Setting 0)*/0x09, /* Descriptor size */CY_U3P_USB_INTRFC_DESCR, /* Interface Descriptor type */0x00, /* Index of this Interface */0x00, /* Alternate setting number */0x01, /* Number of end points - 1 Interrupt Endpoint*/0x0E, /* Video Interface Class Code: CC_VIDEO */0x01, /* Interface sub class: SC_VIDEOCONTROL */0x00, /* Interface protocol code: PC_PROTOCOL_UNDEFINED.*/0x00, /* Interface descriptor string index *//* Class specific VC Interface Header Descriptor */0x0D, /* Descriptor size */CX3_CS_INTRFC_DESCR, /* Class Specific Interface Descriptor type: CS_INTERFACE */0x01, /* Descriptor Sub type: VC_HEADER */
#ifdef CX3_UVC_1_0_SUPPORT0x00, 0x01, /* Revision of UVC class spec: 1.0 - Legacy version */0x50, 0x00, /* Total Size of class specific descriptors*/
#else0x10, 0x01, /* Revision of UVC class spec: 1.1 - Minimum version required for USB Compliance. Not supported on Windows XP*/ 0x51, 0x00, /* Total Size of class specific descriptors (till Output terminal) */
#endif0x00, 0x6C, 0xDC, 0x02, /* Clock frequency : 48MHz(Deprecated) */0x01, /* Number of streaming interfaces */0x01, /*VideoStreaming interface 1 belongs to this VideoControl interface*//* Input (Camera) Terminal Descriptor */0x12, /* Descriptor size */CX3_CS_INTRFC_DESCR, /* CS_INTERFACE */0x02, /* VC_INPUT_TERMINAL subtype */0x01, /* ID of this input terminal */0x01, 0x02, /* ITT_CAMERA type. This terminal is a camera terminal representing the CCD sensor*/0x00, /* No association terminal */0x00, /* Unused */0x00, 0x00, /* No optical zoom supported */0x00, 0x00, /* No optical zoom supported */0x00, 0x00, /* No optical zoom supported */0x03, /* Size of controls field for this terminal : 3 bytes */0x00, 0x00, 0x00, /* No controls supported *//* Processing Unit Descriptor */
#ifdef CX3_UVC_1_0_SUPPORT0x0C, /* Descriptor size*/
#else0x0D, /* Descriptor size */
#endifCX3_CS_INTRFC_DESCR, /* Class specific interface desc type */0x05, /* Processing Unit Descriptor type: VC_PROCESSING_UNIT*/0x02, /* ID of this unit */0x01, /* Source ID: 1: Conencted to input terminal */0x00, 0x40, /* Digital multiplier */0x03, /* Size of controls field for this terminal: 3 bytes */0x00, 0x00, 0x00, /* No controls supported */0x00, /* String desc index: Not used */
#ifndef CX3_UVC_1_0_SUPPORT 0x00, /* Analog Video Standards Supported: None */
#endif/* Extension Unit Descriptor */0x1C, /* Descriptor size */CX3_CS_INTRFC_DESCR, /* Class specific interface desc type */0x06, /* Extension Unit Descriptor type */0x03, /* ID of this terminal */0xFF, 0xFF, 0xFF, 0xFF, /* 16 byte GUID */0xFF, 0xFF, 0xFF, 0xFF,0xFF, 0xFF, 0xFF, 0xFF,0xFF, 0xFF, 0xFF, 0xFF,0x00, /* Number of controls in this terminal */0x01, /* Number of input pins in this terminal */0x02, /* Source ID : 2 : Connected to Proc Unit */0x03, /* Size of controls field for this terminal : 3 bytes */0x00, 0x00, 0x00, /* No controls supported */0x00, /* String descriptor index : Not used *//* Output Terminal Descriptor */0x09, /* Descriptor size */CX3_CS_INTRFC_DESCR, /* Class specific interface desc type */0x03, /* Output Terminal Descriptor type */0x04, /* ID of this terminal */0x01, 0x01, /* USB Streaming terminal type */0x00, /* No association terminal */0x03, /* Source ID : 3 : Connected to Extn Unit */0x00, /* String desc index : Not used *//* Video Control Status Interrupt Endpoint Descriptor */0x07, /* Descriptor size */CY_U3P_USB_ENDPNT_DESCR, /* Endpoint Descriptor Type */CX3_EP_CONTROL_STATUS, /* Endpoint address and description: EP-2 IN */CY_U3P_USB_EP_INTR, /* Interrupt End point Type */0x40, 0x00, /* Max packet size: 64 bytes */0x01, /* Servicing interval *//* Class Specific Interrupt Endpoint Descriptor */0x05, /* Descriptor size */0x25, /* Class specific endpoint descriptor type */CY_U3P_USB_EP_INTR, /* End point sub type */0x40,0x00, /* Max packet size = 64 bytes *//* Standard Video Streaming Interface Descriptor (Interface 1, Alternate Setting 0) */0x09, /* Descriptor size */CY_U3P_USB_INTRFC_DESCR, /* Interface descriptor type */0x01, /* Interface number: 1 */0x00, /* Alternate setting number: 0 */0x01, /* Number of end points: 1 Bulk endopoint*/0x0E, /* Interface class : CC_VIDEO */0x02, /* Interface sub class : SC_VIDEOSTREAMING */0x00, /* Interface protocol code : PC_PROTOCOL_UNDEFINED */0x00, /* Interface descriptor string index *//* Class-specific Video Streaming Input Header Descriptor */0x0D + HS_NO_OF_VIDEO_FORMATS_SUPPORTED,/* Descriptor size */CX3_CS_INTRFC_DESCR, /* Class-specific VS interface type */0x01, /* Descriptor subtype : Input Header */HS_NO_OF_VIDEO_FORMATS_SUPPORTED, /* Number of video formats supported */HS_TOTAL_SIZE_VS_CLASS_DSCR_L, /* Total size of class specific VS descr LSB */HS_TOTAL_SIZE_VS_CLASS_DSCR_H, /* Total size of class specific VS descr MSB */CX3_EP_BULK_VIDEO, /* EP address for BULK video data: EP 3 IN */0x00, /* No dynamic format change supported */0x04, /* Output terminal ID : 4 */0x00, /* No Still image capture method supported */0x00, /* Hardware trigger not supported */0x00, /* Hardware to initiate still image capture not supported*/0x01, /* Size of controls field : 1 byte */0x00, /* YUY2 Format*//* Class specific Uncompressed VS format descriptor - YUY2 */0x1B, /* Descriptor size */CX3_CS_INTRFC_DESCR, /* Class-specific VS interface Type */0x04, /* Subtype : VS_FORMAT */HS_YUY2_INDEX, /* Format desciptor index */HS_YUY2_TOTAL_NO_OF_RES, /* Number of Frame Descriptors that follow this descriptor: 3 *//* GUID, globally unique identifier used to identify streaming-encoding format: YUY2 */0x59, 0x55, 0x59, 0x32, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0xAA, 0x00, 0x38, 0x9B, 0x71, 0x10, /* Number of bits per pixel: 16*/0x01, /* Optimum Frame Index for this stream: 2 (720p) */0x00, /* X dimension of the picture aspect ratio; Non-interlaced */0x00, /* Y dimension of the pictuer aspect ratio: Non-interlaced */0x00, /* Interlace Flags: Progressive scanning, no interlace */0x00, /* duplication of the video stream restriction: 0 - no restriction *//* Class specific Uncompressed VS Frame Descriptor 1 - Resolution1 320 x 480 @ 30.0 fps*/0x1E, /* Descriptor size */CX3_CS_INTRFC_DESCR, /* Descriptor type*/0x05, /* Subtype: frame interface*/0x01, /* Frame Descriptor Index: 1 */0x00, /* No Still image capture method supported */0x40,0x01, /* Width in pixel: 320 */ 0xe0,0x01, /* Height in pixel: 480 */0x00,0x00,0x65,0x04, /* Min bit rate (bits/s): 320 x 480 x 16 x 30.0 = 73728000 */0x00,0x00,0x65,0x04, /* Max bit rate (bits/s): Fixed rate so same as Min */0x00,0xb0,0x04,0x00, /* Maximum video or still frame size in bytes(Deprecated): 320 x 480 x 2 */0x15,0x16,0x05,0x00, /* Default frame interval (in 100ns units): (1/30.0)x10^7 */0x01, /* Frame interval type : No of discrete intervals */0x15,0x16,0x05,0x00, /* Frame interval 3: Same as Default frame interval *//* Color matching descriptor - YUY2 */0x06,0x24,0x0D,0x00,0x00,0x00,/* Endpoint descriptor for Bulk streaming video data */0x07, /* Descriptor size */CY_U3P_USB_ENDPNT_DESCR, /* Endpoint Descriptor Type */CX3_EP_BULK_VIDEO, /* Endpoint address and description: EP 3 IN */CY_U3P_USB_EP_BULK, /* BULK End point */0x00, /* Packet Size: 512 bytes */0x02,0x00 /* Servicing interval for data transfers */
};
当主机连接你的 UVC 设备时,视频类驱动(如 Windows Camera Class Driver、Linux UVC Driver)会通过控制传输:
发送 GET_DEF / GET_MIN / GET_MAX / GET_CUR 请求,来询问设备支持的默认视频参数。
主机会基于你返回的内容选择合适参数,然后发 SET_CUR。
最后发送 COMMIT,确认启动视频流。
记录下结构体:
/* UVC Probe Control Settings - Input format: RAW8, Output Format: YUY2 - Resolution1 320 x 480 @ 30.0 fps*/
uint8_t const glRAW8_YUY2Resolution1ProbeCtrl[CX3_UVC_MAX_PROBE_SETTING] = {0x00, 0x00, /* bmHint : No fixed parameters */SS_YUY2_INDEX, /* Use 1st Video format index */0x01, /* Use 1st Video frame index */0x15,0x16,0x05,0x00, /* Desired frame interval in 100ns = (1/ 30.0)x10^7 */ 0x00, 0x00, /* Key frame rate in key frame/video frame units */0x00, 0x00, /* PFrame rate in PFrame / key frame units */ 0x00, 0x00, /* Compression quality control */0x00, 0x00, /* Window size for average bit rate */0x00, 0x00, /* Internal video streaming i/f latency in ms */0x00,0xb0,0x04,0x00, /* Max video frame size in bytes = 320 x 480 x 2 */
#ifdef CX3_UVC_1_0_SUPPORT 0x00, 0x90, 0x00, 0x00 /* No. of bytes device can rx in single payload: 36KB */
#else/* UVC 1.1 Probe Control has additional fields from UVC 1.0 */0x00, 0x90, 0x00, 0x00, /* No. of bytes device can rx in single payload: 36KB */0x00, 0x60, 0xE3, 0x16, /* Device Clock */0x00, /* Framing Information - Ignored for uncompressed format*/0x00, /* Preferred payload format version */0x00, /* Minimum payload format version */0x00 /* Maximum payload format version */
#endif
};
上面结构体是在获取对应分辨率相机的数据时,反馈给主控设备的字段
Host requests for probe data of 34 bytes (UVC 1.1) or 26 Bytes (UVC1.0). Send it over EP0.
SS UVC Probe control structure corresponding to each format and frame
ref:参考链接
工程代码资源下载链接:CX3-imx586-raw10-raw8
查看图片数据
sudo v4l2-ctl -d /dev/video0 --set-fmt-video=width=1920,height=1080,pixelformat=YUYV --stream-mmap=3
sudo v4l2-ctl -d /dev/video0 --set-fmt-video=width=640,height=480,pixelformat=YUYV --stream-mmap=3
sudo v4l2-ctl -d /dev/video0 --set-fmt-video=width=640,height=480,pixelformat=YUYV --stream-mmap=3 --stream-to=frame.raw --stream-count=1
sudo v4l2-ctl -d /dev/video0 --set-fmt-video=width=1920,height=1080,pixelformat=YUYV --stream-mmap=3 --stream-to=frame.raw --stream-count=1