cancel
Showing results for 
Search instead for 
Did you mean: 

Any example on STM32F2xx with UVC?

ericyuanzhang9
Associate II
Posted on June 03, 2012 at 13:59

Hi,

Does anybody know if there is example on STM32F2xx to support UVC class? I checked USB lib provided by STM but only similar example (Audio with ISO out) provided and I do think there should be quite some works if I port Audio project towards UVC class, as for they indeed have some differences.

That would be good if you can share any idea on the implement method or materials could be shared, I appreciate it pretty much.

Basically I am doing a small demo to simulate a USB Camera by STM32F2xx, a real camera is plugged to DCMI I/F. What I am facing issue is USB Part with suppporting on UVC.

Thank you...

#uvc #usb
22 REPLIES 22
tsuneo
Senior
Posted on June 12, 2012 at 20:06

The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6b8&d=%2Fa%2F0X0000000brR%2FMOfY7.NfpZ4UDSoQ.cUl789dexWpEvG.UMBkXnbF6os&asPdf=false
tsuneo
Senior
Posted on June 12, 2012 at 20:10

The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6bD&d=%2Fa%2F0X0000000brU%2FYtgqJpfqj5immrbvAW1I2NBkPvlFfKzNLvX2WA3UnW4&asPdf=false
alok472
Associate II
Posted on June 13, 2012 at 03:00

Hi chinzei.tsuneo

''Set_Interface switches the alternate streaming interface. And then, isoc IN transactions start. ''

Is it ISO EP or we can use Bulk ? I always thought it it possible to use any EP

tsuneo
Senior
Posted on June 13, 2012 at 08:40

For video streaming interface, an isoc or bulk endpoint is allowed by the UVC spec.

For isoc endpoint,

1) The streaming interface should have zero-bandwidth default interface. One or more alternate interfaces are defined, for required bandwidth (wMaxPacketSize) depending on frame size/ frame rate.

At the start of streaming, Set_Interface request switches from default to one of alternate. At the end of streaming, Set_Interface recovers the default interface.

2) One payload transfer (payload header + its payload) per single transaction (for full-speed and non-high-bandwidth high-speed)

3) The transactions in the frame gap (from the last frame end to next frame), are filled with zero-payload transfers (payload header without any payload).

For bulk endpoint,

1) The streaming interface doesn't have any alternate, just a default. Set_Interface isn't issued by host.

2) One payload transfer is split into multiple transactions.

3) The endpoint NAKs in frame gap.

These two transfer types have their own pros and cons, respectively.

- Bulk firmware code is simpler than isoc, at least for alternate interfaces and Set_Interface support.

- For isoc, Set_Interface explicitly gives the start/stop timing of streaming.

- Isoc reserves bus bandwidth at Set_Interface. Available bandwidth for bulk varies on the fly.

etc.

I can't tell which one is better.

Tsuneo

ericyuanzhang9
Associate II
Posted on June 13, 2012 at 17:08

The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6bI&d=%2Fa%2F0X0000000brV%2FsPcbxsfAVa7Yz_1vdoAjFT0odl3L.INAGdjtPGJZwhA&asPdf=false
tsuneo
Senior
Posted on June 14, 2012 at 08:51

You are starting with the descriptors in ''3 Video Camera Player Example'' of USB_Video_Example 1.1.pdf

(included in UVC spec on USB.org, http://www.usb.org/developers/devclass_docs/USB_Video_Class_1_1_090711.zip)

1) Simplify descriptors

I recommend you to simplify the example more, for the first starting up. And then, you'll see less class requests (Get_Cur/Set_Cur etc.)

Drop these optional descriptors.

- Input Terminal Descriptor (Media Transport)

- Selector Unit Descriptor

- Standard Interrupt Endpoint Descriptor

- Class-specific Interrupt Endpoint Descriptor

- Class-specific Still Image Frame Descriptor

- Standard Bulk Endpoint Descriptor

- Standard Bulk Endpoint Descriptor (on alternate IF)

Dropping these descriptors results in minor tuning of other descriptors.

/* Configuration 1 */

  LOBYTE(0x00d9),      /* wTotalLength  109 bytes*/ <-- decrease by the size of above descs

  HIBYTE(0x00d9),      

/* Standard VC Interface Descriptor */

  0x01,                /* bNumEndpoints */  <-- 0

/* VideoControl Interface Descriptor: (Header) */

LOBYTE(0x0040),        /* wTotalLength  */ <-- decrease by the size of Input Terminal (Media Transport)

HIBYTE(0x0040),        /* wTotalLength  */     and Selector Unit

/* Input Terminal Descriptor (Camera) */

0x03,            /* bTerminalID        => ID of this input terminal  */ <-- 0x01

0x00,              /* bmControls       => Supported controls */

0x02,    <-- 0x00 (no control)

0x00,

/* Streaming Descriptor */

0x01,            /* bNumEndpoints      => 1 endpoints */ <-- 0x00 (no endpoint on the default)

/* Class-specific VS Header Descriptor (Input) */

0x4C,            /* wTotalLength       =>      */ <-- decrease by the size of Still Image Frame

0x00,

0x03,     /* bStillCaptureMethod=> Device supports still image capture method 3.*/ <-- 0x00 None

/* Operational Alternate Setting 1 */

/* Standard VS Interface Descriptor*/

0x02,            /* bNumEndpoints      => 2 endpoints */  <-- 0x01  one endpoint

2) Endpoint address

In this example descriptors, Video-streaming isoc IN EP is assigned to 0x85

/* Standard VS Isochronous Video Data Endpoint Descriptor */

0x85,            /* bEndpointAddress => IN endpoint 5 */

But the EP addresses on STM32F2xx is limited to 0x81, 0x82 and 0x83.

Therefore, you have to change the EP address of the endpoint descriptor into one of these ones.

Also, address of the VS isoc IN EP is referred in this descriptor. Change it, too.

/* Class-specific VS Header Descriptor (Input) */

0x85,            /* bEndpointAddress   => Address of the isochronous endpoint*/

In the convention of STM32_USB-Host-Device_Lib, the endpoint is initialized in usbd_audio_Init() (STM32_USB-Host-Device_Lib_V2.1.0\Libraries\STM32_USB_Device_Library\Class\audio\src\usbd_audio_core.c) by calling DCD_EP_Open(), if you are starting with the audio example.

Tsuneo

ericyuanzhang9
Associate II
Posted on July 31, 2012 at 16:32

Hi! Now,my device has been recognized by the system and can be find as a camera in the hareware management .But when I open the device ,there is no video and with the bushound tool .I find there is only one isochronous transmation paket ,and the ,the device entered in hardwarefault,just after I enable the endpoint 1.

I have been bothered by this trouble for 2weeks ,does any one have any idea about the isochronous trans?does there any other configeration have to do before enable the endpoint 1?

Here is the steps I did:

1 .configed  the endpoint 1 as isochronous mode;

2.prepare  the data buffer

3. In the In token interrupt service ,enable the endpoint 1 .

And then  hardwarefault  occurred .

balmukund66
Associate II
Posted on September 17, 2013 at 06:50

Hi,

In USB video class demo,Class specific request is not coming.

I am worikng on UVC Lib using STM32F2xx.

The device gets enumerated,after running descriptor(It appears in the Device Manager as Imaging device).

But No IN request comes from Host after that.

 

Thanks & Regards

Balmukund Prasad 

tomaskrueger
Associate II
Posted on August 13, 2014 at 20:35

On Google ''STM32 uvc'', this gets the most hits, so i may as well pick it up, as i am right here.

I am not aware of any '' USB video class demo'' as mentioned in the previous post.

So...I adopted the above ''Descriptor'' with its final modification and ...voila...Windows has a new Video device.

Opening a Camera Application, select video device works, video-adjust options are correctly deactivated (as to the Descriptor). Windows correctly selected ''usbvideo.sys'' driver.

My uvc-device gets the following Setup messages from Windows:

Setup: typ:0xa1 request:129 value:256

Setup: typ:0xa1 request:129 value:512

...several times.

These are Class->Set Interface messages.

So here we are trying to start the isochronous IN (INto PC) data transfer of videodata.

An Endpoint of type isochronous has been opened.

I am currently unclear about the isochronous transfer algorithm.

The above ''Set Interface'' messages could be interpreted as ''Hey man, go ahead and start transmitting Videodata with framesize 256 or 512 bytes''.

Then i am reading that on isoc-transfers each transmit shall be syncronized with the reception of an SOF frame, thus sending one 512-byte datapacket after each SOF.

Maybe someone can bring some light in here. ?

tomaskrueger
Associate II
Posted on September 17, 2014 at 20:40

my goal: develop a UVC FullSpeed OV7670 alike USB Video Camera ''Device'', using the STM Lib V2.1.0 .

Hardware: stm32f207, custom board. Host system=winxp.(alternate win7)

As a matter of fact, you have to work through the USB UVC specification V1.1 from USB.org.

my leaning curve:

- get your descriptors correct with ''interface association'', ''Control interface'', ''streaming interface/Input-Output-Terminal'', ''Format and frame descriptors'', ''endpoints''

- there are specific uvc setup requests being send to your USB-uvc-device.

Get_Cur, Get_Max, Get_Min, Set_Cur, Set_Cur-with-Commit(thats your working set), all use a structure ''control-setup'' with different length depending on ''Revision of class specification''. winxp only V1.0 (0x1A-size, else size 0x22)

So here i am, using isoc transfers.

isochronous means you have to send a fixed amount of data at the beginning of each SOF-interrupt. For FullSpeed that is every 1 millisecond.(endpoint->interval=1).Each transfer shall include a (minimum) 2-byte hader.

my current implementation:-->

On the SOF interrupt routine do:

if (VideoFramedataIsReady) ->

put Frames: [2 Byte Header ([lenght=2],[(toggle-bit|EOF=0|0x80)]+[data(lenght=control_commit_transfersize)] ......

On Last packet:[2 Byte Header [(length=2],[(toggle-bit|EOF=1|0x80)]+[last_data(lenght=AsIs)]

else // Videoframe not ready(still gathering Videoframe data from camera)

//just send empty Header

put ''the header of the next expected frame'' ie: put 2 Byte Header ([lenght=2],[(toggle-bit|EOF=0|0x80)]

Note: the toggle-bit ''toggles'' after each completed frame from the camera !

Comment: I am doing this in the interrupt routine of the SOF interrupt of the stm V2.1.0 Lib Callback ''SOF_int''. So i send ''DCD_EP_Tx (pdev, IN_EP2, TxBuf, len);'' in the interrupt. if this is working?? Am I too late???

OK, what i am seeing is: i get IsocIncomplete interrupts from the ''UsrIO_CallBacks->IsoINincomplete''.

It seems, the Host(Windows-PC), is not providing IN-tokens, or my data is too late.

Tsuneo responded on this thread, regarding IsocIncomplete-ints :

https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Source%20of%20isochronous%20IN%20incomplete%20interrupt

maybe i get a hint on whats going wrong here?

ps. i am on the ''user-level'' of the stm32-lib v2.1.0 . (implemented some ''fixes'' sugested in the forum)

regards thomas