Skip to main content
L_Kopp
Associate II
December 19, 2022
Question

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

  • December 19, 2022
  • 9 replies
  • 4101 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.

9 replies

Javier1
Principal
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.

hit me up in https://www.linkedin.com/in/javiermuñoz/
gbm
Super User
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.

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice
L_Kopp
L_KoppAuthor
Associate 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.

mohamed.ayed
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_Kopp
L_KoppAuthor
Associate 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 ?

Pavel A.
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_Kopp
L_KoppAuthor
Associate II
December 22, 2022

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

Piranha
Principal III
December 30, 2022

> I tried tinyusb but it doesnt work well

It does work. Integrate and use it properly.