# Using FreeRTOS with STM32 usbd\_core.c as USB device

**URL:** <https://forums.freertos.org/t/using-freertos-with-stm32-usbd-core-c-as-usb-device/7764>\
**Category:** Kernel\
**Created:** [April 3, 2019, 11:37pm UTC](https://forums.freertos.org/t/using-freertos-with-stm32-usbd-core-c-as-usb-device/7764 "2019-04-03T23:37:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [April 3, 2019, 11:37pm UTC](https://forums.freertos.org/t/using-freertos-with-stm32-usbd-core-c-as-usb-device/7764/1 "2019-04-03T23:37:06Z")

</div>

**[jonavarque](https://sourceforge.net/u/jonavarque/)** wrote on [Wednesday, April 03, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/2eb034536c/#39cf):

I’ve been working on a STM32(f7) project that uses USB host and device drivers from the STM32 libraries. usbh\_core.c and usbd\_core.c , I have been able to get the host working under OS pretty well but I now hat to get the usb driver working under RTOS. ST made the host code confrom to FreeRTOS and it is essentially switchable. I havea USB device working now, but it is running in the IDLE thread, which I am asusming isn’t good? So before I move on, I would like to get all that under control. I with ST had done the same things with the usb device as they didi with the host but there aren’t even examples of a USB device with RTOS, that I can find , anyway.  
My project is a MIDI project so I have usbd\_MIDI.c and usbd\_MIDI\_if.c performing the midi IO to and from the app. I am a bit lost as to how to get usbd\_core to run in its own thread that I can have some control over. I guess I am not really sure what to ask for here as I am still trying to grok how the usb device code works. I believe it is all interrupt driven… I didn’t write it so I am at somewhat of a loss at this point.

So , any hints or links or examples would be very helpful. Thank you for reading and thank you for FreeRTOS.

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [April 4, 2019, 1:27am UTC](https://forums.freertos.org/t/using-freertos-with-stm32-usbd-core-c-as-usb-device/7764/2 "2019-04-04T01:27:10Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Thursday, April 04, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/2eb034536c/#39cf/f1d4):

Sorry nothing specific, but would say it is ok to run in the Idle task  
_ **provided that** _ the code never blocks the task - by which I mean  
never does something like call vTaskDelay(), or wait for a semaphore  
with a block time, etc.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [April 4, 2019, 1:33pm UTC](https://forums.freertos.org/t/using-freertos-with-stm32-usbd-core-c-as-usb-device/7764/3 "2019-04-04T13:33:12Z")

</div>

**[jonavarque](https://sourceforge.net/u/jonavarque/)** wrote on [Thursday, April 04, 2019](https://sourceforge.net/p/freertos/discussion/382005/thread/2eb034536c/#39cf/f1d4/3063):

Thank you Richard. Every little bit helps!

----- Original Message -----  
From: “[freertos:discussion]”  
[382005@discussion.freertos.p.re.sourceforge.net](mailto:382005@discussion.freertos.p.re.sourceforge.net)  
To:"[freertos:discussion]"  
[382005@discussion.freertos.p.re.sourceforge.net](mailto:382005@discussion.freertos.p.re.sourceforge.net)  
Cc:  
Sent:Thu, 04 Apr 2019 01:27:15 -0000  
Subject:[freertos:discussion] Re: Using FreeRTOS with STM32  
usbd\_core.c as USB device

```
Sorry nothing specific, but would say it is ok to run in the Idle

```

## task _PROVIDED THAT_ the code never blocks the task - by which I mean never does something like call vTaskDelay(), or wait for a semaphore with a block time, etc.

```
Using FreeRTOS with STM32 usbd_core.c as USB device [1] 

```

* * *

```
Sent from sourceforge.net because you indicated interest in

```

[https://sourceforge.net/p/freertos/discussion/382005/](https://sourceforge.net/p/freertos/discussion/382005/) [2]

```
To unsubscribe from further messages, please visit

```

[https://sourceforge.net/auth/subscriptions/](https://sourceforge.net/auth/subscriptions/) [3]

## Links:

[1]  
[https://sourceforge.net/p/freertos/discussion/382005/thread/2eb034536c/?limit=25#39cf/f1d4](https://sourceforge.net/p/freertos/discussion/382005/thread/2eb034536c/?limit=25#39cf/f1d4)  
[2] [https://sourceforge.net/p/freertos/discussion/382005/](https://sourceforge.net/p/freertos/discussion/382005/)  
[3] [https://sourceforge.net/auth/subscriptions/](https://sourceforge.net/auth/subscriptions/)
