Skip to main content
L_Kopp
Associate II
Dec 19, 2022 7:28 AM UTC
Question

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

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.

9 replies

Javier1
Principal
Dec 19, 2022 8:34 AM UTC

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.

hit me up in https://www.linkedin.com/in/javiermuñoz/
gbm
Super User
Dec 19, 2022 8:55 AM UTC

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.

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice
L_Kopp
L_KoppAuthor
Associate II
Dec 19, 2022 9:45 AM UTC

Thanks for your answers!

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

mohamed.ayed
ST Employee
Dec 19, 2022 1:40 PM UTC

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_Kopp
L_KoppAuthor
Associate II
Dec 19, 2022 3:23 PM UTC

@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 ?

Pavel A.
Dec 20, 2022 12:27 AM UTC

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_Kopp
L_KoppAuthor
Associate II
Dec 22, 2022 12:40 PM UTC

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

Piranha
Principal III
Dec 30, 2022 1:19 AM UTC

> I tried tinyusb but it doesnt work well

It does work. Integrate and use it properly.