922|0

504

帖子

4

TA的资源

纯净的硅(高级)

楼主
 

[原创] 【ST多款开发板返场测评】STM32F767 Nucleo-144 实现UVC设备-枚举与开关 [复制链接]

前言

USB设备的开发第一步是准备描述符,可以参考规格书和搜索样例准备。

我们这里就来准备UVC设备的描述符, 完成枚举过程调试,枚举成功也就成功了一半了。

 

添加代码

  1. 添加源码

 

 

  1. 配置头文件包含路径

 

  1. Main.h中

#include "usbd_video.h"

#include "usbd_video_if_template.h"

  1. Main.c中

  USBD_RegisterClass(&USBD_Device, USBD_VIDEO_CLASS);

USBD_VIDEO_RegisterInterface(&USBD_Device, &USBD_VIDEO_fops_FS);

 

  1. usbd_video_if_template.h中

const  uint8_t image[] = {0x00};

const  uint8_t *tImagesList[] = {image};

uint16_t tImagesSizes[] = {IMAGE_SIZE};

移动到usbd_video_if_template.c中

 

  1. usbd_core.c中USBD_LL_SetupStage添加调试输出

  do_debug(DEBUG_TAG_SETUP, DEBUG_LEVEL_INFO, "%#02x %#02x %#02x %#02x %#02x", pdev->request.bmRequest,pdev->request.bRequest,pdev->request.wValue,pdev->request.wIndex,pdev->request.wLength);

  1. USBD_malloc使用了malloc堆管理,堆设置大一些

 

描述符

Usbd_desc.c中

设备描述符

如下

重点注意bDeviceClassbDeviceSubClassbDeviceProtocol 着三个值

参考https://mp.weixin.qq.com/s/qPdHOjLlZRoAKCdj1_8ZGA

 

/* USB Standard Device Descriptor */

#if defined ( __ICCARM__ ) /*!< IAR Compiler */

  #pragma data_alignment=4   

#endif

__ALIGN_BEGIN   uint8_t USBD_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END = {

  0x12,                       /* bLength */

  USB_DESC_TYPE_DEVICE,       /* bDescriptorType */

  0x00,                       /* bcdUSB */

  0x02,

  0xEF,                       /* bDeviceClass */

  0x02,                       /* bDeviceSubClass */

  0x01,                       /* bDeviceProtocol */

  USB_MAX_EP0_SIZE,           /* bMaxPacketSize */

  LOBYTE(USBD_VID),           /* idVendor */

  HIBYTE(USBD_VID),           /* idVendor */

  LOBYTE(USBD_PID),           /* idVendor */

  HIBYTE(USBD_PID),           /* idVendor */

  0x00,                       /* bcdDevice rel. 2.00 */

  0x02,

  USBD_IDX_MFC_STR,           /* Index of manufacturer string */

  USBD_IDX_PRODUCT_STR,       /* Index of product string */

  USBD_IDX_SERIAL_STR,        /* Index of serial number string */

  USBD_MAX_NUM_CONFIGURATION  /* bNumConfigurations */

}; /* USB_DeviceDescriptor */

字符串描述符

修改对应的字符串

#define USBD_MANUFACTURER_STRING      "MyCompany"

#define USBD_PRODUCT_HS_STRING        "UVCCamera"

#define USBD_PRODUCT_FS_STRING        "UVCCamera"

#define USBD_CONFIGURATION_HS_STRING  "UVC Config"

#define USBD_INTERFACE_HS_STRING      "UVC Interface"

#define USBD_CONFIGURATION_FS_STRING  "UVC Config"

#define USBD_INTERFACE_FS_STRING      "UVC Interface"

 

配置描述符

usbd_video.c中

USBD_VIDEO_CfgDesc

详见后面UsbTreeView解析

测试

运行看到打印的枚举过程如下

 

设备管理器看到枚举的设备

 

使用potplayer可以看到设备

 

 

打开关闭设备

 

 

UsbTreeView查看描述符解析

 

 

    ---------------------- Device Descriptor ----------------------

bLength                  : 0x12 (18 bytes)

bDescriptorType          : 0x01 (Device Descriptor)

bcdUSB                   : 0x200 (USB Version 2.0) -> but device is Full-Speed only

bDeviceClass             : 0xEF (Miscellaneous)

bDeviceSubClass          : 0x02

bDeviceProtocol          : 0x01 (IAD - Interface Association Descriptor)

bMaxPacketSize0          : 0x40 (64 bytes)

idVendor                 : 0x0483 (STMicroelectronics)

idProduct                : 0x5710

bcdDevice                : 0x0200

iManufacturer            : 0x01 (String Descriptor 1)

 Language 0x0409         : "MyCompany"

iProduct                 : 0x02 (String Descriptor 2)

 Language 0x0409         : "UVCCamera"

iSerialNumber            : 0x03 (String Descriptor 3)

 Language 0x0409         : "FFFFFFFEFFFF"

bNumConfigurations       : 0x01 (1 Configuration)

Data (HexDump)           : 12 01 00 02 EF 02 01 40 83 04 10 57 00 02 01 02   .......@...W....

                           03 01                                             ..



    ------------------ Configuration Descriptor -------------------

bLength                  : 0x09 (9 bytes)

bDescriptorType          : 0x02 (Configuration Descriptor)

wTotalLength             : 0x0088 (136 bytes)

bNumInterfaces           : 0x02 (2 Interfaces)

bConfigurationValue      : 0x01 (Configuration 1)

iConfiguration           : 0x00 (No String Descriptor)

bmAttributes             : 0xC0

 D7: Reserved, set 1     : 0x01

 D6: Self Powered        : 0x01 (yes)

 D5: Remote Wakeup       : 0x00 (no)

 D4..0: Reserved, set 0  : 0x00

MaxPower                 : 0x32 (100 mA)

Data (HexDump)           : 09 02 88 00 02 01 00 C0 32 08 0B 00 02 0E 03 00   ........2.......

                           00 09 04 00 00 00 0E 01 00 00 0D 24 01 10 01 1E   ...........$....

                           00 00 6C DC 02 01 01 08 24 02 01 00 02 00 00 09   ..l.....$.......

                           24 03 02 01 01 00 01 00 09 04 01 00 00 0E 02 00   $...............

                           00 0E 24 01 01 37 00 81 00 02 00 00 00 01 00 0B   ..$..7..........

                           24 06 01 01 01 01 00 00 00 00 1E 24 07 01 02 90   $..........$....

                           01 F0 00 00 60 EA 00 00 60 EA 00 00 B8 0B 00 40   ....`...`......@

                           42 0F 00 01 40 42 0F 00 09 04 01 01 01 0E 02 00   B...@B..........

                           00 07 05 81 05 00 01 01                           ........



        ------------------- IAD Descriptor --------------------

bLength                  : 0x08 (8 bytes)

bDescriptorType          : 0x0B (Interface Association Descriptor)

bFirstInterface          : 0x00 (Interface 0)

bInterfaceCount          : 0x02 (2 Interfaces)

bFunctionClass           : 0x0E (Video)

bFunctionSubClass        : 0x03 (Video Interface Collection)

bFunctionProtocol        : 0x00 (PC_PROTOCOL_UNDEFINED)

iFunction                : 0x00 (No String Descriptor)

Data (HexDump)           : 08 0B 00 02 0E 03 00 00                           ........



        ---------------- Interface Descriptor -----------------

bLength                  : 0x09 (9 bytes)

bDescriptorType          : 0x04 (Interface Descriptor)

bInterfaceNumber         : 0x00 (Interface 0)

bAlternateSetting        : 0x00

bNumEndpoints            : 0x00 (Default Control Pipe only)

bInterfaceClass          : 0x0E (Video)

bInterfaceSubClass       : 0x01 (Video Control)

bInterfaceProtocol       : 0x00

iInterface               : 0x00 (No String Descriptor)

Data (HexDump)           : 09 04 00 00 00 0E 01 00 00                        .........



        ------- Video Control Interface Header Descriptor -----

bLength                  : 0x0D (13 bytes)

bDescriptorType          : 0x24 (Video Control Interface)

bDescriptorSubtype       : 0x01 (Video Control Header)

bcdUVC                   : 0x0110 (UVC Version 1.10)

wTotalLength             : 0x001E (30 bytes)

dwClockFreq              : 0x02DC6C00 (48 MHz)

bInCollection            : 0x01 (1 VideoStreaming interface)

baInterfaceNr[1]         : 0x01 (Interface 1)

Data (HexDump)           : 0D 24 01 10 01 1E 00 00 6C DC 02 01 01            .$......l....



        -------- Video Control Input Terminal Descriptor ------

bLength                  : 0x08 (8 bytes)

bDescriptorType          : 0x24 (Video Control Interface)

bDescriptorSubtype       : 0x02 (Input Terminal)

bTerminalID              : 0x01 (1)

wTerminalType            : 0x0200 (ITT_VENDOR_SPECIFIC)

bAssocTerminal           : 0x00 (Not associated with an Output Terminal)

iTerminal                : 0x00 (No String Descriptor)

Data (HexDump)           : 08 24 02 01 00 02 00 00                           .$......



        ------- Video Control Output Terminal Descriptor ------

bLength                  : 0x09 (9 bytes)

bDescriptorType          : 0x24 (Video Control Interface)

bDescriptorSubtype       : 0x03 (Output Terminal)

bTerminalID              : 0x02 (2)

wTerminalType            : 0x0101 (TT_STREAMING)

bAssocTerminal           : 0x00 (Not associated with an Input Terminal)

bSourceID                : 0x01 (1)

iTerminal                : 0x00 (No String Descriptor)

Data (HexDump)           : 09 24 03 02 01 01 00 01 00                        .$.......



        ---------------- Interface Descriptor -----------------

bLength                  : 0x09 (9 bytes)

bDescriptorType          : 0x04 (Interface Descriptor)

bInterfaceNumber         : 0x01 (Interface 1)

bAlternateSetting        : 0x00

bNumEndpoints            : 0x00 (Default Control Pipe only)

bInterfaceClass          : 0x0E (Video)

bInterfaceSubClass       : 0x02 (Video Streaming)

bInterfaceProtocol       : 0x00

iInterface               : 0x00 (No String Descriptor)

Data (HexDump)           : 09 04 01 00 00 0E 02 00 00                        .........



        ---- VC-Specific VS Video Input Header Descriptor -----

bLength                  : 0x0E (14 bytes)

bDescriptorType          : 0x24 (Video Streaming Interface)

bDescriptorSubtype       : 0x01 (Input Header)

bNumFormats              : 0x01

wTotalLength             : 0x0037 (55 bytes)

bEndpointAddress         : 0x81 (Direction=IN  EndpointID=1)

bmInfo                   : 0x00 (Dynamic Format Change not supported)

bTerminalLink            : 0x02 (Output Terminal ID 2)

bStillCaptureMethod      : 0x00 (No Still Capture)

nbTriggerSupport         : 0x00 (Hardware Triggering not supported)

bTriggerUsage            : 0x00 (Host will initiate still image capture)

bControlSize             : 0x01 (1 bytes each)

Video Payload Format 1   : 0x00

 D0                      : 0   no -  Key Frame Rate

 D1                      : 0   no -  P Frame Rate

 D2                      : 0   no -  Compression Quality

 D3                      : 0   no -  Compression Window Size

 D4                      : 0   no -  Generate Key Frame

 D5                      : 0   no -  Update Frame Segment

 D6                      : 0   no -  Reserved

 D7                      : 0   no -  Reserved

Data (HexDump)           : 0E 24 01 01 37 00 81 00 02 00 00 00 01 00         .$..7.........



        ----- Video Streaming MJPEG Format Type Descriptor ----

bLength                  : 0x0B (11 bytes)

bDescriptorType          : 0x24 (Video Streaming Interface)

bDescriptorSubtype       : 0x06 (Format MJPEG)

bFormatIndex             : 0x01 (1)

bNumFrameDescriptors     : 0x01 (1)

bmFlags                  : 0x01 (Sample size is fixed)

bDefaultFrameIndex       : 0x01 (1)

bAspectRatioX            : 0x00

bAspectRatioY            : 0x00

bmInterlaceFlags         : 0x00

 D0 IL stream or variable: 0 (no)

 D1 Fields per frame     : 0 (2 fields)

 D2 Field 1 first        : 0 (no)

 D3 Reserved             : 0

 D4..5 Field pattern     : 0 (Field 1 only)

 D6..7 Display Mode      : 0 (Bob only)

bCopyProtect             : 0x00 (No restrictions)

*!*ERROR:  no Color Matching Descriptor for this format

Data (HexDump)           : 0B 24 06 01 01 01 01 00 00 00 00                  .$.........



        ----- Video Streaming MJPEG Frame Type Descriptor -----

---> This is the Default (optimum) Frame index

bLength                  : 0x1E (30 bytes)

bDescriptorType          : 0x24 (Video Streaming Interface)

bDescriptorSubtype       : 0x07 (MJPEG Frame Type)

bFrameIndex              : 0x01

bmCapabilities           : 0x02

wWidth                   : 0x0190 (400)

wHeight                  : 0x00F0 (240)

dwMinBitRate             : 0x00EA6000 (15360000 bps -> 1.920 MB/s)

dwMaxBitRate             : 0x00EA6000 (15360000 bps -> 1.920 MB/s)

dwMaxVideoFrameBufferSize: 0x000BB800 (768000 bytes)

dwDefaultFrameInterval   : 0x000F4240 (100.0000 ms -> 10.0000 fps)

bFrameIntervalType       : 0x01 (1 discrete frame interval supported)

adwFrameInterval[1]      : 0x000F4240 (100.0000 ms -> 10.0000 fps)

Data (HexDump)           : 1E 24 07 01 02 90 01 F0 00 00 60 EA 00 00 60 EA   .$........`...`.

                           00 00 B8 0B 00 40 42 0F 00 01 40 42 0F 00         .....@B...@B..



        ---------------- Interface Descriptor -----------------

bLength                  : 0x09 (9 bytes)

bDescriptorType          : 0x04 (Interface Descriptor)

bInterfaceNumber         : 0x01 (Interface 1)

bAlternateSetting        : 0x01

bNumEndpoints            : 0x01 (1 Endpoint)

bInterfaceClass          : 0x0E (Video)

bInterfaceSubClass       : 0x02 (Video Streaming)

bInterfaceProtocol       : 0x00

iInterface               : 0x00 (No String Descriptor)

Data (HexDump)           : 09 04 01 01 01 0E 02 00 00                        .........



        ----------------- Endpoint Descriptor -----------------

bLength                  : 0x07 (7 bytes)

bDescriptorType          : 0x05 (Endpoint Descriptor)

bEndpointAddress         : 0x81 (Direction=IN EndpointID=1)

bmAttributes             : 0x05 (TransferType=Isochronous  SyncType=Asynchronous  EndpointType=Data)

wMaxPacketSize           : 0x0100 (256 bytes)

bInterval                : 0x01 (1 ms)

Data (HexDump)           : 07 05 81 05 00 01 01                              .......



    ----------------- Device Qualifier Descriptor -----------------

Error                    : ERROR_GEN_FAILURE  (because the device is Full-Speed only)



      -------------------- String Descriptors -------------------

             ------ String Descriptor 0 ------

bLength                  : 0x04 (4 bytes)

bDescriptorType          : 0x03 (String Descriptor)

Language ID[0]           : 0x0409 (English - United States)

Data (HexDump)           : 04 03 09 04                                       ....

             ------ String Descriptor 1 ------

bLength                  : 0x14 (20 bytes)

bDescriptorType          : 0x03 (String Descriptor)

Language 0x0409          : "MyCompany"

Data (HexDump)           : 14 03 4D 00 79 00 43 00 6F 00 6D 00 70 00 61 00   ..M.y.C.o.m.p.a.

                           6E 00 79 00                                       n.y.

             ------ String Descriptor 2 ------

bLength                  : 0x14 (20 bytes)

bDescriptorType          : 0x03 (String Descriptor)

Language 0x0409          : "UVCCamera"

Data (HexDump)           : 14 03 55 00 56 00 43 00 43 00 61 00 6D 00 65 00   ..U.V.C.C.a.m.e.

                           72 00 61 00                                       r.a.

             ------ String Descriptor 3 ------

bLength                  : 0x1A (26 bytes)

bDescriptorType          : 0x03 (String Descriptor)

Language 0x0409          : "FFFFFFFEFFFF"

Data (HexDump)           : 1A 03 46 00 46 00 46 00 46 00 46 00 46 00 46 00   ..F.F.F.F.F.F.F.

                           45 00 46 00 46 00 46 00 46 00                     E.F.F.F.F.

             ------ String Descriptor 4 ------

bLength                  : 0x16 (22 bytes)

bDescriptorType          : 0x03 (String Descriptor)

Language 0x0409          : "UVC Config"

Data (HexDump)           : 16 03 55 00 56 00 43 00 20 00 43 00 6F 00 6E 00   ..U.V.C. .C.o.n.

                           66 00 69 00 67 00                                 f.i.g.

             ------ String Descriptor 5 ------

bLength                  : 0x1C (28 bytes)

bDescriptorType          : 0x03 (String Descriptor)

Language 0x0409          : "UVC Interface"

Data (HexDump)           : 1C 03 55 00 56 00 43 00 20 00 49 00 6E 00 74 00   ..U.V.C. .I.n.t.

                           65 00 72 00 66 00 61 00 63 00 65 00               e.r.f.a.c.e.

总结

以上实现了UVC设备的枚举与打开关闭,已经完成了一半,后面加上图像数据的发送即可。

此帖出自stm32/stm8论坛
点赞 关注
 

回复
举报
您需要登录后才可以回帖 登录 | 注册

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/8 下一条

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表