cancel
Showing results for 
Search instead for 
Did you mean: 

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

L_Kopp
Associate II

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

9 REPLIES 9
Javier1
Principal

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.

Available for consulting/freelancing , hit me up in https://github.com/javiBajoCero
gbm
Lead III

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
Associate II

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

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
Associate II

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

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.

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

Segger?

Piranha
Chief II

> I tried tinyusb but it doesnt work well

It does work. Integrate and use it properly.