# FreeRTOS tasks can interrupt USB stack implementation?

**URL:** <https://forums.freertos.org/t/freertos-tasks-can-interrupt-usb-stack-implementation/741>\
**Category:** Kernel\
**Created:** [September 24, 2015, 7:51am UTC](https://forums.freertos.org/t/freertos-tasks-can-interrupt-usb-stack-implementation/741 "2015-09-24T07:51:55Z")\
**Posts on this page:** 5\
**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:** [September 24, 2015, 7:51am UTC](https://forums.freertos.org/t/freertos-tasks-can-interrupt-usb-stack-implementation/741/1 "2015-09-24T07:51:55Z")

</div>

**[ddudas](https://sourceforge.net/u/ddudas/)** wrote on [Thursday, September 24, 2015](https://sourceforge.net/p/freertos/discussion/382005/thread/23d7b809/#0ac6):

Hi all,

I’m using ST’s CubeMX implementation on a F4 discovery board. I use ST’s USB middlewares with FreeRTOS.

When I get a special OutputReport from PC side I have to answer nearly immediately (in 10-15 ms). Currently I cannot achieve this timing and it seems my high priority tasks can interrupt the USB callback. What do you think, is it possible? Because it’s generated code I’m not sure but can I increase the priority of the USB interrupt (if there is any)?

Thank you,  
David

---

<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:** [September 24, 2015, 9:16am UTC](https://forums.freertos.org/t/freertos-tasks-can-interrupt-usb-stack-implementation/741/2 "2015-09-24T09:16:35Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Thursday, September 24, 2015](https://sourceforge.net/p/freertos/discussion/382005/thread/23d7b809/#c1b1):

10 to 15 ms is very slow, so I’m sure its possible.

Where is the USB callback function called from? If it is an interrupt then it cannot be interrupted by high priority RTOS tasks. Any non interrupt code (whether you are using an RTOS or not) can only run if no interrupts are running.

Without knowing the control flow in your application its hard to know what to suggest. How is the OutputReport communicated to you? By an interrupt, a message from another task, or some other way?

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [September 24, 2015, 2:32pm UTC](https://forums.freertos.org/t/freertos-tasks-can-interrupt-usb-stack-implementation/741/3 "2015-09-24T14:32:48Z")

</div>

**[ddudas](https://sourceforge.net/u/ddudas/)** wrote on [Thursday, September 24, 2015](https://sourceforge.net/p/freertos/discussion/382005/thread/23d7b809/#d447):

The callback which receive the data from PC is called from the OTG\_FS\_IRQHandler (it’s the part of the HAL\_PCD\_IRQHandler function). I think the problem is SysTick\_Handler’s priority is higher than OTG\_FS\_IRQHandler and it’s cannot be modified, but the scheduler shouldn’t interrupt the OTG\_FS\_IRQHandler with any task handled by the scheduler. Am I wrong that the scheduler can interrupt the OTG\_FS\_IRQHandler?

---

<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:** [September 24, 2015, 3:01pm UTC](https://forums.freertos.org/t/freertos-tasks-can-interrupt-usb-stack-implementation/741/4 "2015-09-24T15:01:44Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Thursday, September 24, 2015](https://sourceforge.net/p/freertos/discussion/382005/thread/23d7b809/#d447/8cfd):

A couple of things -

First the SysTick handler should be the **lowest** priority interrupt,  
so it can get interrupted by the USB interrupt, but it cannot interrupt  
the USB interrupt. Even if the SysTick was running at a higher priority  
it would only account for a few microseconds, not so many milliseconds.

Second, as per my previous email, it is physically impossible (the  
hardware will not allow it) for the scheduler to start running a task  
(i.e. non-interrupt code) while an interrupt is executing.

I think you are probably looking for the problem in the wrong area.

Regards.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [September 24, 2015, 3:06pm UTC](https://forums.freertos.org/t/freertos-tasks-can-interrupt-usb-stack-implementation/741/5 "2015-09-24T15:06:19Z")

</div>

**[ddudas](https://sourceforge.net/u/ddudas/)** wrote on [Thursday, September 24, 2015](https://sourceforge.net/p/freertos/discussion/382005/thread/23d7b809/#d447/8cfd/a662):

Thank you for the answer, I think I’m a bit confused with the Cortex ISR priorities 🙂  
What I can observe is if I use a much higher osDelay in my high priority task I can respond for the received USB message much faster. This is why I think tasks can mess up with my OTG interrupt.
