Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uvc摄像头例子通讯报错 (AEGHB-844) #157

Closed
Gornerrrrr opened this issue Jan 10, 2022 · 16 comments
Closed

uvc摄像头例子通讯报错 (AEGHB-844) #157

Gornerrrrr opened this issue Jan 10, 2022 · 16 comments

Comments

@Gornerrrrr
Copy link

开发板:esp32s2-Saola-v1.2
开发环境:win10 + IDFv4.4 + esp iot solution
摄像头:USB2.0 uvc免驱支持MJPEG摄像头

我根据摄像头描述符配置了usb_camera_wifi_transfer例程的参数后烧写测试,发现在通讯之后报错“SWAP NO EOF ”。

运行log

I (816) UVC_STREAM: UVC Streaming Config Succeed
I (866) UVC_STREAM: UVC Streaming Starting
I (896) UVC_STREAM: Port=1 init succeed
I (896) UVC_STREAM: Waitting USB Connection
I (1146) UVC_STREAM: line 353 HCD_PORT_EVENT_CONNECTION
I (1146) UVC_STREAM: Resetting Port
I (1206) UVC_STREAM: Setting Port FIFO
I (1206) UVC_STREAM: Getting Port Speed
I (1206) UVC_STREAM: Port speed = 1
I (1206) UVC_STREAM: USB Speed: full-speed
I (1206) UVC_STREAM: Set Device Addr = 1
I (1226) UVC_STREAM: Set Device Addr Done
I (1226) UVC_STREAM: Set Device Configuration = 1
I (1236) UVC_STREAM: Set Device Configuration Done
I (1236) UVC_STREAM: SET_CUR Probe
I (1236) UVC_STREAM: SET_CUR Probe Done
I (1236) UVC_STREAM: GET_CUR Probe
bmHint: 0001
bFormatIndex: 2
bFrameIndex: 5
dwFrameInterval: 10000000
wKeyFrameRate: 0
wPFrameRate: 0
wCompQuality: 0
wCompWindowSize: 0
wDelay: 0
dwMaxVideoFrameSize: 614400
dwMaxPayloadTransferSize: 800
dwClockFrequency: 0
bmFramingInfo: 0
bPreferredVersion: 0
bMinVersion: 0
bMaxVersion: 0
bInterfaceNumber: 0
I (1276) UVC_STREAM: GET_CUR Probe Done, actual_num_bytes:64
I (1276) UVC_STREAM: SET_CUR COMMIT
I (1286) UVC_STREAM: SET_CUR COMMIT Done
I (1286) UVC_STREAM: Set Device Interface = 1, Alt = 4
I (1296) UVC_STREAM: Set Device Interface Done
I (1296) UVC_STREAM: Sample processing task started
I (1356) UVC_STREAM: Camera Start Streaming
W (5346) UVC_STREAM: SWAP NO EOF 9412
W (5846) UVC_STREAM: SWAP NO EOF 9536
W (6336) UVC_STREAM: SWAP NO EOF 9656

我的配置:

    uvc_config_t uvc_config = {
        .dev_speed = USB_SPEED_FULL, //固定为 USB_SPEED_FULL
        .configuration = 1, //配置描述符编号,一般为 1
        .format_index = 2, // MJPEG 对应的 bFormatIndex, bFormatIndex: 0x02 (2)
        .frame_width = 160, // MJPEG 横向像素,例如 320
        .frame_height = 120, // MJPEG 纵向像素,例如 240
        .frame_index = 5, //MJPEG 320*240 对应的 bFrameIndex, bFrameIndex: 0x05
        .frame_interval = 333333, //可选的帧率 dwFrameInterval,例如 30fps
        .interface = 1, // 可选的视频流接口 bInterfaceNumber,一般为 1
        .interface_alt = 4, // 接口选项 bAlternateSetting, bAlternateSetting: 0x04
        .isoc_ep_addr = 0x82, // 接口选项对应的 bEndpointAddress, bEndpointAddresS: 0x82 (Direction=IN EndpointID=2)
        .isoc_ep_mps = 512, // 接口选项的确定的 MPS, 例如为 512
        .xfer_buffer_size = 20*1024, //单帧图像大小,需要根据实际测试确定,320*240 一般小于 35KB
        .xfer_buffer_a = pointer_buffer_a, // 已经申请的 buffer 指针
        .xfer_buffer_b = pointer_buffer_b, // 已经申请的 buffer 指针
        .frame_buffer_size = 20*1024, //单帧图像大小,需要根据实际测试确定
        .frame_buffer = pointer_frame_buffer, // 已经申请的 buffer 指针
    };

摄像头描述符,我是用win10的软件获取的,比较多
摄像头描述符.txt

请问可能是什么问题导致的?uvc协议还在学习中不是很明白,是描述符配置的不对还是摄像头本身就不支持?或者说例程需要改动?

@leeebo
Copy link
Collaborator

leeebo commented Jan 12, 2022

The root reason for this problem is that the camera has a different configuration descriptor in USB Fullspeed mode than in Highspeed mode. While the configuration descriptor obtained by the PC is Highspeed mode, with this configuration, the camera may not work on the ESP chip.

To get the camera's Fullspeed descriptor, there are two ways:

  1. Use a USB Fullspeed isolator to obtain from PC
  2. Run ESP-IDF host example to obtain from ESP chips

More convenient methods will be added later

Same problem: #146 #152 #156

@kidboygmail
Copy link

The root reason for this problem is that the camera has a different configuration descriptor in USB Fullspeed mode than in Highspeed mode. While the configuration descriptor obtained by the PC is Highspeed mode, with this configuration, the camera may not work on the ESP chip.

To get the camera's Fullspeed descriptor, there are two ways:

  1. Use a USB Fullspeed isolator to obtain from PC
  2. Run ESP-IDF host example to obtain from ESP chips

More convenient methods will be added later

Same problem: #146 #152 #156

I ran the 2nd way of ESP-IDF host example, in the attached file still shows USB2.0.
Also how could we find the FrameIndex and FormatIndex information? Thank you!
ESP32_USB_Descriptor.txt

zhanzhaocheng pushed a commit that referenced this issue Mar 7, 2022
@leeebo
Copy link
Collaborator

leeebo commented Mar 7, 2022

Hi, from the ESP32_USB_Descriptor.txt, the camera could be supported because there is a MPS 512 interface

the latest commits of uvc_stream can help print the camera class's descriptors, please try to find the MJPEG format index and frame index, modify your code based on that.

IDF should also be updated to the latest release/v4.4, these new commits must be included

@Gornerrrrr
Copy link
Author

Gornerrrrr commented Mar 22, 2022

Hi, from the ESP32_USB_Descriptor.txt, the camera could be supported because there is a MPS 512 interface

the latest commits of uvc_stream can help print the camera class's descriptors, please try to find the MJPEG format index and frame index, modify your code based on that.

IDF should also be updated to the latest release/v4.4, these new commits must be included

Thanks your suggest! I updated to latest release/v4.4 and run usb_camera_wifi_transfer example(remove wifi and http). And then get HCD_PIPE_EVENT_ERROR_OVERFLOW warning:(
Run log:

PS S:\Work\ESP\esp-iot-solution\examples\usb\host\usb_camera_wifi_transfer> idf.py monitor
Executing action: monitor
Serial port COM9
Connecting....
Detecting chip type... Unsupported detection protocol, switching and trying again...
Detecting chip type... ESP32-S2
Running idf_monitor in directory s:\work\esp\esp-iot-solution\examples\usb\host\usb_camera_wifi_transfer
Executing "S:\Work\ESP\TOOLS\python_env\idf4.4_py3.8_env\Scripts\python.exe S:\Work\ESP\IDF4.4\tools/idf_monitor.py -p COM9 -b 115200 --toolchain-prefix xtensa-esp32s2-elf- --target esp32s2 s:\work\esp\esp-iot-solution\examples\usb\host\usb_camera_wifi_transfer\build\uvc_mjpeg_wifi.elf -m 'S:\Work\ESP\TOOLS\python_env\idf4.4_py3.8_env\Scripts\python.exe' 'S:\Work\ESP\IDF4.4\tools\idf.py'"...
�[0;33m--- WARNING: GDB cannot open serial ports accessed as COMx�[0m
�[0;33m--- Using \\.\COM9 instead...�[0m
�[0;33m--- idf_monitor on \\.\COM9 115200 ---�[0m
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
ESP-ROM:esp32s2-rc4-20191025
Build:Oct 25 2019
rst:0x1 (POWERON),boot:0x8 (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:1
load:0x3ffe6100,len:0x177c
load:0x4004c000,len:0xa48
load:0x40050000,len:0x2e58
entry 0x4004c204
I (21) boot: ESP-IDF v4.4-367-gc29343eb94-dirty 2nd stage bootloader
I (21) boot: compile time 09:10:59
I (21) boot: chip revision: 0
I (26) boot.esp32s2: SPI Speed      : 80MHz
I (30) boot.esp32s2: SPI Mode       : DIO
I (35) boot.esp32s2: SPI Flash Size : 2MB
I (40) boot: Enabling RNG early entropy source...
I (45) boot: Partition Table:
I (49) boot: ## Label            Usage          Type ST Offset   Length
I (56) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (64) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (71) boot:  2 factory          factory app      00 00 00010000 00100000
I (78) boot: End of partition table
I (83) esp_image: segment 0: paddr=00010020 vaddr=3f000020 size=0abd4h ( 43988) map
I (100) esp_image: segment 1: paddr=0001abfc vaddr=3ffbf2f0 size=01d44h (  7492) load
I (102) esp_image: segment 2: paddr=0001c948 vaddr=40024000 size=036d0h ( 14032) load
I (111) esp_image: segment 3: paddr=00020020 vaddr=40080020 size=18a38h (100920) map
I (137) esp_image: segment 4: paddr=00038a60 vaddr=400276d0 size=07c14h ( 31764) load
I (145) esp_image: segment 5: paddr=0004067c vaddr=50000000 size=00010h (    16) load
I (150) boot: Loaded app from partition at offset 0x10000
I (151) boot: Disabling RNG early entropy source...
I (165) cache: Instruction cache        : size 8KB, 4Ways, cache line size 32Byte
I (165) cache: Data cache               : size 8KB, 4Ways, cache line size 32Byte
I (169) spiram: Found 16MBit SPI RAM device
I (174) spiram: SPI RAM mode: sram 40m
I (178) spiram: PSRAM initialized, cache is in normal (1-core) mode.
I (185) cpu_start: Pro cpu up.
I (599) spi�ff������f���I�5�memory test OK
D (599) efuse: In EFUSE_BLK2__DATA4_REG is used 3 bits starting with 4 bit
D (608) clk: RTC_SLOW_CLK calibration value: 5702702
I (616) cpu_start: Pro cpu start user code
I (616) cpu_start: cpu freq: 240000000
I (616) cpu_start: Application information:
I (621) cpu_start: Project name:     uvc_mjpeg_wifi
I (626) cpu_start: App version:      14d9f9b-dirty
I (632) cpu_start: Compile time:     Mar 22 2022 14:22:25
I (638) cpu_start: ELF file SHA256:  62cd7214c6e5c367...
I (644) cpu_start: ESP-IDF:          v4.4-367-gc29343eb94-dirty
D (650) memory_layout: Checking 5 reserved memory ranges:
D (656) memory_layout: Reserved memory range 0x3f500000 - 0x3ff80000
D (662) memory_layout: Reserved memory range 0x3ff9e000 - 0x3ff9e000
D (669) memory_layout: Reserved memory range 0x3ffb4000 - 0x3ffbf2e4
D (675) memory_layout: Reserved memory range 0x3ffbf2f0 - 0x3ffc1958
D (682) memory_layout: Reserved memory range 0x3ffffa10 - 0x40000000
D (688) memory_layout: Building list of available memory regions:
D (694) memory_layout: Available memory region 0x3ffc1958 - 0x3ffc4000
D (701) memory_layout: Available memory region 0x3ffc4000 - 0x3ffc8000
D (707) memory_layout: Available memory region 0x3ffc8000 - 0x3ffcc000
D (714) memory_layout: Available memory region 0x3ffcc000 - 0x3ffd0000
D (721) memory_layout: Available memory region 0x3ffd0000 - 0x3ffd4000
D (727) memory_layout: Available memory region 0x3ffd4000 - 0x3ffd8000
D (734) memory_layout: Available memory region 0x3ffd8000 - 0x3ffdc000
D (740) memory_layout: Available memory region 0x3ffdc000 - 0x3ffe0000
D (747) memory_layout: Available memory region 0x3ffe0000 - 0x3ffe4000
D (754) memory_layout: Available memory region 0x3ffe4000 - 0x3ffe8000
D (760) memory_layout: Available memory region 0x3ffe8000 - 0x3ffec000
D (767) memory_layout: Available memory region 0x3ffec000 - 0x3fff0000
D (773) memory_layout: Available memory region 0x3fff0000 - 0x3fff4000
D (780) memory_layout: Available memory region 0x3fff4000 - 0x3fff8000
D (787) memory_layout: Available memory region 0x3fff8000 - 0x3fffc000
D (793) memory_layout: Available memory region 0x3fffc000 - 0x3ffffa10
D (800) memory_layout: Available memory region 0x3ff9e000 - 0x3ffa0000
I (806) heap_init: Initializing. RAM available for dynamic allocation:
D (814) heap_init: New heap initialised at 0x3ffc1958
I (819) heap_init: At 3FFC1958 len 0003A6A8 (233 KiB): DRAM
I (825) heap_init: At 3FFFC000 len 00003A10 (14 KiB): DRAM
D (831) heap_init: New heap initialised at 0x3ff9e000
I (836) heap_init: At 3FF9E000 len 00002000 (8 KiB): RTCRAM
I (843) spiram: Adding pool of 2048K of external SPI memory to heap allocator
D (851) FLASH_HAL: extra_dummy: 0
D (854) spi_flash: trying chip: issi
D (857) spi_flash: trying chip: gd
D (861) spi_flash: trying chip: mxic
D (865) spi_flash: trying chip: winbond
D (868) spi_flash: trying chip: boya
D (872) spi_flash: trying chip: th
D (876) spi_flash: trying chip: generic
I (879) spi_flash: detected chip: generic
I (884) spi_flash: flash io: dio
W (888) spi_flash: Detected size(4096k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
D (901) cpu_start: calling init function: 0x40081388
0x40081388: esp_ota_init_app_elf_sha256 at S:/Work/ESP/IDF4.4/components/app_update/esp_app_desc.c:68

D (906) intr_alloc: Connected src 73 to int 10 (cpu 0)
D (911) intr_alloc: Connected src 28 to int 2 (cpu 0)
I (916) cpu_start: Starting scheduler on PRO CPU.
D (922) heap_init: New heap initialised at 0x3fffc000
I (927) spiram: Reserving pool of 32K of internal memory for DMA/internal allocations
D (935) intr_alloc: Connected src 17 to int 3 (cpu 0)
I (940) UVC_STREAM: UVC Streaming Config Succeed
D (946) UVC_STREAM: urb alloced
D (949) UVC_STREAM: urb alloced
D (952) UVC_STREAM: urb alloced
D (955) UVC_STREAM: urb alloced
D (1008) intr_alloc: Connected src 48 to int 19 (cpu 0)
I (1008) UVC_STREAM: UVC Streaming Starting
I (1008) uvc_demo: uvc streaming successed!
I (1038) UVC_STREAM: Port=1 init succeed
I (1038) UVC_STREAM: Waitting USB Connection
I (1288) UVC_STREAM: line 358 HCD_PORT_EVENT_CONNECTION
I (1288) UVC_STREAM: Resetting Port
I (1348) UVC_STREAM: Setting Port FIFO
I (1348) UVC_STREAM: Getting Port Speed
I (1348) UVC_STREAM: Port speed = 1
I (1350) UVC_STREAM: USB Speed: full-speed
D (1355) UVC_STREAM: urb alloced
I (1358) UVC_STREAM: Set Device Addr = 1
D (1373) UVC_STREAM: Got expected pipe_handle and event
I (1373) UVC_STREAM: Set Device Addr Done
D (1373) UVC_STREAM: urb free
D (1375) UVC_STREAM: urb alloced
I (1379) UVC_STREAM: get short config desc
D (1391) UVC_STREAM: Got expected pipe_handle and event
I (1391) UVC_STREAM: get config desc, actual_num_bytes:16
I (1395) UVC_STREAM: get full config desc
D (1421) UVC_STREAM: Got expected pipe_handle and event
I (1421) UVC_STREAM: get full config desc, actual_num_bytes:459
*** Configuration descriptor ***
bLength 9
bDescriptorType 2
wTotalLength 451
bNumInterfaces 2
bConfigurationValue 1
iConfiguration 0
bmAttributes 0x80
bMaxPower 500mA
        *** Interface descriptor ***
        bLength 9
        bDescriptorType 4
        bInterfaceNumber 0
        bAlternateSetting 0
        bNumEndpoints 1
        bInterfaceClass 0x0
        iInterface 4
        bcdUVC 100
        *** Extension Unit Descriptor unsupported, skipping... ***
                *** Endpoint descriptor ***
                bLength 7
                bDescriptorType 5
                bEndpointAddress 0x81   EP 1 IN
                bmAttributes 0x3        INT
                wMaxPacketSize 16
                bInterval 8
        *** Interface descriptor ***
        bLength 9
        bDescriptorType 4
        bInterfaceNumber 1
        bAlternateSetting 0
        bNumEndpoints 0
        bInterfaceClass 0x0
        iInterface 4
        *** Class-specific VS Interface Descriptor ***
        bNumFormats 2
        *** VS Format MJPEG Descriptor ***
        bFormatIndex 0x1
        bDefaultFrameIndex 1
        *** VS MJPEG Frame Descriptor ***
        bFrameIndex 0x1
        wWidth 320
        wHeigh 240
        dwMaxVideoFrameBufSize 230400
        FrameInterval[0] 500000
        *** VS MJPEG Frame Descriptor ***
        bFrameIndex 0x2
        wWidth 176
        wHeigh 144
        dwMaxVideoFrameBufSize 76032
        FrameInterval[0] 500000
        *** VS MJPEG Frame Descriptor ***
        bFrameIndex 0x3
        wWidth 160
        wHeigh 120
        dwMaxVideoFrameBufSize 57600
        FrameInterval[0] 500000
        *** Interface descriptor ***
        bLength 9
        bDescriptorType 4
        bInterfaceNumber 1
        bAlternateSetting 1
        bNumEndpoints 1
        bInterfaceClass 0x0
        iInterface 4
                *** Endpoint descriptor ***
                bLength 7
                bDescriptorType 5
                bEndpointAddress 0x82   EP 2 IN
                bmAttributes 0x5        ISOC
                wMaxPacketSize 800
                bInterval 1
        *** Interface descriptor ***
        bLength 9
        bDescriptorType 4
        bInterfaceNumber 1
        bAlternateSetting 2
        bNumEndpoints 1
        bInterfaceClass 0x0
        iInterface 4
                *** Endpoint descriptor ***
                bLength 7
                bDescriptorType 5
                bEndpointAddress 0x82   EP 2 IN
                bmAttributes 0x5        ISOC
                wMaxPacketSize 700
                bInterval 1
        *** Interface descriptor ***
        bLength 9
        bDescriptorType 4
        bInterfaceNumber 1
        bAlternateSetting 3
        bNumEndpoints 1
        bInterfaceClass 0x0
        iInterface 4
                *** Endpoint descriptor ***
                bLength 7
                bDescriptorType 5
                bEndpointAddress 0x82   EP 2 IN
                bmAttributes 0x5        ISOC
                wMaxPacketSize 512
                bInterval 1
        *** Interface descriptor ***
        bLength 9
        bDescriptorType 4
        bInterfaceNumber 1
        bAlternateSetting 4
        bNumEndpoints 1
        bInterfaceClass 0x0
        iInterface 4
                *** Endpoint descriptor ***
                bLength 7
                bDescriptorType 5
                bEndpointAddress 0x82   EP 2 IN
                bmAttributes 0x5        ISOC
                wMaxPacketSize 192
                bInterval 1
D (1645) UVC_STREAM: urb free
D (1648) UVC_STREAM: urb alloced
I (1651) UVC_STREAM: Set Device Configuration = 1
D (1657) UVC_STREAM: Got expected pipe_handle and event
I (1662) UVC_STREAM: Set Device Configuration Done
D (1667) UVC_STREAM: urb free
D (1670) UVC_STREAM: urb alloced
I (1674) UVC_STREAM: SET_CUR Probe
D (1679) UVC_STREAM: Got expected pipe_handle and event
I (1683) UVC_STREAM: SET_CUR Probe Done
I (1688) UVC_STREAM: GET_CUR Probe
D (1693) UVC_STREAM: Got expected pipe_handle and event
bmHint: 0001
bFormatIndex: 1
bFrameIndex: 3
dwFrameInterval: 500000
wKeyFrameRate: 0
wPFrameRate: 0
wCompQuality: 0
wCompWindowSize: 0
wDelay: 0
dwMaxVideoFrameSize: 57600
dwMaxPayloadTransferSize: 800
dwClockFrequency: 0
bmFramingInfo: 0
bPreferredVersion: 0
bMinVersion: 0
bMaxVersion: 0
bInterfaceNumber: 0
I (1725) UVC_STREAM: GET_CUR Probe Done, actual_num_bytes:34
I (1732) UVC_STREAM: SET_CUR COMMIT
D (1737) UVC_STREAM: Got expected pipe_handle and event
I (1741) UVC_STREAM: SET_CUR COMMIT Done
D (1746) UVC_STREAM: urb free
D (1749) UVC_STREAM: urb alloced
I (1752) UVC_STREAM: Set Device Interface = 1, Alt = 4
D (1758) UVC_STREAM: Got expected pipe_handle and event
I (1763) UVC_STREAM: Set Device Interface Done
D (1768) UVC_STREAM: urb free
I (1771) UVC_STREAM: Sample processing task started
I (1827) UVC_STREAM: Camera Start Streaming
D (1827) UVC_STREAM: urb context update
D (1827) UVC_STREAM: urb context update
D (1828) UVC_STREAM: urb context update
D (1832) UVC_STREAM: urb context update
W (2622) UVC_STREAM: line 677 Pipe: iso HCD_PIPE_EVENT_ERROR_OVERFLOW

my uvc_config:

#define DESCRIPTOR_CONFIGURATION_INDEX 0x01
#define DESCRIPTOR_FORMAT_MJPEG_INDEX  0x01
#define DEMO_FRAME_INDEX 0x03
#define DEMO_FRAME_WIDTH 160
#define DEMO_FRAME_HEIGHT 120
#define DEMO_FRAME_INTERVAL 500000
#define DEMO_XFER_BUFFER_SIZE (20 * 1024) 
#define DESCRIPTOR_STREAM_INTERFACE_INDEX   0x01
#define DESCRIPTOR_STREAM_ISOC_ENDPOINT_ADDR  0x82
#define DEMO_ISOC_INTERFACE_ALT 0x04
#define DEMO_ISOC_EP_MPS 192

The HCD_PIPE_EVENT_ERROR_OVERFLOW warning because of MPS >= 512?
I noticed MPS≠512 in log(dwMaxPayloadTransferSize: 800). But Alt=4 MPS=192 in interface descriptor.
How to set MPS?
And I cant get frame_callback after start stream.

@Gornerrrrr
Copy link
Author

Gornerrrrr commented Mar 24, 2022

I'm trying to set it like this

#elif CONFIG_SIZE_160_120
#define DESCRIPTOR_CONFIGURATION_INDEX 0x01
#define DESCRIPTOR_FORMAT_MJPEG_INDEX  0x01
#define DEMO_FRAME_INDEX 0x03
#define DEMO_FRAME_WIDTH 160
#define DEMO_FRAME_HEIGHT 120
#define DEMO_FRAME_INTERVAL 500000
#define DEMO_XFER_BUFFER_SIZE (20 * 1024) //Double buffer
#define DESCRIPTOR_STREAM_INTERFACE_INDEX   0x01
#define DESCRIPTOR_STREAM_ISOC_ENDPOINT_ADDR  0x82
#define DEMO_ISOC_INTERFACE_ALT 0x04
#define DEMO_ISOC_EP_MPS 512
#elif CONFIG_SIZE_320_240
#define DESCRIPTOR_CONFIGURATION_INDEX 0x01
#define DESCRIPTOR_FORMAT_MJPEG_INDEX  0x01
#define DEMO_FRAME_INDEX 0x01
#define DEMO_FRAME_WIDTH 320
#define DEMO_FRAME_HEIGHT 240
#define DEMO_FRAME_INTERVAL 400000
#define DEMO_XFER_BUFFER_SIZE (30 * 1024) //Double buffer
#define DESCRIPTOR_STREAM_INTERFACE_INDEX   0x01
#define DESCRIPTOR_STREAM_ISOC_ENDPOINT_ADDR  0x82
#define DEMO_ISOC_INTERFACE_ALT 0x04
#define DEMO_ISOC_EP_MPS 512

It's can be working.
But GET_CUR Probe MPS=800 too.

@leeebo
Copy link
Collaborator

leeebo commented Mar 24, 2022

@Gornerrrrr I think MPS=512 corresponding DEMO_ISOC_INTERFACE_ALT should be 3 from your log

UVC negotiate process will give a suggested MPS result, your camera seems prefer MPS=800 interface, but it's no problem if you can set interface Alt to 512 without a pipe stall response, after that your camera will prepare 512-Bytes packets for the host to fetch.

image

@Gornerrrrr
Copy link
Author

@Gornerrrrr I think MPS=512 corresponding DEMO_ISOC_INTERFACE_ALT should be 3 from your log

UVC negotiate process will give a suggested MPS result, your camera seems prefer MPS=800 interface, but it's no problem if you can set interface Alt to 512 without a pipe stall response, after that your camera will prepare 512-Bytes packets for the host to fetch.

image

Thanks your help!
I've tried ALT=3 MPS=512, get HCD_PIPE_EVENT_ERROR_OVERFLOW;
ALT=4 MPS=192, get HCD_PIPE_EVENT_ERROR_OVERFLOW too;
ALT=4 MPS=512, it's woking:)
So it's no problem without a pipe stall response,

@leeebo
Copy link
Collaborator

leeebo commented Mar 24, 2022

@Gornerrrrr You can dig deeper into the issue, if you set ALT=4 while the camera transfer packets (please change the log level to print the received packet size) with MPS=512 not 192, It just means there's a mistake in the device's descriptor.

@Gornerrrrr
Copy link
Author

@Gornerrrrr You can dig deeper into the issue, if you set ALT=4 while the camera transfer packets (please change the log level to print the received packet size) with MPS=512 not 192, It just means there's a mistake in the device's descriptor.

when ALT=4 log

I (4010) UVC_STREAM: Camera Start Streaming
D (4010) UVC_STREAM: urb context update
D (4010) UVC_STREAM: urb context update
D (4011) UVC_STREAM: urb context update
D (4015) UVC_STREAM: urb context update
D (4107) uvc_demo: callback! frame_format = 7, seq = 1, width = 320, height = 240, length = 6716, ptr = 0
I (4107) uvc_demo: send frame = 1
I (5110) uvc_demo: send frame done = 1
D (5111) uvc_demo: callback! frame_format = 7, seq = 21, width = 320, height = 240, length = 6772, ptr = 0
I (5113) uvc_demo: send frame = 21
I (6117) uvc_demo: send frame done = 21
D (6118) uvc_demo: callback! frame_format = 7, seq = 41, width = 320, height = 240, length = 5724, ptr = 0
I (6120) uvc_demo: send frame = 41
I (7124) uvc_demo: send frame done = 41
D (7125) uvc_demo: callback! frame_format = 7, seq = 61, width = 320, height = 240, length = 6772, ptr = 0
I (7127) uvc_demo: send frame = 61
I (8131) uvc_demo: send frame done = 61
D (8133) uvc_demo: callback! frame_format = 7, seq = 81, width = 320, height = 240, length = 6812, ptr = 0
I (8134) uvc_demo: send frame = 81
I (9138) uvc_demo: send frame done = 81
D (9139) uvc_demo: callback! frame_format = 7, seq = 101, width = 320, height = 240, length = 6560, ptr = 0

And I tryed get descriptor in windows PC.

        ---------------- Interface Descriptor -----------------
bLength                  : 0x09 (9 bytes)
bDescriptorType          : 0x04 (Interface Descriptor)
bInterfaceNumber         : 0x01
bAlternateSetting        : 0x01
bNumEndpoints            : 0x01 (1 Endpoint)
bInterfaceClass          : 0x0E (Video)
bInterfaceSubClass       : 0x02 (Video Streaming)
bInterfaceProtocol       : 0x00
iInterface               : 0x04 (String Descriptor 4)
 Language 0x0409         : "USB 2.0 Camera"
Data (HexDump)           : 09 04 01 01 01 0E 02 00 04                        .........

        ----------------- Endpoint Descriptor -----------------
bLength                  : 0x07 (7 bytes)
bDescriptorType          : 0x05 (Endpoint Descriptor)
bEndpointAddress         : 0x82 (Direction=IN EndpointID=2)
bmAttributes             : 0x05 (TransferType=Isochronous  SyncType=Asynchronous  EndpointType=Data)
wMaxPacketSize           : 0x1400
 Bits 15..13             : 0x00 (reserved, must be zero)
 Bits 12..11             : 0x02 (2 additional transactions per microframe -> allows 683..1024 bytes per packet)
 Bits 10..0              : 0x400 (1024 bytes per packet)
bInterval                : 0x01 (1 ms)
Data (HexDump)           : 07 05 82 05 00 14 01                              .......

        ---------------- Interface Descriptor -----------------
bLength                  : 0x09 (9 bytes)
bDescriptorType          : 0x04 (Interface Descriptor)
bInterfaceNumber         : 0x01
bAlternateSetting        : 0x02
bNumEndpoints            : 0x01 (1 Endpoint)
bInterfaceClass          : 0x0E (Video)
bInterfaceSubClass       : 0x02 (Video Streaming)
bInterfaceProtocol       : 0x00
iInterface               : 0x04 (String Descriptor 4)
 Language 0x0409         : "USB 2.0 Camera"
Data (HexDump)           : 09 04 01 02 01 0E 02 00 04                        .........

        ----------------- Endpoint Descriptor -----------------
bLength                  : 0x07 (7 bytes)
bDescriptorType          : 0x05 (Endpoint Descriptor)
bEndpointAddress         : 0x82 (Direction=IN EndpointID=2)
bmAttributes             : 0x05 (TransferType=Isochronous  SyncType=Asynchronous  EndpointType=Data)
wMaxPacketSize           : 0x0C00
 Bits 15..13             : 0x00 (reserved, must be zero)
 Bits 12..11             : 0x01 (1 additional transactions per microframe -> allows 513..1024 byte per packet)
 Bits 10..0              : 0x400 (1024 bytes per packet)
bInterval                : 0x01 (1 ms)
Data (HexDump)           : 07 05 82 05 00 0C 01                              .......

        ---------------- Interface Descriptor -----------------
bLength                  : 0x09 (9 bytes)
bDescriptorType          : 0x04 (Interface Descriptor)
bInterfaceNumber         : 0x01
bAlternateSetting        : 0x03
bNumEndpoints            : 0x01 (1 Endpoint)
bInterfaceClass          : 0x0E (Video)
bInterfaceSubClass       : 0x02 (Video Streaming)
bInterfaceProtocol       : 0x00
iInterface               : 0x04 (String Descriptor 4)
 Language 0x0409         : "USB 2.0 Camera"
Data (HexDump)           : 09 04 01 03 01 0E 02 00 04                        .........

        ----------------- Endpoint Descriptor -----------------
bLength                  : 0x07 (7 bytes)
bDescriptorType          : 0x05 (Endpoint Descriptor)
bEndpointAddress         : 0x82 (Direction=IN EndpointID=2)
bmAttributes             : 0x05 (TransferType=Isochronous  SyncType=Asynchronous  EndpointType=Data)
wMaxPacketSize           : 0x0400
 Bits 15..13             : 0x00 (reserved, must be zero)
 Bits 12..11             : 0x00 (0 additional transactions per microframe -> allows 1..1024 bytes per packet)
 Bits 10..0              : 0x400 (1024 bytes per packet)
bInterval                : 0x01 (1 ms)
Data (HexDump)           : 07 05 82 05 00 04 01                              .......

        ---------------- Interface Descriptor -----------------
bLength                  : 0x09 (9 bytes)
bDescriptorType          : 0x04 (Interface Descriptor)
bInterfaceNumber         : 0x01
bAlternateSetting        : 0x04
bNumEndpoints            : 0x01 (1 Endpoint)
bInterfaceClass          : 0x0E (Video)
bInterfaceSubClass       : 0x02 (Video Streaming)
bInterfaceProtocol       : 0x00
iInterface               : 0x04 (String Descriptor 4)
 Language 0x0409         : "USB 2.0 Camera"
Data (HexDump)           : 09 04 01 04 01 0E 02 00 04                        .........

        ----------------- Endpoint Descriptor -----------------
bLength                  : 0x07 (7 bytes)
bDescriptorType          : 0x05 (Endpoint Descriptor)
bEndpointAddress         : 0x82 (Direction=IN EndpointID=2)
bmAttributes             : 0x05 (TransferType=Isochronous  SyncType=Asynchronous  EndpointType=Data)
wMaxPacketSize           : 0x0200
 Bits 15..13             : 0x00 (reserved, must be zero)
 Bits 12..11             : 0x00 (0 additional transactions per microframe -> allows 1..1024 bytes per packet)
 Bits 10..0              : 0x200 (512 bytes per packet)
bInterval                : 0x01 (1 ms)
Data (HexDump)           : 07 05 82 05 00 02 01    

ALT=4 MPS=512
It's diffrent, because of HS in PC?

@heculess
Copy link

@Gornerrrrr 你用的摄像头在哪买的?我买了几个类型,idf得到的MJPEG Frame Descriptor都是只有一个,而且只有160*120

@Gornerrrrr
Copy link
Author

@Gornerrrrr 你用的摄像头在哪买的?我买了几个类型,idf得到的MJPEG Frame Descriptor都是只有一个,而且只有160*120

淘宝搜阿香科技买的

@miaohaiwei
Copy link

@Gornerrrrr 你用的摄像头在哪买的?我买了几个类型,idf得到的MJPEG Frame Descriptor都是只有一个,而且只有160*120

淘宝搜阿香科技买的

方便问下这个摄像头型号么,我买的在fullspeed模式下仅支持非常小的分辨率。

@xxzling
Copy link

xxzling commented Sep 25, 2022

我使用ESP32S3尝试了4款USB摄像头,提示E (1856) UVC_STREAM: Configuration descriptor larger than control transfer max length 都不支持设置接口为 wMaxPacketSize 为 512,最小都是800,请问能给出一个可用的UVC usb摄像头的购买链接或者是型号吗?,感谢

@leeebo
Copy link
Collaborator

leeebo commented Sep 26, 2022

Some isochronous mode cameras support multiple interface alternatives, to support different data rates. You can try to run the example to find the bAlternateSetting with 512 or lower MPS, If not the camera may not be supported. (Due to the ESP32S2/S3 USB hardware FIFO restriction, the wMaxPacketSize can not be larger than 512 Bytes)

But for camera vendors, it should be easy to add a 512 Bytes interface.

BTW. Bulk mode camera is also supported now (no FIFO restriction, because Full speed bulk using 64 Bytes MPS), please refer fa1d17e for details.

@Gornerrrrr
Copy link
Author

@Gornerrrrr 你用的摄像头在哪买的?我买了几个类型,idf得到的MJPEG Frame Descriptor都是只有一个,而且只有160*120

淘宝搜阿香科技买的

方便问下这个摄像头型号么,我买的在fullspeed模式下仅支持非常小的分辨率。

就是分辨率不高的吗,只能说能看到:(

@dzz10
Copy link

dzz10 commented Oct 14, 2024

我强制改如下参数,不报错了,但是画面只有小部分有:
uvc_dev->vs_ifc->interface_alt = 4;
日志显示:uvc_mic_spk_demo: uvc callback! frame_format = 7, seq = 6867, width = 640, height = 480, length = 5088, ptr = 0
image

@github-actions github-actions bot changed the title uvc摄像头例子通讯报错 uvc摄像头例子通讯报错 (AEGHB-844) Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants