I'm implementing USB web cam on top of Atmega32U4.
I think I managed to implement transactions on the control endpoint, more or less correctly, as all the descriptors are transited and device reports correctly in the system.
Issue is when I'm trying to send video data out of the device, as nothing seems to go through.
The way I implemented data transmission (according to section 22.14 of datasheet) is as follows:
while (len > 0) {
while (1) {
cli();
_select_endpoint(VIDEO_STREAMING_ENDPOINT);
if (bit_is_set(UEINTX, TXINI) && bit_is_set(UEINTX, FIFOCON))
break;
sei();
_delay_ms(1);
}
_clear_TXINI();
while (bit_is_set(UEINTX, RWAL) && len > 0) {
UEDATX = *buff++;
--len;
}
_clear_FIFOCON();
sei();
}
When debugging this I noticed that bank is filled with data during the first loop, but data is not transmitted to the host. It is looping forever in the TXINI,FIFOCON part. Nothing, except the control requests, is shown in the Wireshark. I'm not sure if I missconfigured something on the MCU registers, so it is not sending data to the host upon the request, or in the descriptors, status, etc, so host is not asking for data.
What might have I messed up?
lsusb -v
Bus 001 Device 077: ID 6431:deb2 majkrzak majkrzak
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 2.00
bDeviceClass 239 Miscellaneous Device
bDeviceSubClass 2
bDeviceProtocol 1 Interface Association
bMaxPacketSize0 32
idVendor 0x6431
idProduct 0xdeb2
bcdDevice 0.00
iManufacturer 1 majkrzak
iProduct 1 majkrzak
iSerial 1 majkrzak
bNumConfigurations 1
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 0x00a0
bNumInterfaces 2
bConfigurationValue 1
iConfiguration 1 majkrzak
bmAttributes 0x80
(Bus Powered)
MaxPower 500mA
Interface Association:
bLength 8
bDescriptorType 11
bFirstInterface 0
bInterfaceCount 2
bFunctionClass 14 Video
bFunctionSubClass 3 Video Interface Collection
bFunctionProtocol 0
iFunction 1 majkrzak
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 0
bInterfaceClass 14 Video
bInterfaceSubClass 1 Video Control
bInterfaceProtocol 1
iInterface 1 majkrzak
VideoControl Interface Descriptor:
bLength 13
bDescriptorType 36
bDescriptorSubtype 1 (HEADER)
bcdUVC 1.50
wTotalLength 0x0028
dwClockFrequency 16.000000MHz
bInCollection 1
baInterfaceNr( 0) 1
VideoControl Interface Descriptor:
bLength 18
bDescriptorType 36
bDescriptorSubtype 2 (INPUT_TERMINAL)
bTerminalID 1
wTerminalType 0x0201 Camera Sensor
bAssocTerminal 2
iTerminal 1 majkrzak
wObjectiveFocalLengthMin 0
wObjectiveFocalLengthMax 0
wOcularFocalLength 0
bControlSize 3
bmControls 0x00000000
VideoControl Interface Descriptor:
bLength 9
bDescriptorType 36
bDescriptorSubtype 3 (OUTPUT_TERMINAL)
bTerminalID 2
wTerminalType 0x0101 USB Streaming
bAssocTerminal 1
bSourceID 1
iTerminal 1 majkrzak
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 1
bAlternateSetting 0
bNumEndpoints 1
bInterfaceClass 14 Video
bInterfaceSubClass 2 Video Streaming
bInterfaceProtocol 1
iInterface 1 majkrzak
VideoStreaming Interface Descriptor:
bLength 13
bDescriptorType 36
bDescriptorSubtype 1 (INPUT_HEADER)
bNumFormats 1
wTotalLength 0x0055
bEndpointAddress 0x81 EP 1 IN
bmInfo 0
bTerminalLink 2
bStillCaptureMethod 0
bTriggerSupport 0
bTriggerUsage 0
bControlSize 0
bmaControls( 0) 27
VideoStreaming Interface Descriptor:
bLength 27
bDescriptorType 36
bDescriptorSubtype 4 (FORMAT_UNCOMPRESSED)
bFormatIndex 1
bNumFrameDescriptors 1
guidFormat {32595559-0000-0010-8000-00aa00389b71}
bBitsPerPixel 8
bDefaultFrameIndex 0
bAspectRatioX 1
bAspectRatioY 1
bmInterlaceFlags 0x00
Interlaced stream or variable: No
Fields per frame: 2 fields
Field 1 first: No
Field pattern: Field 1 only
bCopyProtect 0
VideoStreaming Interface Descriptor:
bLength 38
bDescriptorType 36
bDescriptorSubtype 5 (FRAME_UNCOMPRESSED)
bFrameIndex 1
bmCapabilities 0x02
Still image unsupported
Fixed frame-rate
wWidth 16
wHeight 16
dwMinBitRate 262144
dwMaxBitRate 262144
dwMaxVideoFrameBufferSize 768
dwDefaultFrameInterval 1000000
bFrameIntervalType 0
dwMinFrameInterval 1000000
dwMaxFrameInterval 1000000
dwFrameIntervalStep 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x81 EP 1 IN
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0020 1x 32 bytes
bInterval 1
Device Status: 0x0000
(Bus Powered)
I'd made a simple script with pyusb
which is pulling data from the endpoint and it works. Wireshark is showing the transactions, so it means that in the uvcvideo
case data is not pulled at all. Definitely I messed up the descriptors then.
The reason why uvc driver is not pulling any data for the device, is that you set dwMaxVideoFrameSize
and dwMaxPayloadTransferSize
to 0
. Set it to value high enough for your case and it will work.