FreeRTOS tasks can interrupt USB stack implementation?

ddudas wrote on Thursday, September 24, 2015:

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

rtel wrote on Thursday, September 24, 2015:

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?

ddudas wrote on Thursday, September 24, 2015:

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?

rtel wrote on Thursday, September 24, 2015:

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.

ddudas wrote on Thursday, September 24, 2015:

Thank you for the answer, I think I’m a bit confused with the Cortex ISR priorities :slight_smile:
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.