FreeRTOS, USB OTG Interrupts

groger57 wrote on Wednesday, November 04, 2015:


I have a target application using the STM32F405. On this board I have a USB port. To get started, I found some sample code written by someone for the STM32F4 Discovery board with a few lines of code for main, and the USB libraries (ub_lib) The project was written in Coocox OS.
I took this project, made a few changes for pin assignments, loaded it in Coocox and I was able to open a file on the USB, write data, close it with no problems on my target application board.

Now I want to use thiese same libraries on my program environment (Atollic TS) which is for all intents and purposes, almost the same as Coocox. I also have FreeRTOS running. So I planted the USB and FAT fs driver directories in, and in main.c, way before the scheduler starts, I put in the same 15 lines of code as the example file has.

Well, nothing could be easier, but nothing could be more difficult to figure out. The USB OTG seems to initialize OK, but it will not actually detect the USB device - it keeps returning “USB_MSC_DEV_DETACHED”, as if for some reason it doesn’t see it. But, this is only on my programming environment, and Coocox (as said) works fine on my same board.

I’ve verified system files such as clocks are all matching. It comes down to interrupts, and this is where I’m a t a loss to understand, and perhaps where the problem is. Does (would) FreeRTOS have anything to do with the way the interrupt handlers are set for the USB OTG? Where could I start looking to establish where the problem might be?

Has anyone else worked with USB OTG on this platform using FreeRTOS and expereinced this? Thanks for any suggestions or help.


rtel wrote on Wednesday, November 04, 2015:

I can’t really comment on driver specifics, but some general hints to consider:

  • Are the tasks running at the same priority between the two systems? Be careful here as some RTOSes illogically have low numeric priorities to mean high logical priority.

  • Have you called NVIC_PriorityGroupConfig( NVIC_PriorityGroup_4 );, which is necessary for STM32 parts:

  • Have you set the USB interrupt priorities? They cannot be left at their defaults if you are using FreeRTOS API functions in the ISR. I would recommend ensuring configASSERT is defined as that will trap a lot of misconfigurations (assuming you are using a recent version of FreeRTOS)

  • Is the tick interrupt frequency the same between the two systems?

groger57 wrote on Thursday, November 05, 2015:


Please note that I pointed out that the test code of the USB interface was before the scheduler launched. What I was trying to understand was any possibility of the FreeRTOS configuration playing a part in this?

Doesn’t seem likely, but I cannot determine what else besides the interrupt would be the problem. Identical code, same hardware, 2 different development platforms. One works, not the other. Very strange.

davedoors wrote on Thursday, November 05, 2015:

In FreeRTOS, if you call an API function before the scheduler is started, then interrupt remain disabled up to configMAX_SYSCALL_INTERRUPT_PRIORITY until the scheduler is started. Could that be your problem? Did you create any tasks or queues or anything?

groger57 wrote on Friday, November 06, 2015:


No, nothing. The code is after all HW is set up, and before any calls relted to FR. So, I guess I kind of answered my own question!

Thanks for all who took the time to respond. Better than anything I got on the STM32 forum, not one response there…