Skip to main content
Visitor II
December 19, 2022
Question

Is there a simple example how to combine USB CDC device and FreeRTOS ?

  • December 19, 2022
  • 6 replies
  • 4030 views

I am trying to implement a cdc device and would also like to use the FreeRTOS. For code generation I use CubeMX. To keep the interrupt of the receives as short as possible I want to send the answer to the host using a task. But after a few seconds my host receive an invalid answer. Is there a simple example that shows how to combine the UBS Device library with FreeRTOS ?

Regards,

Lena

    This topic has been closed for replies.

    6 replies

    Graduate II
    December 19, 2022

    I have tried this before, handling the data to be sent via usb with freertos queues.

    Creating a high priority not preemptable task, i still got missing USB frames ...

    >>But after a few seconds my host receive an invalid answer

    Sounds similar to what happened to me.

    Graduate
    December 19, 2022

    Either call Transmit only from the interrupt routine of the same priority as USB interrupt or at least disable the interrupts before calling Transmit an re-enable them immediately after.

    L_KoppAuthor
    Visitor II
    December 19, 2022

    Thanks for your answers!

    I tried to start the receive in the transmit complete callback but this does not improve the behavior.

    ST Employee
    December 19, 2022

    Hi @Community member​ 

    You Can use AzureRTOS USBX middleware it works in RTOS (Threadx) and standalone mode.

    You can refer to this example:

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

    L_KoppAuthor
    Visitor II
    December 19, 2022

    @mohamed.ayed​ thank you for your answer.

    Since my whole project is based on freeRTOS I don't want to change the operating system. Can the procedure be applied to freeRTOS ?

    Super User
    December 20, 2022

    Use other vendor's USB library that can be ported to FreeRTOS natively or via CMSIS-RTOS wrapper. It likely costs something, but your time isn't free either.

    L_KoppAuthor
    Visitor II
    December 22, 2022

    Do you have an example of a good USB library I tried tinyusb but it doesnt work well

    Graduate II
    December 30, 2022

    > I tried tinyusb but it doesnt work well

    It does work. Integrate and use it properly.