Skip to main content
Visitor II
May 11, 2023
Solved

Example for Azure RTOS USBX device video (UVC)

  • May 11, 2023
  • 21 replies
  • 8178 views

Hello everyone

Does anyone have example code for Azure RTOS USBX device class video (UVC)?

I was able to add Video to my USBX demo application on Nucleo H7A3

There was sample code for CDC_ACM and MSC (mass storage), this worked fine. But for device class video, I was not able to find any example code.

CubeIDE 1.12.1 generated two files

ux_device_video.c

ux_device_video.h

But both files only contain prototypes of callback functions which need to be filled

Like this:

/**
 * @brief USBD_VIDEO_StreamRequest
 * This function is invoked to manage the UVC class requests.
 * @param video_stream: Pointer to video class stream instance.
 * @param transfer: Pointer to the transfer request.
 * @retval status
 */
UINT USBD_VIDEO_StreamRequest(UX_DEVICE_CLASS_VIDEO_STREAM *video_stream,
 UX_SLAVE_TRANSFER *transfer)
{
 UINT status = UX_SUCCESS;
 
 /* USER CODE BEGIN USBD_VIDEO_StreamRequest */
 UX_PARAMETER_NOT_USED(video_stream);
 UX_PARAMETER_NOT_USED(transfer);
 /* USER CODE END USBD_VIDEO_StreamRequest */
 
 return status;
}

How to fill it, that it works?

Thanks

Johannes

    This topic has been closed for replies.
    Best answer by mohamed.ayed

    Hi Johannes,

    It's mentioned in readme file

    https://github.com/STMicroelectronics/x-cube-azrtos-h7/blob/main/Projects/NUCLEO-H723ZG/Applications/USBX/Ux_Device_Video/README.md

    if you you open ioc of application (download https://www.st.com/en/embedded-software/x-cube-azrtos-h7.html) change VIDEO_STREAMING_FORMAT to MJPEG and change video width and height finally generate code and include stream2.h in project instead of stream1.h

    - stream2 FORMAT : UNCOMPRESSED and Width = 176, Height = 144 and the descriptor shall be updated.

    21 replies

    JohannesAuthor
    Visitor II
    May 11, 2023

    This is my project so far. It generates a composite device with 3 endpoints

    • CDC_ACM (serial port)
    • MSC (mass storage) with a ramdisk and FileX
    • Video (does not work)

    Generated with CubeIDE 1.12.1

    on an Nucleo H7A3ZI-Q

    ST Employee
    May 11, 2023

    Hi @Johannes​ ,

    Please refer to this example application with STM32H723-Nucleo:

    https://github.com/STMicroelectronics/x-cube-azrtos-h7/tree/main/Projects/NUCLEO-H723ZG/Applications/USBX/Ux_Device_Video

    JohannesAuthor
    Visitor II
    May 12, 2023

    Hello Mohamed

    Thanky you very much (I could have found this myself, silly me)

     

    Unfortunately I have additional problems

    Windows is still complaining, that the camera cannot be started.

    0693W00000bjwQyQAI_image.png

    It complains about a wrong parameter being transmitted

    Code 0x0A Status 0xC000000D

     


    _legacyfs_online_stmicro_images_0693W00000bjwRhQAI.png 

    Do you have an idea, what the problem might be?

     

    I must admit, that I haven't run the exact example,

    • I use Nucleo H7A3
    • I have setup a compound device with 3 endpoints (MSC, CDC_ACM, Video)
    • I use Cube IDE1.12.1 and have cubeIDE generate all the code

    I checked the file usb descriptors and they look the same. (i am using endpoin 0x84 for video)

     

    Thank you .

    Johannes

    ST Employee
    May 12, 2023

    Hi @Johannes​  can you please share with an usb trace of your device enumeration, or you can port Ux_Device_Video with  STM32H7A3-Nucleo to ensure that it work and then intergrate it in your application.

    JohannesAuthor
    Visitor II
    May 12, 2023

    Hello Mohamed

    Good news: I was able to make the USB Device Video example run.

    But I needed to strip my demo code down to a single endpoint USB device.

    Strangely: If the device endpoint address is less than 0x83 for video, the camera app on windows does not show the video, just a black screen.

    If the endpoint is 0x83 or higher, The camera app shows the demo video.

    As soon as I make the device a compound device by adding MSC storage, windows is complaining about the wrong parameter for the USB camera.

    I have a wireshark USB trace. There are multiple strange packets:


    _legacyfs_online_stmicro_images_0693W00000bjxw7QAA.pngAnd a malformed packet


    _legacyfs_online_stmicro_images_0693W00000bjxwCQAQ.pngThe rest of the packets are related to MSC storage, i think

    JohannesAuthor
    Visitor II
    May 12, 2023

    This is a trace of a working camera (singular endpoint device)


    _legacyfs_online_stmicro_images_0693W00000bjy3mQAA.pngThe "unknown frames" are still there, but there is no "malformed package".

    ST Employee
    May 12, 2023

    @Johannes​ if you modifie device descriptor you need to modifie PID (Product ID)

    JohannesAuthor
    Visitor II
    May 12, 2023

    @mohamed.ayed​ Change the PID to what?

    If I change the PID from e.g. 0x5710 to 0x5711, windows re-installes the drivers. But the malformed package is still there.

    JohannesAuthor
    Visitor II
    May 12, 2023

    If a package is "ok", this seems to be the position is the lengh information of the payload


    _legacyfs_online_stmicro_images_0693W00000bjyGDQAY.pngbLengh = 4, 1 byte "bDescriptor type" and 2 bytes payload = 4 bytes.

    In the malformed package

    bLength = 4, but only the bDescriptor is following and 2 bytes are missing


    _legacyfs_online_stmicro_images_0693W00000bjyLCQAY.png 

    JohannesAuthor
    Visitor II
    May 16, 2023

    I got a solution.

    for some bizare unknown reason, it works if I change the order of the device classes.

    If I change the enumeration of the device classes, so Video comes first, it works.

    uint8_t UserClassInstance[USBD_MAX_CLASS_INTERFACES] = {
     CLASS_TYPE_VIDEO,
     CLASS_TYPE_MSC,
     CLASS_TYPE_CDC_ACM,
    };

    Now I have a compound device with

    • Video
    • Mass storage
    • virtual serial port

    If anyone can explain, why that is, ... highly appreciated.

    Johannes

    ST Employee
    May 16, 2023

    Hi @Johannes​ , As i see in your project TxFifo Config of endpoint video (EP 4 - IN) is missed, you can check it in reference application:

    https://github.com/STMicroelectronics/x-cube-azrtos-h7/blob/f25d657a4de4aac6dba48df28b96238479d73ca0/Projects/NUCLEO-H723ZG/Applications/USBX/Ux_Device_Video/USBX/App/app_usbx_device.c#L245